Mercurial > projects > chipmunkd
diff trunk/chipmunkd/cpSpaceComponent.d @ 23:4ceef5833c8c
updated to chipmunk 5.3.3
author | Extrawurst |
---|---|
date | Fri, 10 Dec 2010 02:10:27 +0100 |
parents | df4ebc8add66 |
children | 80058cee1a77 |
line wrap: on
line diff
--- a/trunk/chipmunkd/cpSpaceComponent.d Thu Dec 09 22:25:04 2010 +0100 +++ b/trunk/chipmunkd/cpSpaceComponent.d Fri Dec 10 02:10:27 2010 +0100 @@ -42,15 +42,17 @@ cpSpace *space = root.space; assert(space, "Trying to activate a body that was never added to a space."); + assert(!space.locked, "Bodies can not be awakened during a query or a call to cpSpaceSte(). Put these calls into a post-step callback."); - cpBody* _body = root; - cpBody* next; + cpBody *_body = root; + cpBody *next; do { next = _body.node.next; - cpComponentNode node = {null, null, 0, 0.0f}; + cpFloat idleTime = (cpBodyIsStatic(_body) ? cast(cpFloat)INFINITY : 0.0f); + cpComponentNode node = {null, null, 0, idleTime}; _body.node = node; - cpArrayPush(space.bodies, _body); + if(!cpBodyIsRogue(_body)) cpArrayPush(space.bodies, _body); for(cpShape *shape=_body.shapesList; shape; shape=shape.next){ cpSpaceHashRemove(space.staticShapes, shape, shape.hashid); @@ -66,7 +68,7 @@ { // Reset the idle time even if it's not in a currently sleeping component // Like a body resting on or jointed to a rogue body. - _body.node.idleTime = 0.0f; + if(!cpBodyIsStatic(_body)) _body.node.idleTime = 0.0f; componentActivate(componentNodeRoot(_body)); } @@ -90,8 +92,8 @@ } // Add any rogue bodies (bodies not added to the space) - if(!a.space) cpArrayPush(rogueBodies, a); - if(!b.space) cpArrayPush(rogueBodies, b); + if(cpBodyIsRogue(a)) cpArrayPush(rogueBodies, a); + if(cpBodyIsRogue(b)) cpArrayPush(rogueBodies, b); componentNodeMerge(a_root, b_root); } @@ -103,7 +105,7 @@ cpBody *next; do { next = _body.node.next; - if(cpBodyIsRogue(_body) || _body.node.idleTime < threshold) return cpTrue; + if(_body.node.idleTime < threshold) return cpTrue; } while((_body = next) != root); return cpFalse; @@ -155,7 +157,7 @@ // iterate graph edges and build forests for(int i=0; i<arbiters.num; i++){ cpArbiter *arb = cast(cpArbiter*)arbiters.arr[i]; - mergeBodies(space, components, rogueBodies, arb.private_a._body, arb.private_b._body); + mergeBodies(space, components, rogueBodies, arb.a._body, arb.b._body); } for(int j=0; j<constraints.num; j++){ cpConstraint *constraint = cast(cpConstraint *)constraints.arr[j]; @@ -205,9 +207,21 @@ } void -cpSpaceSleepBody(cpSpace *space, cpBody *_body){ - cpComponentNode node = {null, _body, 0, 0.0f}; - _body.node = node; +cpBodySleep(cpBody *_body) +{ + cpBodySleepWithGroup(_body, null); +} + +void +cpBodySleepWithGroup(cpBody *_body, cpBody *group){ + assert(!cpBodyIsStatic(_body) && !cpBodyIsRogue(_body), "Rogue and static bodies cannot be put to sleep."); + + cpSpace *space = _body.space; + assert(space, "Cannot put a body to sleep that has not been added to a space."); + assert(!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."); + assert(!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){ cpSpaceHashRemove(space.activeShapes, shape, shape.hashid); @@ -216,6 +230,37 @@ cpSpaceHashInsert(space.staticShapes, shape, shape.hashid, shape.bb); } - cpArrayPush(space.sleepingComponents, _body); + 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); } + +static void +activateTouchingHelper(cpShape *shape, cpContactPointSet *points, cpArray **bodies){ + if(*bodies == null) (*bodies) = cpArrayNew(0); + cpArrayPush(*bodies, shape._body); +} + +void +cpSpaceActivateShapesTouchingShape(cpSpace *space, cpShape *shape){ + cpArray *bodies = null; + cpSpaceShapeQuery(space, shape, cast(cpSpaceShapeQueryFunc)&activateTouchingHelper, &bodies); + + if(bodies){ + for(int i=0; i<bodies.num; i++){ + cpBody *_body = cast(cpBody *)bodies.arr[i]; + cpBodyActivate(_body); + } + } +}