annotate trunk/chipmunkd/cpSpace.d @ 4:7ebbd4d05553

initial commit
author Extrawurst
date Thu, 02 Dec 2010 02:11:26 +0100
parents
children c03a41d47b60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
1
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
2 // written in the D programming language
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
3
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
4 module chipmunkd.cpSpace;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
5
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
6 import chipmunkd.chipmunk;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
7 import chipmunkd.chipmunk_types_h;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
8 import chipmunkd.cpVect,chipmunkd.cpVect_h;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
9 import chipmunkd.cpHashSet;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
10 import chipmunkd.cpCollision;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
11 import chipmunkd.cpBody;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
12 import chipmunkd.cpArray;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
13 import chipmunkd.cpShape;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
14 import chipmunkd.cpBB;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
15 import chipmunkd.cpArbiter;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
16 import chipmunkd.cpSpaceHash;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
17 import chipmunkd.constraints.cpConstraint;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
18 import chipmunkd.cpSpaceQuery;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
19
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
20 // Number of frames that contact information should persist.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
21 //extern cpTimestamp cp_contact_persistence;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
22
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
23 // User collision handler function types.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
24 alias cpBool function(cpArbiter *arb, cpSpace *space, void *data)cpCollisionBeginFunc;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
25 alias cpBool function(cpArbiter *arb, cpSpace *space, void *data)cpCollisionPreSolveFunc;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
26 alias void function(cpArbiter *arb, cpSpace *space, void *data)cpCollisionPostSolveFunc;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
27 alias void function(cpArbiter *arb, cpSpace *space, void *data)cpCollisionSeparateFunc;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
28
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
29 // Structure for holding collision pair function information.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
30 // Used internally.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
31 struct cpCollisionHandler {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
32 cpCollisionType a;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
33 cpCollisionType b;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
34 cpCollisionBeginFunc begin;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
35 cpCollisionPreSolveFunc preSolve;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
36 cpCollisionPostSolveFunc postSolve;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
37 cpCollisionSeparateFunc separate;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
38 void *data;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
39 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
40
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
41 enum CP_MAX_CONTACTS_PER_ARBITER = 6;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
42 struct cpContactBufferHeader {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
43 cpTimestamp stamp;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
44 cpContactBufferHeader *next;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
45 uint numContacts;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
46 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
47
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
48 struct cpSpace{
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
49 // *** User definable fields
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
50
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
51 // Number of iterations to use in the impulse solver to solve contacts.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
52 int iterations;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
53
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
54 // Number of iterations to use in the impulse solver to solve elastic collisions.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
55 int elasticIterations;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
56
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
57 // Default gravity to supply when integrating rigid body motions.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
58 cpVect gravity;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
59
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
60 // Default damping to supply when integrating rigid body motions.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
61 cpFloat damping;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
62
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
63 // Speed threshold for a body to be considered idle.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
64 // The default value of 0 means to let the space guess a good threshold based on gravity.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
65 cpFloat idleSpeedThreshold;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
66
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
67 // Time a group of bodies must remain idle in order to fall asleep
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
68 // The default value of INFINITY disables the sleeping algorithm.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
69 cpFloat sleepTimeThreshold;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
70
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
71 // *** Internally Used Fields
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
72
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
73 // When the space is locked, you should not add or remove objects;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
74 cpBool locked;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
75
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
76 // Time stamp. Is incremented on every call to cpSpaceStep().
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
77 cpTimestamp stamp;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
78
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
79 // The static and active shape spatial hashes.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
80 cpSpaceHash* staticShapes;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
81 cpSpaceHash* activeShapes;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
82
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
83 // List of bodies in the system.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
84 cpArray *bodies;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
85
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
86 // List of groups of sleeping bodies.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
87 cpArray *sleepingComponents;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
88
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
89 // List of active arbiters for the impulse solver.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
90 cpArray* arbiters, pooledArbiters;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
91
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
92 // Linked list ring of contact buffers.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
93 // Head is the newest buffer, and each buffer points to a newer buffer.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
94 // Head wraps around and points to the oldest (tail) buffer.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
95 cpContactBufferHeader* contactBuffersHead, _contactBuffersTail;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
96
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
97 // List of buffers to be free()ed when destroying the space.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
98 cpArray *allocatedBuffers;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
99
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
100 // Persistant contact set.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
101 cpHashSet *contactSet;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
102
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
103 // List of constraints in the system.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
104 cpArray *constraints;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
105
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
106 // Set of collisionpair functions.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
107 cpHashSet *collFuncSet;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
108 // Default collision handler.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
109 cpCollisionHandler defaultHandler;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
110
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
111 cpHashSet *postStepCallbacks;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
112
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
113 cpBody staticBody;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
114 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
115
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
116 //// Basic allocation/destruction functions.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
117 //cpSpace* cpSpaceAlloc(void);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
118 //cpSpace* cpSpaceInit(cpSpace *space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
119 //cpSpace* cpSpaceNew(void);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
120 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
121 //void cpSpaceDestroy(cpSpace *space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
122 //void cpSpaceFree(cpSpace *space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
123 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
124 //// Convenience function. Frees all referenced entities. (bodies, shapes and constraints)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
125 //void cpSpaceFreeChildren(cpSpace *space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
126 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
127 //// Collision handler management functions.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
128 //void cpSpaceSetDefaultCollisionHandler(
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
129 // cpSpace *space,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
130 // cpCollisionBeginFunc begin,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
131 // cpCollisionPreSolveFunc preSolve,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
132 // cpCollisionPostSolveFunc postSolve,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
133 // cpCollisionSeparateFunc separate,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
134 // void *data
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
135 //);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
136 //void cpSpaceAddCollisionHandler(
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
137 // cpSpace *space,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
138 // cpCollisionType a, cpCollisionType b,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
139 // cpCollisionBeginFunc begin,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
140 // cpCollisionPreSolveFunc preSolve,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
141 // cpCollisionPostSolveFunc postSolve,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
142 // cpCollisionSeparateFunc separate,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
143 // void *data
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
144 //);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
145 //void cpSpaceRemoveCollisionHandler(cpSpace *space, cpCollisionType a, cpCollisionType b);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
146 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
147 //// Add and remove entities from the system.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
148 //cpShape *cpSpaceAddShape(cpSpace *space, cpShape *shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
149 //cpShape *cpSpaceAddStaticShape(cpSpace *space, cpShape *shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
150 //cpBody *cpSpaceAddBody(cpSpace *space, cpBody *body);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
151 //cpConstraint *cpSpaceAddConstraint(cpSpace *space, cpConstraint *constraint);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
152 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
153 //void cpSpaceRemoveShape(cpSpace *space, cpShape *shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
154 //void cpSpaceRemoveStaticShape(cpSpace *space, cpShape *shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
155 //void cpSpaceRemoveBody(cpSpace *space, cpBody *body);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
156 //void cpSpaceRemoveConstraint(cpSpace *space, cpConstraint *constraint);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
157 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
158 //// Post Step function definition
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
159 alias void function(cpSpace *space, void *obj, void *data) cpPostStepFunc;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
160 //// Register a post step function to be called after cpSpaceStep() has finished.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
161 //// obj is used a key, you can only register one callback per unique value for obj
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
162 //void cpSpaceAddPostStepCallback(cpSpace *space, cpPostStepFunc func, void *obj, void *data);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
163 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
164 //// Point query callback function
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
165 alias void function(cpShape *shape, void *data) cpSpacePointQueryFunc;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
166 //void cpSpacePointQuery(cpSpace *space, cpVect point, cpLayers layers, cpGroup group, cpSpacePointQueryFunc func, void *data);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
167 //cpShape *cpSpacePointQueryFirst(cpSpace *space, cpVect point, cpLayers layers, cpGroup group);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
168 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
169 //// Segment query callback function
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
170 alias void function(cpShape *shape, cpFloat t, cpVect n, void *data)cpSpaceSegmentQueryFunc;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
171 //void cpSpaceSegmentQuery(cpSpace *space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSpaceSegmentQueryFunc func, void *data);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
172 //cpShape *cpSpaceSegmentQueryFirst(cpSpace *space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo *out);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
173 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
174 //// BB query callback function
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
175 alias void function(cpShape *shape, void *data)cpSpaceBBQueryFunc;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
176 //void cpSpaceBBQuery(cpSpace *space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void *data);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
177 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
178 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
179 //// Iterator function for iterating the bodies in a space.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
180 alias void function(cpBody *_body, void *data)cpSpaceBodyIterator;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
181 //void cpSpaceEachBody(cpSpace *space, cpSpaceBodyIterator func, void *data);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
182 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
183 //// Spatial hash management functions.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
184 //void cpSpaceResizeStaticHash(cpSpace *space, cpFloat dim, int count);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
185 //void cpSpaceResizeActiveHash(cpSpace *space, cpFloat dim, int count);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
186 //void cpSpaceRehashStatic(cpSpace *space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
187 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
188 //void cpSpaceRehashShape(cpSpace *space, cpShape *shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
189 //
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
190 //// Update the space.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
191 //void cpSpaceStep(cpSpace *space, cpFloat dt);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
192
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
193
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
194 cpTimestamp cp_contact_persistence = 3;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
195
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
196 // Equal function for contactSet.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
197 static cpBool
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
198 contactSetEql(cpShape **shapes, cpArbiter *arb)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
199 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
200 cpShape *a = shapes[0];
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
201 cpShape *b = shapes[1];
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
202
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
203 return ((a == arb.private_a && b == arb.private_b) || (b == arb.private_a && a == arb.private_b));
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
204 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
205
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
206 // Transformation function for contactSet.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
207 static void *
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
208 contactSetTrans(cpShape **shapes, cpSpace *space)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
209 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
210 if(space.pooledArbiters.num == 0){
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
211 // arbiter pool is exhausted, make more
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
212 int count = CP_BUFFER_BYTES/cpArbiter.sizeof;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
213 assert(count, "Buffer size too small.");
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
214
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
215 cpArbiter *buffer = cast(cpArbiter *)cpmalloc(CP_BUFFER_BYTES);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
216 cpArrayPush(space.allocatedBuffers, buffer);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
217
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
218 for(int i=0; i<count; i++) cpArrayPush(space.pooledArbiters, buffer + i);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
219 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
220
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
221 return cpArbiterInit(cast(cpArbiter *) cpArrayPop(space.pooledArbiters), shapes[0], shapes[1]);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
222 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
223
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
224 // Equals function for collFuncSet.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
225 static cpBool
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
226 collFuncSetEql(cpCollisionHandler *check, cpCollisionHandler *pair)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
227 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
228 return ((check.a == pair.a && check.b == pair.b) || (check.b == pair.a && check.a == pair.b));
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
229 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
230
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
231 // Transformation function for collFuncSet.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
232 static void *
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
233 collFuncSetTrans(cpCollisionHandler *handler, void *unused)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
234 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
235 cpCollisionHandler *copy = cast(cpCollisionHandler *)cpmalloc(cpCollisionHandler.sizeof);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
236 (*copy) = (*handler);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
237
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
238 return copy;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
239 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
240
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
241 // Default collision functions.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
242 static cpBool alwaysCollide(cpArbiter *arb, cpSpace *space, void *data){return 1;}
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
243 static void nothing(cpArbiter *arb, cpSpace *space, void *data){}
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
244
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
245 // BBfunc callback for the spatial hash.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
246 static cpBB shapeBBFunc(cpShape *shape){return shape.bb;}
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
247
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
248 // Iterator functions for destructors.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
249 static void freeWrap(void *ptr, void *unused){ cpfree(ptr);}
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
250 static void shapeFreeWrap(cpShape *ptr, void *unused){ cpShapeFree(ptr);}
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
251 static void bodyFreeWrap(cpBody *ptr, void *unused){ cpBodyFree(ptr);}
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
252 static void constraintFreeWrap(cpConstraint *ptr, void *unused){cpConstraintFree(ptr);}
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
253
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
254 cpSpace *
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
255 cpSpaceAlloc()
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
256 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
257 return cast(cpSpace *)cpcalloc(1, cpSpace.sizeof);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
258 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
259
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
260 enum DEFAULT_DIM_SIZE = 100.0f;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
261 enum DEFAULT_COUNT = 1000;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
262 enum DEFAULT_ITERATIONS = 10;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
263 enum DEFAULT_ELASTIC_ITERATIONS = 0;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
264
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
265 cpCollisionHandler defaultHandler = {0, 0, &alwaysCollide, &alwaysCollide, &nothing, &nothing, null};
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
266
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
267 cpSpace*
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
268 cpSpaceInit(cpSpace *space)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
269 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
270 space.iterations = DEFAULT_ITERATIONS;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
271 space.elasticIterations = DEFAULT_ELASTIC_ITERATIONS;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
272 // space.sleepTicks = 300;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
273
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
274 space.gravity = cpvzero;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
275 space.damping = 1.0f;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
276
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
277 space.locked = 0;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
278 space.stamp = 0;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
279
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
280 space.staticShapes = cpSpaceHashNew(DEFAULT_DIM_SIZE, DEFAULT_COUNT, cast(cpSpaceHashBBFunc)&shapeBBFunc);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
281 space.activeShapes = cpSpaceHashNew(DEFAULT_DIM_SIZE, DEFAULT_COUNT, cast(cpSpaceHashBBFunc)&shapeBBFunc);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
282
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
283 space.allocatedBuffers = cpArrayNew(0);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
284
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
285 space.bodies = cpArrayNew(0);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
286 space.sleepingComponents = cpArrayNew(0);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
287 space.sleepTimeThreshold = INFINITY;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
288 space.idleSpeedThreshold = 0.0f;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
289
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
290 space.arbiters = cpArrayNew(0);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
291 space.pooledArbiters = cpArrayNew(0);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
292
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
293 space.contactBuffersHead = null;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
294 space.contactSet = cpHashSetNew(0, cast(cpHashSetEqlFunc)&contactSetEql, cast(cpHashSetTransFunc)&contactSetTrans);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
295
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
296 space.constraints = cpArrayNew(0);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
297
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
298 space.defaultHandler = defaultHandler;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
299 space.collFuncSet = cpHashSetNew(0, cast(cpHashSetEqlFunc)&collFuncSetEql, cast(cpHashSetTransFunc)&collFuncSetTrans);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
300 space.collFuncSet.default_value = &space.defaultHandler;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
301
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
302 space.postStepCallbacks = null;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
303
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
304 cpBodyInit(&space.staticBody, INFINITY, INFINITY);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
305 space.staticBody.space = space;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
306
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
307 return space;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
308 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
309
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
310 cpSpace*
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
311 cpSpaceNew()
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
312 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
313 return cpSpaceInit(cpSpaceAlloc());
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
314 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
315
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
316 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
317 cpSpaceDestroy(cpSpace *space)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
318 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
319 cpSpaceHashFree(space.staticShapes);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
320 cpSpaceHashFree(space.activeShapes);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
321
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
322 cpArrayFree(space.bodies);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
323 cpArrayFree(space.sleepingComponents);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
324
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
325 cpArrayFree(space.constraints);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
326
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
327 cpHashSetFree(space.contactSet);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
328
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
329 cpArrayFree(space.arbiters);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
330 cpArrayFree(space.pooledArbiters);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
331
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
332 if(space.allocatedBuffers){
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
333 cpArrayEach(space.allocatedBuffers, &freeWrap, null);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
334 cpArrayFree(space.allocatedBuffers);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
335 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
336
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
337 if(space.postStepCallbacks){
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
338 cpHashSetEach(space.postStepCallbacks, &freeWrap, null);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
339 cpHashSetFree(space.postStepCallbacks);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
340 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
341
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
342 if(space.collFuncSet){
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
343 cpHashSetEach(space.collFuncSet, &freeWrap, null);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
344 cpHashSetFree(space.collFuncSet);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
345 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
346 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
347
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
348 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
349 cpSpaceFree(cpSpace *space)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
350 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
351 if(space){
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
352 cpSpaceDestroy(space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
353 cpfree(space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
354 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
355 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
356
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
357 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
358 cpSpaceFreeChildren(cpSpace *space)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
359 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
360 cpArray *components = space.sleepingComponents;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
361 while(components.num) cpBodyActivate(cast(cpBody *)components.arr[0]);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
362
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
363 cpSpaceHashEach(space.staticShapes, cast(cpSpaceHashIterator)&shapeFreeWrap, null);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
364 cpSpaceHashEach(space.activeShapes, cast(cpSpaceHashIterator)&shapeFreeWrap, null);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
365 cpArrayEach(space.bodies, cast(cpArrayIter)&bodyFreeWrap, null);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
366 cpArrayEach(space.constraints, cast(cpArrayIter)&constraintFreeWrap, null);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
367 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
368
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
369 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
370 cpSpaceAddCollisionHandler(
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
371 cpSpace *space,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
372 cpCollisionType a, cpCollisionType b,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
373 cpCollisionBeginFunc begin,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
374 cpCollisionPreSolveFunc preSolve,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
375 cpCollisionPostSolveFunc postSolve,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
376 cpCollisionSeparateFunc separate,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
377 void *data
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
378 ){
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
379 // Remove any old function so the new one will get added.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
380 cpSpaceRemoveCollisionHandler(space, a, b);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
381
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
382 cpCollisionHandler handler = {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
383 a, b,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
384 begin ? begin : &alwaysCollide,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
385 preSolve ? preSolve : &alwaysCollide,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
386 postSolve ? postSolve : &nothing,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
387 separate ? separate : &nothing,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
388 data
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
389 };
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
390
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
391 cpHashSetInsert(space.collFuncSet, CP_HASH_PAIR(a, b), &handler, null);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
392 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
393
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
394 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
395 cpSpaceRemoveCollisionHandler(cpSpace *space, cpCollisionType a, cpCollisionType b)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
396 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
397 struct tmp{cpCollisionType a, b;} tmp ids = {a, b};
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
398 cpCollisionHandler *old_handler = cast(cpCollisionHandler *) cpHashSetRemove(space.collFuncSet, CP_HASH_PAIR(a, b), &ids);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
399 cpfree(old_handler);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
400 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
401
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
402 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
403 cpSpaceSetDefaultCollisionHandler(
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
404 cpSpace *space,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
405 cpCollisionBeginFunc begin,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
406 cpCollisionPreSolveFunc preSolve,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
407 cpCollisionPostSolveFunc postSolve,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
408 cpCollisionSeparateFunc separate,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
409 void *data
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
410 ){
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
411 cpCollisionHandler handler = {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
412 0, 0,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
413 begin ? begin : &alwaysCollide,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
414 preSolve ? preSolve : &alwaysCollide,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
415 postSolve ? postSolve : &nothing,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
416 separate ? separate : &nothing,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
417 data
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
418 };
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
419
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
420 space.defaultHandler = handler;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
421 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
422
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
423 //#pragma mark Body, Shape, and Joint Management
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
424
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
425 void cpAssertSpaceUnlocked(cpSpace* _space){
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
426 assert(!_space.locked,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
427 "This addition/removal cannot be done safely during a call to cpSpaceStep(). "
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
428 "Put these calls into a Post Step Callback."
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
429 );}
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
430
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
431 static void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
432 cpBodyAddShape(cpBody *_body, cpShape *shape)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
433 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
434 shape.next = shape._body.shapesList;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
435 shape._body.shapesList = shape;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
436 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
437
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
438 static void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
439 cpBodyRemoveShape(cpBody *_body, cpShape *shape)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
440 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
441 cpShape **prev_ptr = &_body.shapesList;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
442 cpShape *node = _body.shapesList;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
443
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
444 while(node && node != shape){
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
445 prev_ptr = &node.next;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
446 node = node.next;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
447 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
448
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
449 assert(node, "Attempted to remove a shape from a body it was never attached to.");
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
450 (*prev_ptr) = node.next;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
451 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
452
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
453 cpShape *
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
454 cpSpaceAddShape(cpSpace *space, cpShape *shape)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
455 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
456 cpBody *_body = shape._body;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
457 if(!_body || _body == &space.staticBody) return cpSpaceAddStaticShape(space, shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
458
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
459 assert(!cpHashSetFind(space.activeShapes.handleSet, shape.hashid, shape),
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
460 "Cannot add the same shape more than once.");
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
461 cpAssertSpaceUnlocked(space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
462
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
463 cpBodyActivate(_body);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
464 cpBodyAddShape(_body, shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
465
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
466 cpShapeCacheBB(shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
467 cpSpaceHashInsert(space.activeShapes, shape, shape.hashid, shape.bb);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
468
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
469 return shape;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
470 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
471
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
472 static void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
473 activateShapesTouchingShapeHelper(cpShape *shape, void *unused)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
474 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
475 cpBodyActivate(shape._body);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
476 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
477
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
478 static void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
479 activateShapesTouchingShape(cpSpace *space, cpShape *shape)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
480 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
481 // TODO this query should be more precise
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
482 // Use shape queries once they are written
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
483 cpSpaceBBQuery(space, shape.bb, shape.layers, shape.group, &activateShapesTouchingShapeHelper, null);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
484 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
485
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
486 cpShape *
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
487 cpSpaceAddStaticShape(cpSpace *space, cpShape *shape)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
488 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
489 assert(!cpHashSetFind(space.staticShapes.handleSet, shape.hashid, shape),
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
490 "Cannot add the same static shape more than once.");
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
491 cpAssertSpaceUnlocked(space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
492
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
493 if(!shape._body) shape._body = &space.staticBody;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
494
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
495 cpShapeCacheBB(shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
496 activateShapesTouchingShape(space, shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
497 cpSpaceHashInsert(space.staticShapes, shape, shape.hashid, shape.bb);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
498
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
499 return shape;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
500 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
501
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
502 cpBody *
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
503 cpSpaceAddBody(cpSpace *space, cpBody *_body)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
504 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
505 cpAssertWarn(_body.m != INFINITY, "Did you really mean to add an infinite mass body to the space?");
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
506 assert(!_body.space, "Cannot add a body to a more than one space or to the same space twice.");
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
507 // cpAssertSpaceUnlocked(space); This should be safe as long as it's not from an integration callback
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
508
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
509 cpArrayPush(space.bodies, _body);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
510 _body.space = space;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
511
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
512 return _body;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
513 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
514
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
515 cpConstraint *
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
516 cpSpaceAddConstraint(cpSpace *space, cpConstraint *constraint)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
517 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
518 assert(!cpArrayContains(space.constraints, constraint), "Cannot add the same constraint more than once.");
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
519 // cpAssertSpaceUnlocked(space); This should be safe as long as its not from a constraint callback.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
520
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
521 if(!constraint.a) constraint.a = &space.staticBody;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
522 if(!constraint.b) constraint.b = &space.staticBody;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
523
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
524 cpBodyActivate(constraint.a);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
525 cpBodyActivate(constraint.b);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
526 cpArrayPush(space.constraints, constraint);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
527
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
528 return constraint;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
529 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
530
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
531 struct removalContext {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
532 cpSpace *space;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
533 cpShape *shape;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
534 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
535
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
536 // Hashset filter func to throw away old arbiters.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
537 static cpBool
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
538 contactSetFilterRemovedShape(cpArbiter *arb, removalContext *context)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
539 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
540 if(context.shape == arb.private_a || context.shape == arb.private_b){
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
541 arb.handler.separate(arb, context.space, arb.handler.data);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
542 cpArrayPush(context.space.pooledArbiters, arb);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
543 return cpFalse;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
544 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
545
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
546 return cpTrue;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
547 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
548
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
549 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
550 cpSpaceRemoveShape(cpSpace *space, cpShape *shape)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
551 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
552 cpBody *_body = shape._body;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
553 if(cpBodyIsStatic(_body)){
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
554 cpSpaceRemoveStaticShape(space, shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
555 return;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
556 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
557
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
558 cpBodyActivate(_body);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
559
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
560 cpAssertSpaceUnlocked(space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
561 cpAssertWarn(cpHashSetFind(space.activeShapes.handleSet, shape.hashid, shape) !is null,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
562 "Cannot remove a shape that was never added to the space. (Removed twice maybe?)");
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
563
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
564 cpBodyRemoveShape(_body, shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
565
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
566 removalContext context = {space, shape};
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
567 cpHashSetFilter(space.contactSet, cast(cpHashSetFilterFunc)&contactSetFilterRemovedShape, &context);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
568 cpSpaceHashRemove(space.activeShapes, shape, shape.hashid);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
569 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
570
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
571 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
572 cpSpaceRemoveStaticShape(cpSpace *space, cpShape *shape)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
573 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
574 cpAssertWarn(cpHashSetFind(space.staticShapes.handleSet, shape.hashid, shape) !is null,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
575 "Cannot remove a static or sleeping shape that was never added to the space. (Removed twice maybe?)");
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
576 cpAssertSpaceUnlocked(space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
577
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
578 removalContext context = {space, shape};
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
579 cpHashSetFilter(space.contactSet, cast(cpHashSetFilterFunc)&contactSetFilterRemovedShape, &context);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
580 cpSpaceHashRemove(space.staticShapes, shape, shape.hashid);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
581
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
582 activateShapesTouchingShape(space, shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
583 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
584
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
585 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
586 cpSpaceRemoveBody(cpSpace *space, cpBody *_body)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
587 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
588 cpAssertWarn(_body.space == space,
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
589 "Cannot remove a body that was never added to the space. (Removed twice maybe?)");
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
590 cpAssertSpaceUnlocked(space);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
591
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
592 cpBodyActivate(_body);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
593 cpArrayDeleteObj(space.bodies, _body);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
594 _body.space = null;
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
595 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
596
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
597 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
598 cpSpaceRemoveConstraint(cpSpace *space, cpConstraint *constraint)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
599 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
600 cpAssertWarn(cpArrayContains(space.constraints, constraint),
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
601 "Cannot remove a constraint that was never added to the space. (Removed twice maybe?)");
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
602 // cpAssertSpaceUnlocked(space); Should be safe as long as its not from a constraint callback.
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
603
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
604 cpBodyActivate(constraint.a);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
605 cpBodyActivate(constraint.b);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
606 cpArrayDeleteObj(space.constraints, constraint);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
607 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
608
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
609 //#pragma mark Spatial Hash Management
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
610
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
611 static void updateBBCache(cpShape *shape, void *unused){cpShapeCacheBB(shape);}
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
612
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
613 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
614 cpSpaceResizeStaticHash(cpSpace *space, cpFloat dim, int count)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
615 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
616 cpSpaceHashResize(space.staticShapes, dim, count);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
617 cpSpaceHashRehash(space.staticShapes);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
618 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
619
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
620 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
621 cpSpaceResizeActiveHash(cpSpace *space, cpFloat dim, int count)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
622 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
623 cpSpaceHashResize(space.activeShapes, dim, count);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
624 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
625
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
626 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
627 cpSpaceRehashStatic(cpSpace *space)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
628 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
629 cpSpaceHashEach(space.staticShapes, cast(cpSpaceHashIterator)&updateBBCache, null);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
630 cpSpaceHashRehash(space.staticShapes);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
631 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
632
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
633 void
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
634 cpSpaceRehashShape(cpSpace *space, cpShape *shape)
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
635 {
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
636 cpShapeCacheBB(shape);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
637
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
638 // attempt to rehash the shape in both hashes
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
639 cpSpaceHashRehashObject(space.activeShapes, shape, shape.hashid);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
640 cpSpaceHashRehashObject(space.staticShapes, shape, shape.hashid);
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
641 }
7ebbd4d05553 initial commit
Extrawurst
parents:
diff changeset
642