comparison trunk/chipmunkd/cpSpace.d @ 23:4ceef5833c8c

updated to chipmunk 5.3.3
author Extrawurst
date Fri, 10 Dec 2010 02:10:27 +0100
parents df4ebc8add66
children 4541ca17975b
comparison
equal deleted inserted replaced
22:ed2c81f3d1df 23:4ceef5833c8c
24 cpCollisionPostSolveFunc postSolve; 24 cpCollisionPostSolveFunc postSolve;
25 cpCollisionSeparateFunc separate; 25 cpCollisionSeparateFunc separate;
26 void *data; 26 void *data;
27 } 27 }
28 28
29 enum CP_MAX_CONTACTS_PER_ARBITER = 6;
30 struct cpContactBufferHeader { 29 struct cpContactBufferHeader {
31 cpTimestamp stamp; 30 cpTimestamp stamp;
32 cpContactBufferHeader *next; 31 cpContactBufferHeader *next;
33 uint numContacts; 32 uint numContacts;
34 } 33 }
78 cpArray* arbiters, pooledArbiters; 77 cpArray* arbiters, pooledArbiters;
79 78
80 // Linked list ring of contact buffers. 79 // Linked list ring of contact buffers.
81 // Head is the newest buffer, and each buffer points to a newer buffer. 80 // Head is the newest buffer, and each buffer points to a newer buffer.
82 // Head wraps around and points to the oldest (tail) buffer. 81 // Head wraps around and points to the oldest (tail) buffer.
83 cpContactBufferHeader* contactBuffersHead, _contactBuffersTail; 82 cpContactBufferHeader* contactBuffersHead;
83 deprecated cpContactBufferHeader* _contactBuffersTail_Deprecated;
84 84
85 // List of buffers to be free()ed when destroying the space. 85 // List of buffers to be free()ed when destroying the space.
86 cpArray *allocatedBuffers; 86 cpArray *allocatedBuffers;
87 87
88 // Persistant contact set. 88 // Persistant contact set.
160 //cpShape *cpSpaceSegmentQueryFirst(cpSpace *space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo *out); 160 //cpShape *cpSpaceSegmentQueryFirst(cpSpace *space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo *out);
161 // 161 //
162 //// BB query callback function 162 //// BB query callback function
163 alias void function(cpShape *shape, void *data)cpSpaceBBQueryFunc; 163 alias void function(cpShape *shape, void *data)cpSpaceBBQueryFunc;
164 //void cpSpaceBBQuery(cpSpace *space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void *data); 164 //void cpSpaceBBQuery(cpSpace *space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void *data);
165 // 165
166 // 166 // Shape query callback function
167 alias void function(cpShape *shape, cpContactPointSet *points, void *data)cpSpaceShapeQueryFunc;
168 //cpBool cpSpaceShapeQuery(cpSpace *space, cpShape *shape, cpSpaceShapeQueryFunc func, void *data);
169
170
171 //void cpSpaceActivateShapesTouchingShape(cpSpace *space, cpShape *shape);
172
167 //// Iterator function for iterating the bodies in a space. 173 //// Iterator function for iterating the bodies in a space.
168 alias void function(cpBody *_body, void *data)cpSpaceBodyIterator; 174 alias void function(cpBody *_body, void *data)cpSpaceBodyIterator;
169 //void cpSpaceEachBody(cpSpace *space, cpSpaceBodyIterator func, void *data); 175 //void cpSpaceEachBody(cpSpace *space, cpSpaceBodyIterator func, void *data);
170 // 176 //
171 //// Spatial hash management functions. 177 //// Spatial hash management functions.
186 contactSetEql(cpShape **shapes, cpArbiter *arb) 192 contactSetEql(cpShape **shapes, cpArbiter *arb)
187 { 193 {
188 cpShape *a = shapes[0]; 194 cpShape *a = shapes[0];
189 cpShape *b = shapes[1]; 195 cpShape *b = shapes[1];
190 196
191 return ((a == arb.private_a && b == arb.private_b) || (b == arb.private_a && a == arb.private_b)); 197 return ((a == arb.a && b == arb.b) || (b == arb.a && a == arb.b));
192 } 198 }
193 199
194 // Transformation function for contactSet. 200 // Transformation function for contactSet.
195 static void * 201 static void *
196 contactSetTrans(cpShape **shapes, cpSpace *space) 202 contactSetTrans(cpShape **shapes, cpSpace *space)
455 cpSpaceHashInsert(space.activeShapes, shape, shape.hashid, shape.bb); 461 cpSpaceHashInsert(space.activeShapes, shape, shape.hashid, shape.bb);
456 462
457 return shape; 463 return shape;
458 } 464 }
459 465
460 static void
461 activateShapesTouchingShapeHelper(cpShape *shape, void *unused)
462 {
463 cpBodyActivate(shape._body);
464 }
465
466 static void
467 activateShapesTouchingShape(cpSpace *space, cpShape *shape)
468 {
469 // TODO this query should be more precise
470 // Use shape queries once they are written
471 cpSpaceBBQuery(space, shape.bb, shape.layers, shape.group, &activateShapesTouchingShapeHelper, null);
472 }
473
474 cpShape * 466 cpShape *
475 cpSpaceAddStaticShape(cpSpace *space, cpShape *shape) 467 cpSpaceAddStaticShape(cpSpace *space, cpShape *shape)
476 { 468 {
477 assert(!cpHashSetFind(space.staticShapes.handleSet, shape.hashid, shape), 469 assert(!cpHashSetFind(space.staticShapes.handleSet, shape.hashid, shape),
478 "Cannot add the same static shape more than once."); 470 "Cannot add the same static shape more than once.");
479 cpAssertSpaceUnlocked(space); 471 cpAssertSpaceUnlocked(space);
480 472
481 if(!shape._body) shape._body = &space.staticBody; 473 if(!shape._body) shape._body = &space.staticBody;
482 474
483 cpShapeCacheBB(shape); 475 cpShapeCacheBB(shape);
484 activateShapesTouchingShape(space, shape); 476 cpSpaceActivateShapesTouchingShape(space, shape);
485 cpSpaceHashInsert(space.staticShapes, shape, shape.hashid, shape.bb); 477 cpSpaceHashInsert(space.staticShapes, shape, shape.hashid, shape.bb);
486 478
487 return shape; 479 return shape;
488 } 480 }
489 481
490 cpBody * 482 cpBody *
491 cpSpaceAddBody(cpSpace *space, cpBody *_body) 483 cpSpaceAddBody(cpSpace *space, cpBody *_body)
492 { 484 {
493 mixin(cpAssertWarn!("_body.m != INFINITY", "Did you really mean to add an infinite mass body to the space?",__FILE__,__LINE__)); 485 mixin(cpAssertWarn!("!cpBodyIsStatic(_body)", "Static bodies cannot be added to a space as they are not meant to be simulated.",__FILE__,__LINE__));
494 assert(!_body.space, "Cannot add a body to a more than one space or to the same space twice."); 486 assert(!_body.space, "Cannot add a body to a more than one space or to the same space twice.");
495 // cpAssertSpaceUnlocked(space); This should be safe as long as it's not from an integration callback 487 // cpAssertSpaceUnlocked(space); This should be safe as long as it's not from an integration callback
496 488
497 cpArrayPush(space.bodies, _body); 489 cpArrayPush(space.bodies, _body);
498 _body.space = space; 490 _body.space = space;
523 515
524 // Hashset filter func to throw away old arbiters. 516 // Hashset filter func to throw away old arbiters.
525 static cpBool 517 static cpBool
526 contactSetFilterRemovedShape(cpArbiter *arb, removalContext *context) 518 contactSetFilterRemovedShape(cpArbiter *arb, removalContext *context)
527 { 519 {
528 if(context.shape == arb.private_a || context.shape == arb.private_b){ 520 if(context.shape == arb.a || context.shape == arb.b){
529 arb.handler.separate(arb, context.space, arb.handler.data); 521 if(arb.state != cpArbiterState.cpArbiterStateCached){
522 arb.handler.separate(arb, context.space, arb.handler.data);
523 }
524
530 cpArrayPush(context.space.pooledArbiters, arb); 525 cpArrayPush(context.space.pooledArbiters, arb);
531 return cpFalse; 526 return cpFalse;
532 } 527 }
533 528
534 return cpTrue; 529 return cpTrue;
565 560
566 removalContext context = {space, shape}; 561 removalContext context = {space, shape};
567 cpHashSetFilter(space.contactSet, cast(cpHashSetFilterFunc)&contactSetFilterRemovedShape, &context); 562 cpHashSetFilter(space.contactSet, cast(cpHashSetFilterFunc)&contactSetFilterRemovedShape, &context);
568 cpSpaceHashRemove(space.staticShapes, shape, shape.hashid); 563 cpSpaceHashRemove(space.staticShapes, shape, shape.hashid);
569 564
570 activateShapesTouchingShape(space, shape); 565 cpSpaceActivateShapesTouchingShape(space, shape);
571 } 566 }
572 567
573 void 568 void
574 cpSpaceRemoveBody(cpSpace *space, cpBody *_body) 569 cpSpaceRemoveBody(cpSpace *space, cpBody *_body)
575 { 570 {