void cpBodySleepWithGroup(cpBody *body, cpBody *group){ cpAssert(!cpBodyIsStatic(body) && !cpBodyIsRogue(body), "Rogue and static bodies cannot be put to sleep."); cpSpace *space = body->space; cpAssert(space, "Cannot put a body to sleep that has not been added to a space."); cpAssert(!space->locked, "Bodies can not be put to sleep during a query or a call to cpSpaceSte(). Put these calls into a post-step callback."); cpAssert(!group || cpBodyIsSleeping(group), "Cannot use a non-sleeping body as a group identifier."); if(cpBodyIsSleeping(body)) return; for(cpShape *shape = body->shapesList; shape; shape = shape->next){ cpShapeCacheBB(shape); cpSpaceHashRemove(space->activeShapes, shape, shape->hashid); cpSpaceHashInsert(space->staticShapes, shape, shape->hashid, shape->bb); } if(group){ cpBody *root = componentNodeRoot(group); cpComponentNode node = {root, root->node.next, 0, 0.0f}; body->node = node; root->node.next = body; } else { cpComponentNode node = {NULL, body, 0, 0.0f}; body->node = node; cpArrayPush(space->sleepingComponents, body); } cpArrayDeleteObj(space->bodies, body); }
void cpSpaceRemoveConstraint(cpSpace *space, cpConstraint *constraint) { assert(cpArrayContains(space->constraints, constraint)); cpArrayDeleteObj(space->constraints, constraint); }
void cpSpaceRemoveBody(cpSpace *space, cpBody *body) { assert(cpArrayContains(space->bodies, body)); cpArrayDeleteObj(space->bodies, body); }
static cpBool cachedArbitersFilter(cpArbiter *arb, struct arbiterFilterContext *context) { cpShape *shape = context->shape; cpBody *body = context->body; // Match on the filter shape, or if it's NULL the filter body if( (body == arb->body_a && (shape == arb->a || shape == NULL)) || (body == arb->body_b && (shape == arb->b || shape == NULL)) ){ // Call separate when removing shapes. if(shape && arb->state != CP_ARBITER_STATE_CACHED){ // Invalidate the arbiter since one of the shapes was removed. arb->state = CP_ARBITER_STATE_INVALIDATED; cpCollisionHandler *handler = arb->handler; handler->separateFunc(arb, context->space, handler->userData); } cpArbiterUnthread(arb); cpArrayDeleteObj(context->space->arbiters, arb); cpArrayPush(context->space->pooledArbiters, arb); return cpFalse; } return cpTrue; }
void cpSpaceRemoveBody(cpSpace *space, cpBody *body) { cpAssert(cpArrayContains(space->bodies, body), "Cannot remove a body that was never added to the space."); cpAssertSpaceUnlocked(space); cpArrayDeleteObj(space->bodies, body); }
void cpSpaceRemoveConstraint(cpSpace *space, cpConstraint *constraint) { cpAssert(cpArrayContains(space->constraints, constraint), "Cannot remove a constraint that was never added to the space."); // cpAssertSpaceUnlocked(space); Should be safe as long as its not from a constraint callback. cpArrayDeleteObj(space->constraints, constraint); }
void cpSpaceRemoveConstraint(cpSpace *space, cpConstraint *constraint) { cpAssertWarn(cpArrayContains(space->constraints, constraint), "Cannot remove a constraint that was not added to the space. (Removed twice maybe?)"); // cpAssertSpaceUnlocked(space); Should be safe as long as its not from a constraint callback. cpBodyActivate(constraint->a); cpBodyActivate(constraint->b); cpArrayDeleteObj(space->constraints, constraint); }
void cpSpaceRemoveBody(cpSpace *space, cpBody *body) { cpAssertWarn(body->space == space, "Cannot remove a body that was not added to the space. (Removed twice maybe?)"); cpAssertSpaceUnlocked(space); cpBodyActivate(body); cpArrayDeleteObj(space->bodies, body); body->space = NULL; }
void cpSpaceRemoveBody(cpSpace *space, cpBody *body) { cpAssertHard(cpSpaceContainsBody(space, body), "Cannot remove a body that was not added to the space. (Removed twice maybe?)"); cpAssertSpaceUnlocked(space); cpBodyActivate(body); // cpSpaceFilterArbiters(space, body, NULL); cpArrayDeleteObj(space->bodies, body); body->space = NULL; }
static void separate(cpArbiter *arb, cpSpace *space, void *ignore) { CP_ARBITER_GET_SHAPES(arb, a, b); PlayerStruct *player = a->data; cpArrayDeleteObj(player->groundShapes, b); if(player->groundShapes->num == 0){ a->u = 0.0f; } }
void cpSpaceRemoveConstraint(cpSpace *space, cpConstraint *constraint) { cpAssertHard(cpSpaceContainsConstraint(space, constraint), "Cannot remove a constraint that was not added to the space. (Removed twice maybe?)"); cpAssertSpaceUnlocked(space); cpBodyActivate(constraint->a); cpBodyActivate(constraint->b); cpArrayDeleteObj(space->constraints, constraint); cpBodyRemoveConstraint(constraint->a, constraint); cpBodyRemoveConstraint(constraint->b, constraint); constraint->space = NULL; }
void cpSpaceRemoveBody(cpSpace *space, cpBody *body) { cpAssertHard(body != cpSpaceGetStaticBody(space), "Cannot remove the designated static body for the space."); cpAssertHard(cpSpaceContainsBody(space, body), "Cannot remove a body that was not added to the space. (Removed twice maybe?)"); // cpAssertHard(body->shapeList == NULL, "Cannot remove a body from the space before removing the bodies attached to it."); // cpAssertHard(body->constraintList == NULL, "Cannot remove a body from the space before removing the constraints attached to it."); cpAssertSpaceUnlocked(space); cpBodyActivate(body); // cpSpaceFilterArbiters(space, body, NULL); cpArrayDeleteObj(cpSpaceArrayForBodyType(space, cpBodyGetType(body)), body); body->space = NULL; }
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); }
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; body->node.next = NULL; body->node.idleTime = 0.0f; cpArrayPush(space->bodies, body); for(cpShape *shape=body->shapesList; shape; shape=shape->next){ removeShapeRaw(shape, space->staticShapes); addShapeRaw(shape, space->activeShapes); } } while((body = next) != root); cpArrayDeleteObj(space->sleepingComponents, root); }
static cpBool cachedArbitersFilter(cpArbiter *arb, struct arbiterFilterContext *context) { cpShape *shape = context->shape; cpBody *body = context->body; // Match on the filter shape, or if it's NULL the filter body if( (body == arb->body_a && (shape == arb->a || shape == NULL)) || (body == arb->body_b && (shape == arb->b || shape == NULL)) ){ // Call separate when removing shapes. if(shape && arb->state != cpArbiterStateCached) cpArbiterCallSeparate(arb, context->space); cpArbiterUnthread(arb); cpArrayDeleteObj(context->space->arbiters, arb); cpArrayPush(context->space->pooledArbiters, arb); return cpFalse; } return cpTrue; }
void cpSpaceRemoveJoint(cpSpace *space, cpJoint *joint) { cpArrayDeleteObj(space->joints, joint); }
void cpSpaceRemoveBody(cpSpace *space, cpBody *body) { cpArrayDeleteObj(space->bodies, body); }