void
cpSpaceUnlock(cpSpace *space, cpBool runPostStep)
{
	space->locked--;
	cpAssertHard(space->locked >= 0, "Internal Error: Space lock underflow.");
	
	if(space->locked == 0 && runPostStep && !space->skipPostStep){
		space->skipPostStep = cpTrue;
		
		cpArray *waking = space->rousedBodies;
		for(int i=0, count=waking->num; i<count; i++){
			cpSpaceActivateBody(space, (cpBody *)waking->arr[i]);
			waking->arr[i] = NULL;
		}
		
		cpArray *arr = space->postStepCallbacks;
		for(int i=0; i<arr->num; i++){
			cpPostStepCallback *callback = (cpPostStepCallback *)arr->arr[i];
			cpPostStepFunc func = callback->func;
			
			// Mark the func as NULL in case calling it calls cpSpaceRunPostStepCallbacks() again.
			callback->func = NULL;
			if(func) func(space, callback->key, callback->data);
			
			arr->arr[i] = NULL;
			cpfree(callback);
		}
		
		waking->num = 0;
		arr->num = 0;
		space->skipPostStep = cpFalse;
	}
}
Exemple #2
0
void
cpSpaceUnlock(cpSpace *space, cpBool runPostStep)
{
	space->locked--;
	cpAssertSoft(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, (cpBody *)waking->arr[i]);
		}
		
		waking->num = 0;
		
		cpSpaceRunPostStepCallbacks(space);
	}
}
static inline void
componentActivate(cpBody *root)
{
	if(!cpBodyIsSleeping(root)) return;

	cpSpace *space = root->space;
	cpAssert(space, "Trying to activate a body that was never added to a space.");

	cpBody *body = root, *next;
	do {
		next = body->node.next;

		cpComponentNode node = {NULL, NULL, 0, 0.0f};
		body->node = node;

		cpSpaceActivateBody(space, body);
	} while((body = next) != root);

	cpArrayDeleteObj(space->sleepingComponents, root);
}