1 module chipmunk.chipmunk_structs;
2 
3 import chipmunk.chipmunk;
4 import chipmunk.chipmunk_types;
5 import chipmunk.cpBB;
6 import chipmunk.cpShape;
7 import chipmunk.cpBody;
8 import chipmunk.cpSpace;
9 import chipmunk.cpConstraint;
10 import chipmunk.cpDampedSpring;
11 import chipmunk.cpDampedRotarySpring;
12 import chipmunk.cpSpatialIndex;
13 
14 extern (C):
15 
16 alias cpBB function (cpShape*, cpTransform) cpShapeCacheDataImpl;
17 alias void function (cpShape*) cpShapeDestroyImpl;
18 alias void function (const(cpShape)*, cpVect, cpPointQueryInfo*) cpShapePointQueryImpl;
19 alias void function (const(cpShape)*, cpVect, cpVect, double, cpSegmentQueryInfo*) cpShapeSegmentQueryImpl;
20 alias void function (cpConstraint*, double) cpConstraintPreStepImpl;
21 alias void function (cpConstraint*, double) cpConstraintApplyCachedImpulseImpl;
22 alias void function (cpConstraint*, double) cpConstraintApplyImpulseImpl;
23 alias double function (cpConstraint*) cpConstraintGetImpulseImpl;
24 alias void function (cpArbiter*) cpSpaceArbiterApplyImpulseFunc;
25 
26 enum cpArbiterState
27 {
28     CP_ARBITER_STATE_FIRST_COLLISION = 0,
29     CP_ARBITER_STATE_NORMAL = 1,
30     CP_ARBITER_STATE_IGNORE = 2,
31     CP_ARBITER_STATE_CACHED = 3,
32     CP_ARBITER_STATE_INVALIDATED = 4
33 }
34 
35 enum cpShapeType
36 {
37     CP_CIRCLE_SHAPE = 0,
38     CP_SEGMENT_SHAPE = 1,
39     CP_POLY_SHAPE = 2,
40     CP_NUM_SHAPES = 3
41 }
42 
43 struct cpArray
44 {
45     int num;
46     int max;
47     void** arr;
48 }
49 
50 struct cpBody
51 {
52     cpBodyVelocityFunc velocity_func;
53     cpBodyPositionFunc position_func;
54     cpFloat m;
55     cpFloat m_inv;
56     cpFloat i;
57     cpFloat i_inv;
58     cpVect cog;
59     cpVect p;
60     cpVect v;
61     cpVect f;
62     cpFloat a;
63     cpFloat w;
64     cpFloat t;
65     cpTransform transform;
66     cpDataPointer userData;
67     cpVect v_bias;
68     cpFloat w_bias;
69     cpSpace* space;
70     cpShape* shapeList;
71     cpArbiter* arbiterList;
72     cpConstraint* constraintList;
73 
74     private struct Sleeping
75     {
76         cpBody* root;
77         cpBody* next;
78         cpFloat idleTime;
79     }
80 	Sleeping sleeping;
81 }
82 
83 struct cpArbiterThread
84 {
85     cpArbiter* next;
86     cpArbiter* prev;
87 }
88 
89 struct cpContact
90 {
91     cpVect r1;
92     cpVect r2;
93     cpFloat nMass;
94     cpFloat tMass;
95     cpFloat bounce;
96     cpFloat jnAcc;
97     cpFloat jtAcc;
98     cpFloat jBias;
99     cpFloat bias;
100     cpHashValue hash;
101 }
102 
103 struct cpCollisionInfo
104 {
105     const(cpShape)* a;
106     const(cpShape)* b;
107     cpCollisionID id;
108     cpVect n;
109     int count;
110     cpContact* arr;
111 }
112 
113 struct cpArbiter
114 {
115     cpFloat e;
116     cpFloat u;
117     cpVect surface_vr;
118     cpDataPointer data;
119     const(cpShape)* a;
120     const(cpShape)* b;
121     cpBody* body_a;
122     cpBody* body_b;
123     cpArbiterThread thread_a;
124     cpArbiterThread thread_b;
125     int count;
126     cpContact* contacts;
127     cpVect n;
128     cpCollisionHandler* handler;
129     cpCollisionHandler* handlerA;
130     cpCollisionHandler* handlerB;
131     cpBool swapped;
132     cpTimestamp stamp;
133     enum cpArbiterState
134     {
135         CP_ARBITER_STATE_FIRST_COLLISION = 0,
136         CP_ARBITER_STATE_NORMAL = 1,
137         CP_ARBITER_STATE_IGNORE = 2,
138         CP_ARBITER_STATE_CACHED = 3,
139         CP_ARBITER_STATE_INVALIDATED = 4
140     }
141     cpArbiterState state;
142 }
143 
144 struct cpShapeMassInfo
145 {
146     cpFloat m;
147     cpFloat i;
148     cpVect cog;
149     cpFloat area;
150 }
151 
152 struct cpShapeClass
153 {
154     cpShapeType type;
155     cpShapeCacheDataImpl cacheData;
156     cpShapeDestroyImpl destroy;
157     cpShapePointQueryImpl pointQuery;
158     cpShapeSegmentQueryImpl segmentQuery;
159 }
160 
161 struct cpShape
162 {
163     const(cpShapeClass)* klass;
164     cpSpace* space;
165     cpBody* body_;
166     cpShapeMassInfo massInfo;
167     cpBB bb;
168     cpBool sensor;
169     cpFloat e;
170     cpFloat u;
171     cpVect surfaceV;
172     cpDataPointer userData;
173     cpCollisionType type;
174     cpShapeFilter filter;
175     cpShape* next;
176     cpShape* prev;
177     cpHashValue hashid;
178 }
179 
180 struct cpCircleShape
181 {
182     cpShape shape;
183     cpVect c;
184     cpVect tc;
185     cpFloat r;
186 }
187 
188 struct cpSegmentShape
189 {
190     cpShape shape;
191     cpVect a;
192     cpVect b;
193     cpVect n;
194     cpVect ta;
195     cpVect tb;
196     cpVect tn;
197     cpFloat r;
198     cpVect a_tangent;
199     cpVect b_tangent;
200 }
201 
202 struct cpSplittingPlane
203 {
204     cpVect v0;
205     cpVect n;
206 }
207 
208 struct cpPolyShape
209 {
210     cpShape shape;
211     cpFloat r;
212     int count;
213     cpSplittingPlane* planes;
214     cpSplittingPlane[12] _planes;
215 }
216 
217 struct cpConstraintClass
218 {
219     cpConstraintPreStepImpl preStep;
220     cpConstraintApplyCachedImpulseImpl applyCachedImpulse;
221     cpConstraintApplyImpulseImpl applyImpulse;
222     cpConstraintGetImpulseImpl getImpulse;
223 }
224 
225 struct cpConstraint
226 {
227     const(cpConstraintClass)* klass;
228     cpSpace* space;
229     cpBody* a;
230     cpBody* b;
231     cpConstraint* next_a;
232     cpConstraint* next_b;
233     cpFloat maxForce;
234     cpFloat errorBias;
235     cpFloat maxBias;
236     cpBool collideBodies;
237     cpConstraintPreSolveFunc preSolve;
238     cpConstraintPostSolveFunc postSolve;
239     cpDataPointer userData;
240 }
241 
242 struct cpPinJoint
243 {
244     cpConstraint constraint;
245     cpVect anchorA;
246     cpVect anchorB;
247     cpFloat dist;
248     cpVect r1;
249     cpVect r2;
250     cpVect n;
251     cpFloat nMass;
252     cpFloat jnAcc;
253     cpFloat bias;
254 }
255 
256 struct cpSlideJoint
257 {
258     cpConstraint constraint;
259     cpVect anchorA;
260     cpVect anchorB;
261     cpFloat min;
262     cpFloat max;
263     cpVect r1;
264     cpVect r2;
265     cpVect n;
266     cpFloat nMass;
267     cpFloat jnAcc;
268     cpFloat bias;
269 }
270 
271 struct cpPivotJoint
272 {
273     cpConstraint constraint;
274     cpVect anchorA;
275     cpVect anchorB;
276     cpVect r1;
277     cpVect r2;
278     cpMat2x2 k;
279     cpVect jAcc;
280     cpVect bias;
281 }
282 
283 struct cpGrooveJoint
284 {
285     cpConstraint constraint;
286     cpVect grv_n;
287     cpVect grv_a;
288     cpVect grv_b;
289     cpVect anchorB;
290     cpVect grv_tn;
291     cpFloat clamp;
292     cpVect r1;
293     cpVect r2;
294     cpMat2x2 k;
295     cpVect jAcc;
296     cpVect bias;
297 }
298 
299 struct cpDampedSpring
300 {
301     cpConstraint constraint;
302     cpVect anchorA;
303     cpVect anchorB;
304     cpFloat restLength;
305     cpFloat stiffness;
306     cpFloat damping;
307     cpDampedSpringForceFunc springForceFunc;
308     cpFloat target_vrn;
309     cpFloat v_coef;
310     cpVect r1;
311     cpVect r2;
312     cpFloat nMass;
313     cpVect n;
314     cpFloat jAcc;
315 }
316 
317 struct cpDampedRotarySpring
318 {
319     cpConstraint constraint;
320     cpFloat restAngle;
321     cpFloat stiffness;
322     cpFloat damping;
323     cpDampedRotarySpringTorqueFunc springTorqueFunc;
324     cpFloat target_wrn;
325     cpFloat w_coef;
326     cpFloat iSum;
327     cpFloat jAcc;
328 }
329 
330 struct cpRotaryLimitJoint
331 {
332     cpConstraint constraint;
333     cpFloat min;
334     cpFloat max;
335     cpFloat iSum;
336     cpFloat bias;
337     cpFloat jAcc;
338 }
339 
340 struct cpRatchetJoint
341 {
342     cpConstraint constraint;
343     cpFloat angle;
344     cpFloat phase;
345     cpFloat ratchet;
346     cpFloat iSum;
347     cpFloat bias;
348     cpFloat jAcc;
349 }
350 
351 struct cpGearJoint
352 {
353     cpConstraint constraint;
354     cpFloat phase;
355     cpFloat ratio;
356     cpFloat ratio_inv;
357     cpFloat iSum;
358     cpFloat bias;
359     cpFloat jAcc;
360 }
361 
362 struct cpSimpleMotor
363 {
364     cpConstraint constraint;
365     cpFloat rate;
366     cpFloat iSum;
367     cpFloat jAcc;
368 }
369 
370 struct cpSpace
371 {
372     int iterations;
373     cpVect gravity;
374     cpFloat damping;
375     cpFloat idleSpeedThreshold;
376     cpFloat sleepTimeThreshold;
377     cpFloat collisionSlop;
378     cpFloat collisionBias;
379     cpTimestamp collisionPersistence;
380     cpDataPointer userData;
381     cpTimestamp stamp;
382     cpFloat curr_dt;
383     cpArray* dynamicBodies;
384     cpArray* staticBodies;
385     cpArray* rousedBodies;
386     cpArray* sleepingComponents;
387     cpHashValue shapeIDCounter;
388     cpSpatialIndex* staticShapes;
389     cpSpatialIndex* dynamicShapes;
390     cpArray* constraints;
391     cpArray* arbiters;
392     cpContactBufferHeader* contactBuffersHead;
393     cpHashSet* cachedArbiters;
394     cpArray* pooledArbiters;
395     cpArray* allocatedBuffers;
396     uint locked;
397     cpBool usesWildcards;
398     cpHashSet* collisionHandlers;
399     cpCollisionHandler defaultHandler;
400     cpBool skipPostStep;
401     cpArray* postStepCallbacks;
402     cpBody* staticBody;
403     cpBody _staticBody;
404 }
405 
406 struct cpPostStepCallback
407 {
408     cpPostStepFunc func;
409     void* key;
410     void* data;
411 }
412 
413 struct cpContactBufferHeader;