chipmunk 5.3.4.0-x86-mingw32 → 5.3.4.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/README +33 -13
  2. data/Rakefile +20 -7
  3. data/ext/chipmunk/extconf.rb +55 -12
  4. data/ext/chipmunk/rb_chipmunk.c +92 -98
  5. data/ext/chipmunk/rb_chipmunk.h +44 -34
  6. data/ext/chipmunk/rb_cpArbiter.c +135 -98
  7. data/ext/chipmunk/rb_cpBB.c +84 -101
  8. data/ext/chipmunk/rb_cpBody.c +219 -241
  9. data/ext/chipmunk/rb_cpConstraint.c +173 -185
  10. data/ext/chipmunk/rb_cpShape.c +347 -251
  11. data/ext/chipmunk/rb_cpSpace.c +376 -408
  12. data/ext/chipmunk/rb_cpVect.c +132 -170
  13. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk.h +163 -0
  14. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_ffi.h +59 -0
  15. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_private.h +49 -0
  16. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_types.h +151 -0
  17. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_unsafe.h +54 -0
  18. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpConstraint.h +105 -0
  19. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpDampedRotarySpring.h +46 -0
  20. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpDampedSpring.h +53 -0
  21. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpGearJoint.h +41 -0
  22. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpGrooveJoint.h +48 -0
  23. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpPinJoint.h +43 -0
  24. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpPivotJoint.h +42 -0
  25. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpRatchetJoint.h +40 -0
  26. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpRotaryLimitJoint.h +39 -0
  27. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpSimpleMotor.h +37 -0
  28. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpSlideJoint.h +44 -0
  29. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/util.h +134 -0
  30. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpArbiter.h +188 -0
  31. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpArray.h +49 -0
  32. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpBB.h +74 -0
  33. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpBody.h +219 -0
  34. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpCollision.h +28 -0
  35. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpHashSet.h +82 -0
  36. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpPolyShape.h +103 -0
  37. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpShape.h +177 -0
  38. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpSpace.h +206 -0
  39. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpSpaceHash.h +110 -0
  40. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpVect.h +207 -0
  41. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/chipmunk.c +151 -0
  42. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpConstraint.c +54 -0
  43. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpDampedRotarySpring.c +105 -0
  44. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpDampedSpring.c +115 -0
  45. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpGearJoint.c +113 -0
  46. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpGrooveJoint.c +161 -0
  47. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpPinJoint.c +116 -0
  48. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpPivotJoint.c +114 -0
  49. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpRatchetJoint.c +126 -0
  50. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpRotaryLimitJoint.c +120 -0
  51. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpSimpleMotor.c +97 -0
  52. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpSlideJoint.c +129 -0
  53. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpArbiter.c +280 -0
  54. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpArray.c +143 -0
  55. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpBB.c +47 -0
  56. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpBody.c +192 -0
  57. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpCollision.c +411 -0
  58. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpHashSet.c +253 -0
  59. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpPolyShape.c +240 -0
  60. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpShape.c +405 -0
  61. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpace.c +499 -0
  62. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceComponent.c +279 -0
  63. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceHash.c +534 -0
  64. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceQuery.c +246 -0
  65. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceStep.c +398 -0
  66. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpVect.c +71 -0
  67. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/prime.h +68 -0
  68. data/lib/1.9/chipmunk.so +0 -0
  69. data/lib/chipmunk.rb +19 -8
  70. metadata +84 -42
  71. data/lib/1.8/chipmunk.so +0 -0
@@ -0,0 +1,177 @@
1
+ /* Copyright (c) 2007 Scott Lembcke
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to deal
5
+ * in the Software without restriction, including without limitation the rights
6
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ * copies of the Software, and to permit persons to whom the Software is
8
+ * furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in
11
+ * all copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ * SOFTWARE.
20
+ */
21
+
22
+ // Forward declarations required for defining other structs.
23
+ struct cpShape;
24
+ struct cpShapeClass;
25
+
26
+ typedef struct cpSegmentQueryInfo {
27
+ struct cpShape *shape; // shape that was hit, NULL if no collision
28
+ cpFloat t; // Distance along query segment, will always be in the range [0, 1].
29
+ cpVect n; // normal of hit surface
30
+ } cpSegmentQueryInfo;
31
+
32
+ // Enumeration of shape types.
33
+ typedef enum cpShapeType{
34
+ CP_CIRCLE_SHAPE,
35
+ CP_SEGMENT_SHAPE,
36
+ CP_POLY_SHAPE,
37
+ CP_NUM_SHAPES
38
+ } cpShapeType;
39
+
40
+ // Shape class. Holds function pointers and type data.
41
+ typedef struct cpShapeClass {
42
+ cpShapeType type;
43
+
44
+ // Called by cpShapeCacheBB().
45
+ cpBB (*cacheData)(struct cpShape *shape, cpVect p, cpVect rot);
46
+ // Called to by cpShapeDestroy().
47
+ void (*destroy)(struct cpShape *shape);
48
+
49
+ // called by cpShapePointQuery().
50
+ cpBool (*pointQuery)(struct cpShape *shape, cpVect p);
51
+
52
+ // called by cpShapeSegmentQuery()
53
+ void (*segmentQuery)(struct cpShape *shape, cpVect a, cpVect b, cpSegmentQueryInfo *info);
54
+ } cpShapeClass;
55
+
56
+ // Basic shape struct that the others inherit from.
57
+ typedef struct cpShape{
58
+ // The "class" of a shape as defined above
59
+ CP_PRIVATE(const cpShapeClass *klass);
60
+
61
+ // cpBody that the shape is attached to.
62
+ cpBody *body;
63
+
64
+ // Cached BBox for the shape.
65
+ cpBB bb;
66
+
67
+ // Sensors invoke callbacks, but do not generate collisions
68
+ cpBool sensor;
69
+
70
+ // *** Surface properties.
71
+
72
+ // Coefficient of restitution. (elasticity)
73
+ cpFloat e;
74
+ // Coefficient of friction.
75
+ cpFloat u;
76
+ // Surface velocity used when solving for friction.
77
+ cpVect surface_v;
78
+
79
+ // *** User Definable Fields
80
+
81
+ // User defined data pointer for the shape.
82
+ cpDataPointer data;
83
+
84
+ // User defined collision type for the shape.
85
+ cpCollisionType collision_type;
86
+ // User defined collision group for the shape.
87
+ cpGroup group;
88
+ // User defined layer bitmask for the shape.
89
+ cpLayers layers;
90
+
91
+ // *** Internally Used Fields
92
+
93
+ // Shapes form a linked list when added to space on a non-NULL body
94
+ CP_PRIVATE(struct cpShape *next);
95
+
96
+ // Unique id used as the hash value.
97
+ CP_PRIVATE(cpHashValue hashid);
98
+ } cpShape;
99
+
100
+ // Low level shape initialization func.
101
+ cpShape* cpShapeInit(cpShape *shape, const struct cpShapeClass *klass, cpBody *body);
102
+
103
+ // Basic destructor functions. (allocation functions are not shared)
104
+ void cpShapeDestroy(cpShape *shape);
105
+ void cpShapeFree(cpShape *shape);
106
+
107
+ // Cache the BBox of the shape.
108
+ cpBB cpShapeCacheBB(cpShape *shape);
109
+
110
+ // Test if a point lies within a shape.
111
+ cpBool cpShapePointQuery(cpShape *shape, cpVect p);
112
+
113
+ #define CP_DeclareShapeGetter(struct, type, name) type struct##Get##name(cpShape *shape)
114
+
115
+ // Circle shape structure.
116
+ typedef struct cpCircleShape{
117
+ CP_PRIVATE(cpShape shape);
118
+
119
+ // Center in body space coordinates
120
+ CP_PRIVATE(cpVect c);
121
+ // Radius.
122
+ CP_PRIVATE(cpFloat r);
123
+
124
+ // Transformed center. (world space coordinates)
125
+ CP_PRIVATE(cpVect tc);
126
+ } cpCircleShape;
127
+
128
+ // Basic allocation functions for cpCircleShape.
129
+ cpCircleShape *cpCircleShapeAlloc(void);
130
+ cpCircleShape *cpCircleShapeInit(cpCircleShape *circle, cpBody *body, cpFloat radius, cpVect offset);
131
+ cpShape *cpCircleShapeNew(cpBody *body, cpFloat radius, cpVect offset);
132
+
133
+ CP_DeclareShapeGetter(cpCircleShape, cpVect, Offset);
134
+ CP_DeclareShapeGetter(cpCircleShape, cpFloat, Radius);
135
+
136
+ // Segment shape structure.
137
+ typedef struct cpSegmentShape{
138
+ CP_PRIVATE(cpShape shape);
139
+
140
+ // Endpoints and normal of the segment. (body space coordinates)
141
+ cpVect CP_PRIVATE(a), CP_PRIVATE(b), CP_PRIVATE(n);
142
+ // Radius of the segment. (Thickness)
143
+ cpFloat CP_PRIVATE(r);
144
+
145
+ // Transformed endpoints and normal. (world space coordinates)
146
+ cpVect CP_PRIVATE(ta), CP_PRIVATE(tb), CP_PRIVATE(tn);
147
+ } cpSegmentShape;
148
+
149
+ // Basic allocation functions for cpSegmentShape.
150
+ cpSegmentShape* cpSegmentShapeAlloc(void);
151
+ cpSegmentShape* cpSegmentShapeInit(cpSegmentShape *seg, cpBody *body, cpVect a, cpVect b, cpFloat radius);
152
+ cpShape* cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius);
153
+
154
+ CP_DeclareShapeGetter(cpSegmentShape, cpVect, A);
155
+ CP_DeclareShapeGetter(cpSegmentShape, cpVect, B);
156
+ CP_DeclareShapeGetter(cpSegmentShape, cpVect, Normal);
157
+ CP_DeclareShapeGetter(cpSegmentShape, cpFloat, Radius);
158
+
159
+ // For determinism, you can reset the shape id counter.
160
+ void cpResetShapeIdCounter(void);
161
+
162
+ // Directed segment queries against individual shapes.
163
+ void cpSegmentQueryInfoPrint(cpSegmentQueryInfo *info);
164
+
165
+ cpBool cpShapeSegmentQuery(cpShape *shape, cpVect a, cpVect b, cpSegmentQueryInfo *info);
166
+
167
+ static inline cpVect
168
+ cpSegmentQueryHitPoint(const cpVect start, const cpVect end, const cpSegmentQueryInfo info)
169
+ {
170
+ return cpvlerp(start, end, info.t);
171
+ }
172
+
173
+ static inline cpFloat
174
+ cpSegmentQueryHitDist(const cpVect start, const cpVect end, const cpSegmentQueryInfo info)
175
+ {
176
+ return cpvdist(start, end)*info.t;
177
+ }
@@ -0,0 +1,206 @@
1
+ /* Copyright (c) 2007 Scott Lembcke
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to deal
5
+ * in the Software without restriction, including without limitation the rights
6
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ * copies of the Software, and to permit persons to whom the Software is
8
+ * furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in
11
+ * all copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ * SOFTWARE.
20
+ */
21
+
22
+ struct cpSpace;
23
+
24
+ // Number of frames that contact information should persist.
25
+ extern cpTimestamp cp_contact_persistence;
26
+
27
+ // User collision handler function types.
28
+ typedef cpBool (*cpCollisionBeginFunc)(cpArbiter *arb, struct cpSpace *space, void *data);
29
+ typedef cpBool (*cpCollisionPreSolveFunc)(cpArbiter *arb, struct cpSpace *space, void *data);
30
+ typedef void (*cpCollisionPostSolveFunc)(cpArbiter *arb, struct cpSpace *space, void *data);
31
+ typedef void (*cpCollisionSeparateFunc)(cpArbiter *arb, struct cpSpace *space, void *data);
32
+
33
+ // Structure for holding collision pair function information.
34
+ // Used internally.
35
+ typedef struct cpCollisionHandler {
36
+ cpCollisionType a;
37
+ cpCollisionType b;
38
+ cpCollisionBeginFunc begin;
39
+ cpCollisionPreSolveFunc preSolve;
40
+ cpCollisionPostSolveFunc postSolve;
41
+ cpCollisionSeparateFunc separate;
42
+ void *data;
43
+ } cpCollisionHandler;
44
+
45
+ typedef struct cpContactBufferHeader {
46
+ cpTimestamp stamp;
47
+ struct cpContactBufferHeader *next;
48
+ unsigned int numContacts;
49
+ } cpContactBufferHeader;
50
+
51
+ typedef struct cpSpace{
52
+ // *** User definable fields
53
+
54
+ // Number of iterations to use in the impulse solver to solve contacts.
55
+ int iterations;
56
+
57
+ // Number of iterations to use in the impulse solver to solve elastic collisions.
58
+ int elasticIterations;
59
+
60
+ // Default gravity to supply when integrating rigid body motions.
61
+ cpVect gravity;
62
+
63
+ // Default damping to supply when integrating rigid body motions.
64
+ cpFloat damping;
65
+
66
+ // Speed threshold for a body to be considered idle.
67
+ // The default value of 0 means to let the space guess a good threshold based on gravity.
68
+ cpFloat idleSpeedThreshold;
69
+
70
+ // Time a group of bodies must remain idle in order to fall asleep
71
+ // The default value of INFINITY disables the sleeping algorithm.
72
+ cpFloat sleepTimeThreshold;
73
+
74
+ // *** Internally Used Fields
75
+
76
+ // When the space lock count is non zero you cannot add or remove objects
77
+ CP_PRIVATE(int locked);
78
+
79
+ // Time stamp. Is incremented on every call to cpSpaceStep().
80
+ CP_PRIVATE(cpTimestamp stamp);
81
+
82
+ // The static and active shape spatial hashes.
83
+ CP_PRIVATE(cpSpaceHash *staticShapes);
84
+ CP_PRIVATE(cpSpaceHash *activeShapes);
85
+
86
+ // List of bodies in the system.
87
+ CP_PRIVATE(cpArray *bodies);
88
+
89
+ // List of groups of sleeping bodies.
90
+ CP_PRIVATE(cpArray *sleepingComponents);
91
+
92
+ // List of bodies that have been flagged to be awoken.
93
+ CP_PRIVATE(cpArray *rousedBodies);
94
+
95
+ // List of active arbiters for the impulse solver.
96
+ CP_PRIVATE(cpArray *arbiters);
97
+ CP_PRIVATE(cpArray *pooledArbiters);
98
+
99
+ // Linked list ring of contact buffers.
100
+ // Head is the newest buffer, and each buffer points to a newer buffer.
101
+ // Head wraps around and points to the oldest (tail) buffer.
102
+ CP_PRIVATE(cpContactBufferHeader *contactBuffersHead);
103
+ CP_PRIVATE(cpContactBufferHeader *_contactBuffersTail_Deprecated);
104
+
105
+ // List of buffers to be free()ed when destroying the space.
106
+ CP_PRIVATE(cpArray *allocatedBuffers);
107
+
108
+ // Persistant contact set.
109
+ CP_PRIVATE(cpHashSet *contactSet);
110
+
111
+ // List of constraints in the system.
112
+ CP_PRIVATE(cpArray *constraints);
113
+
114
+ // Set of collisionpair functions.
115
+ CP_PRIVATE(cpHashSet *collFuncSet);
116
+ // Default collision handler.
117
+ CP_PRIVATE(cpCollisionHandler defaultHandler);
118
+
119
+ CP_PRIVATE(cpHashSet *postStepCallbacks);
120
+
121
+ cpBody staticBody;
122
+ } cpSpace;
123
+
124
+ // Basic allocation/destruction functions.
125
+ cpSpace* cpSpaceAlloc(void);
126
+ cpSpace* cpSpaceInit(cpSpace *space);
127
+ cpSpace* cpSpaceNew(void);
128
+
129
+ void cpSpaceDestroy(cpSpace *space);
130
+ void cpSpaceFree(cpSpace *space);
131
+
132
+ // Convenience function. Frees all referenced entities. (bodies, shapes and constraints)
133
+ void cpSpaceFreeChildren(cpSpace *space);
134
+
135
+ // Collision handler management functions.
136
+ void cpSpaceSetDefaultCollisionHandler(
137
+ cpSpace *space,
138
+ cpCollisionBeginFunc begin,
139
+ cpCollisionPreSolveFunc preSolve,
140
+ cpCollisionPostSolveFunc postSolve,
141
+ cpCollisionSeparateFunc separate,
142
+ void *data
143
+ );
144
+ void cpSpaceAddCollisionHandler(
145
+ cpSpace *space,
146
+ cpCollisionType a, cpCollisionType b,
147
+ cpCollisionBeginFunc begin,
148
+ cpCollisionPreSolveFunc preSolve,
149
+ cpCollisionPostSolveFunc postSolve,
150
+ cpCollisionSeparateFunc separate,
151
+ void *data
152
+ );
153
+ void cpSpaceRemoveCollisionHandler(cpSpace *space, cpCollisionType a, cpCollisionType b);
154
+
155
+ // Add and remove entities from the system.
156
+ cpShape *cpSpaceAddShape(cpSpace *space, cpShape *shape);
157
+ cpShape *cpSpaceAddStaticShape(cpSpace *space, cpShape *shape);
158
+ cpBody *cpSpaceAddBody(cpSpace *space, cpBody *body);
159
+ cpConstraint *cpSpaceAddConstraint(cpSpace *space, cpConstraint *constraint);
160
+
161
+ void cpSpaceRemoveShape(cpSpace *space, cpShape *shape);
162
+ void cpSpaceRemoveStaticShape(cpSpace *space, cpShape *shape);
163
+ void cpSpaceRemoveBody(cpSpace *space, cpBody *body);
164
+ void cpSpaceRemoveConstraint(cpSpace *space, cpConstraint *constraint);
165
+
166
+ // Post Step function definition
167
+ typedef void (*cpPostStepFunc)(cpSpace *space, void *obj, void *data);
168
+ // Register a post step function to be called after cpSpaceStep() has finished.
169
+ // obj is used a key, you can only register one callback per unique value for obj
170
+ void cpSpaceAddPostStepCallback(cpSpace *space, cpPostStepFunc func, void *obj, void *data);
171
+
172
+ // Point query callback function
173
+ typedef void (*cpSpacePointQueryFunc)(cpShape *shape, void *data);
174
+ void cpSpacePointQuery(cpSpace *space, cpVect point, cpLayers layers, cpGroup group, cpSpacePointQueryFunc func, void *data);
175
+ cpShape *cpSpacePointQueryFirst(cpSpace *space, cpVect point, cpLayers layers, cpGroup group);
176
+
177
+ // Segment query callback function
178
+ typedef void (*cpSpaceSegmentQueryFunc)(cpShape *shape, cpFloat t, cpVect n, void *data);
179
+ void cpSpaceSegmentQuery(cpSpace *space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSpaceSegmentQueryFunc func, void *data);
180
+ cpShape *cpSpaceSegmentQueryFirst(cpSpace *space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo *out);
181
+
182
+ // BB query callback function
183
+ typedef void (*cpSpaceBBQueryFunc)(cpShape *shape, void *data);
184
+ void cpSpaceBBQuery(cpSpace *space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void *data);
185
+
186
+ // Shape query callback function
187
+ typedef void (*cpSpaceShapeQueryFunc)(cpShape *shape, cpContactPointSet *points, void *data);
188
+ cpBool cpSpaceShapeQuery(cpSpace *space, cpShape *shape, cpSpaceShapeQueryFunc func, void *data);
189
+
190
+
191
+ void cpSpaceActivateShapesTouchingShape(cpSpace *space, cpShape *shape);
192
+
193
+
194
+ // Iterator function for iterating the bodies in a space.
195
+ typedef void (*cpSpaceBodyIterator)(cpBody *body, void *data);
196
+ void cpSpaceEachBody(cpSpace *space, cpSpaceBodyIterator func, void *data);
197
+
198
+ // Spatial hash management functions.
199
+ void cpSpaceResizeStaticHash(cpSpace *space, cpFloat dim, int count);
200
+ void cpSpaceResizeActiveHash(cpSpace *space, cpFloat dim, int count);
201
+ void cpSpaceRehashStatic(cpSpace *space);
202
+
203
+ void cpSpaceRehashShape(cpSpace *space, cpShape *shape);
204
+
205
+ // Update the space.
206
+ void cpSpaceStep(cpSpace *space, cpFloat dt);
@@ -0,0 +1,110 @@
1
+ /* Copyright (c) 2007 Scott Lembcke
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to deal
5
+ * in the Software without restriction, including without limitation the rights
6
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ * copies of the Software, and to permit persons to whom the Software is
8
+ * furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in
11
+ * all copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ * SOFTWARE.
20
+ */
21
+
22
+ // The spatial hash is Chipmunk's default (and currently only) spatial index type.
23
+ // Based on a chained hash table.
24
+
25
+ // Used internally to track objects added to the hash
26
+ typedef struct cpHandle{
27
+ // Pointer to the object
28
+ void *obj;
29
+ // Retain count
30
+ int retain;
31
+ // Query stamp. Used to make sure two objects
32
+ // aren't identified twice in the same query.
33
+ cpTimestamp stamp;
34
+ } cpHandle;
35
+
36
+ // Linked list element for in the chains.
37
+ typedef struct cpSpaceHashBin{
38
+ cpHandle *handle;
39
+ struct cpSpaceHashBin *next;
40
+ } cpSpaceHashBin;
41
+
42
+ // BBox callback. Called whenever the hash needs a bounding box from an object.
43
+ typedef cpBB (*cpSpaceHashBBFunc)(void *obj);
44
+
45
+ typedef struct cpSpaceHash{
46
+ // Number of cells in the table.
47
+ CP_PRIVATE(int numcells);
48
+ // Dimentions of the cells.
49
+ CP_PRIVATE(cpFloat celldim);
50
+
51
+ // BBox callback.
52
+ CP_PRIVATE(cpSpaceHashBBFunc bbfunc);
53
+
54
+ // Hashset of the handles and the recycled ones.
55
+ CP_PRIVATE(cpHashSet *handleSet);
56
+ CP_PRIVATE(cpArray *pooledHandles);
57
+
58
+ // The table and the recycled bins.
59
+ CP_PRIVATE(cpSpaceHashBin **table);
60
+ CP_PRIVATE(cpSpaceHashBin *pooledBins);
61
+
62
+ // list of buffers to free on destruction.
63
+ CP_PRIVATE(cpArray *allocatedBuffers);
64
+
65
+ // Incremented on each query. See cpHandle.stamp.
66
+ CP_PRIVATE(cpTimestamp stamp);
67
+ } cpSpaceHash;
68
+
69
+ //Basic allocation/destruction functions.
70
+ cpSpaceHash *cpSpaceHashAlloc(void);
71
+ cpSpaceHash *cpSpaceHashInit(cpSpaceHash *hash, cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc);
72
+ cpSpaceHash *cpSpaceHashNew(cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc);
73
+
74
+ void cpSpaceHashDestroy(cpSpaceHash *hash);
75
+ void cpSpaceHashFree(cpSpaceHash *hash);
76
+
77
+ // Resize the hashtable. (Does not rehash! You must call cpSpaceHashRehash() if needed.)
78
+ void cpSpaceHashResize(cpSpaceHash *hash, cpFloat celldim, int numcells);
79
+
80
+ // Add an object to the hash.
81
+ void cpSpaceHashInsert(cpSpaceHash *hash, void *obj, cpHashValue id, cpBB _deprecated_ignored);
82
+ // Remove an object from the hash.
83
+ void cpSpaceHashRemove(cpSpaceHash *hash, void *obj, cpHashValue id);
84
+
85
+ // Iterator function
86
+ typedef void (*cpSpaceHashIterator)(void *obj, void *data);
87
+ // Iterate over the objects in the hash.
88
+ void cpSpaceHashEach(cpSpaceHash *hash, cpSpaceHashIterator func, void *data);
89
+
90
+ // Rehash the contents of the hash.
91
+ void cpSpaceHashRehash(cpSpaceHash *hash);
92
+ // Rehash only a specific object.
93
+ void cpSpaceHashRehashObject(cpSpaceHash *hash, void *obj, cpHashValue id);
94
+
95
+ // Query callback.
96
+ typedef void (*cpSpaceHashQueryFunc)(void *obj1, void *obj2, void *data);
97
+ // Point query the hash. A reference to the query point is passed as obj1 to the query callback.
98
+ void cpSpaceHashPointQuery(cpSpaceHash *hash, cpVect point, cpSpaceHashQueryFunc func, void *data);
99
+ // Query the hash for a given BBox.
100
+ void cpSpaceHashQuery(cpSpaceHash *hash, void *obj, cpBB bb, cpSpaceHashQueryFunc func, void *data);
101
+ // Run a query for the object, then insert it. (Optimized case)
102
+ void cpSpaceHashQueryInsert(cpSpaceHash *hash, void *obj, cpBB bb, cpSpaceHashQueryFunc func, void *data);
103
+ // Rehashes while querying for each object. (Optimized case)
104
+ void cpSpaceHashQueryRehash(cpSpaceHash *hash, cpSpaceHashQueryFunc func, void *data);
105
+
106
+ // Segment Query callback.
107
+ // Return value is uesd for early exits of the query.
108
+ // If while traversing the grid, the raytrace function detects that an entire grid cell is beyond the hit point, it will stop the trace.
109
+ typedef cpFloat (*cpSpaceHashSegmentQueryFunc)(void *obj1, void *obj2, void *data);
110
+ void cpSpaceHashSegmentQuery(cpSpaceHash *hash, void *obj, cpVect a, cpVect b, cpFloat t_exit, cpSpaceHashSegmentQueryFunc func, void *data);