diff trunk/chipmunkd/chipmunk_types.d @ 15:df4ebc8add66

rename/refactoring
author Extrawurst
date Sat, 04 Dec 2010 00:51:29 +0100
parents
children 131331ebb599
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trunk/chipmunkd/chipmunk_types.d	Sat Dec 04 00:51:29 2010 +0100
@@ -0,0 +1,159 @@
+
+// written in the D programming language
+
+module chipmunkd.chipmunk_types;
+
+//#ifdef __APPLE__
+//   #import "TargetConditionals.h"
+//#endif
+//
+//#ifndef CP_USE_DOUBLES
+//  // Use single precision floats on the iPhone.
+//  #if TARGET_OS_IPHONE
+//    #define CP_USE_DOUBLES 0
+//  #else
+//    // use doubles by default for higher precision
+//    #define CP_USE_DOUBLES 1
+//  #endif
+//#endif
+//
+version(CP_USE_DOUBLES){
+	alias double cpFloat;
+	//TODO:
+//	#define cpfsqrt sqrt
+//	#define cpfsin sin
+//	#define cpfcos cos
+//	#define cpfacos acos
+//	#define cpfatan2 atan2
+//	#define cpfmod fmod
+//	#define cpfexp exp
+//	#define cpfpow pow
+//	#define cpffloor floor
+//	#define cpfceil ceil
+}else{
+	extern (C) nothrow {
+		float sqrtf(float);
+		float sinf(float);
+		float cosf(float);
+		float acosf(float);
+		float atan2f(float,float);
+		float fmodf(float,float);
+		float expf(float);
+		float powf(float,float);
+		float floorf(float);
+		float ceilf(float);
+	}
+	
+	alias float cpFloat;
+	
+	alias sqrtf cpfsqrt;
+	alias sinf cpfsin;
+	alias cosf cpfcos;
+	alias acosf cpfacos;
+	alias atan2f cpfatan2;
+	alias fmodf cpfmod;
+	alias expf cpfexp;
+	alias powf cpfpow;
+	alias floorf cpffloor;
+	alias ceilf cpfceil;
+}
+
+static cpFloat
+cpfmax(cpFloat a, cpFloat b)
+{
+	return (a > b) ? a : b;
+}
+
+static cpFloat
+cpfmin(cpFloat a, cpFloat b)
+{
+	return (a < b) ? a : b;
+}
+
+static cpFloat
+cpfabs(cpFloat n)
+{
+	return (n < 0) ? -n : n;
+}
+
+static cpFloat
+cpfclamp(cpFloat f, cpFloat min, cpFloat max)
+{
+	return cpfmin(cpfmax(f, min), max);
+}
+
+static cpFloat
+cpflerp(cpFloat f1, cpFloat f2, cpFloat t)
+{
+	return f1*(1.0f - t) + f2*t;
+}
+
+static cpFloat
+cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d)
+{
+	return f1 + cpfclamp(f2 - f1, -d, d);
+}
+
+//#if TARGET_OS_IPHONE
+//	// CGPoints are structurally the same, and allow
+//	// easy interoperability with other iPhone libraries
+//	#import <CoreGraphics/CGGeometry.h>
+//	typedef CGPoint cpVect;
+//#else
+	struct cpVect{cpFloat x = 0; cpFloat y=0;}
+//#endif
+
+alias uint cpHashValue;
+
+// Oh C, how we love to define our own boolean types to get compiler compatibility
+//#ifdef CP_BOOL_TYPE
+//	typedef CP_BOOL_TYPE cpBool;
+//#else
+	alias bool cpBool;
+//#endif
+
+//#ifndef cpTrue
+	enum cpTrue = true;
+//#endif
+
+//#ifndef cpFalse
+	enum cpFalse = false;
+//#endif
+
+//#ifdef CP_DATA_POINTER_TYPE
+//	typedef CP_DATA_POINTER_TYPE cpDataPointer;
+//#else
+	alias void * cpDataPointer;
+//#endif
+
+//#ifdef CP_COLLISION_TYPE_TYPE
+//	typedef CP_COLLISION_TYPE_TYPE cpCollisionType;
+//#else
+	alias uint cpCollisionType;
+//#endif
+
+//#ifdef CP_GROUP_TYPE
+//	typedef CP_GROUP_TYPE cpGroup;
+//#else
+	alias uint cpGroup;
+//#endif
+
+//#ifdef CP_LAYERS_TYPE
+//	typedef CP_GROUP_TYPE cpLayers;
+//#else
+	alias uint cpLayers;
+//#endif
+
+//#ifdef CP_TIMESTAMP_TYPE
+//	typedef CP_TIMESTAMP_TYPE cpTimestamp;
+//#else
+	alias uint cpTimestamp;
+//#endif
+
+//#ifndef CP_NO_GROUP
+	enum CP_NO_GROUP = 0;
+//#endif
+
+//#ifndef CP_ALL_LAYERS
+	enum CP_ALL_LAYERS = ~0;
+//#endif