diff trunk/chipmunkd/cpSpace.d @ 29:80058cee1a77

updated to chipmunk 5.3.4
author Extrawurst
date Thu, 16 Dec 2010 00:33:06 +0100
parents 4541ca17975b
children
line wrap: on
line diff
--- a/trunk/chipmunkd/cpSpace.d	Mon Dec 13 21:40:56 2010 +0100
+++ b/trunk/chipmunkd/cpSpace.d	Thu Dec 16 00:33:06 2010 +0100
@@ -1,4 +1,3 @@
-
 // written in the D programming language
 
 module chipmunkd.cpSpace;
@@ -58,7 +57,7 @@
 	// *** Internally Used Fields
 	
 	// When the space is locked, you should not add or remove objects;
-	cpBool locked;
+	int locked;
 	
 	// Time stamp. Is incremented on every call to cpSpaceStep().
 	cpTimestamp stamp;
@@ -73,6 +72,9 @@
 	// List of groups of sleeping bodies.
 	cpArray *sleepingComponents;
 	
+	// List of bodies that have been flagged to be awoken.
+	cpArray *rousedBodies;
+	
 	// List of active arbiters for the impulse solver.
 	cpArray* arbiters, pooledArbiters;
 	
@@ -278,6 +280,8 @@
 	
 	space.bodies = cpArrayNew(0);
 	space.sleepingComponents = cpArrayNew(0);
+	space.rousedBodies = cpArrayNew(0);
+
 	space.sleepTimeThreshold = INFINITY;
 	space.idleSpeedThreshold = 0.0f;
 	
@@ -315,6 +319,7 @@
 	
 	cpArrayFree(space.bodies);
 	cpArrayFree(space.sleepingComponents);
+	cpArrayFree(space.rousedBodies);
 	
 	cpArrayFree(space.constraints);
 	
@@ -448,7 +453,7 @@
 cpSpaceAddShape(cpSpace *space, cpShape *shape)
 {
 	cpBody *_body = shape._body;
-	if(!_body || _body == &space.staticBody) return cpSpaceAddStaticShape(space, shape);
+	if(!_body || cpBodyIsStatic(_body)) return cpSpaceAddStaticShape(space, shape);
 	
 	assert(!cpHashSetFind(space.activeShapes.handleSet, shape.hashid, shape),
 		"Cannot add the same shape more than once.");
@@ -623,3 +628,51 @@
 	cpSpaceHashRehashObject(space.staticShapes, shape, shape.hashid);
 }
 
+void
+cpSpaceEachBody(cpSpace *space, cpSpaceBodyIterator func, void *data)
+{
+	cpArray *bodies = space.bodies;
+	
+	for(int i=0; i<bodies.num; i++){
+		func(cast(cpBody *)bodies.arr[i], data);
+	}
+	
+	cpArray *components = space.sleepingComponents;
+	for(int i=0; i<components.num; i++){
+		cpBody *root = cast(cpBody *)components.arr[i];
+		cpBody *_body = root, next;
+		do {
+			next = _body.node.next;
+			func(_body , data);
+		} while((_body = next) != root);
+	}
+}
+
+// chipmunk_private.h
+
+//void *cpSpaceGetPostStepData(cpSpace *space, void *obj);
+
+//void cpSpaceActivateBody(cpSpace *space, cpBody *body);
+
+static void
+cpSpaceLock(cpSpace *space)
+{
+	space.locked++;
+}
+
+static void
+cpSpaceUnlock(cpSpace *space)
+{
+	space.locked--;
+	assert(space.locked >= 0, "Internal error:Space lock underflow.");
+	
+	if(!space.locked){
+		cpArray *waking = space.rousedBodies;
+		for(int i=0, count=waking.num; i<count; i++){
+			cpSpaceActivateBody(space, cast(cpBody *)waking.arr[i]);
+		}
+		
+		waking.num = 0;
+	}
+}
+