chipmunk 5.3.4.5 → 6.1.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/ext/chipmunk/chipmunk.c +199 -28
  2. data/ext/chipmunk/chipmunk.h +123 -68
  3. data/ext/chipmunk/chipmunk_ffi.h +129 -11
  4. data/ext/chipmunk/chipmunk_private.h +232 -16
  5. data/ext/chipmunk/chipmunk_types.h +94 -30
  6. data/ext/chipmunk/chipmunk_unsafe.h +12 -3
  7. data/ext/chipmunk/constraints/cpConstraint.h +90 -34
  8. data/ext/chipmunk/{cpDampedRotarySpring.h → constraints/cpDampedRotarySpring.h} +18 -8
  9. data/ext/chipmunk/{cpDampedSpring.h → constraints/cpDampedSpring.h} +27 -16
  10. data/ext/chipmunk/constraints/cpGearJoint.h +17 -7
  11. data/ext/chipmunk/constraints/cpGrooveJoint.h +19 -10
  12. data/ext/chipmunk/constraints/cpPinJoint.h +17 -8
  13. data/ext/chipmunk/constraints/cpPivotJoint.h +18 -9
  14. data/ext/chipmunk/constraints/cpRatchetJoint.h +17 -8
  15. data/ext/chipmunk/constraints/cpRotaryLimitJoint.h +16 -7
  16. data/ext/chipmunk/{cpSimpleMotor.h → constraints/cpSimpleMotor.h} +15 -6
  17. data/ext/chipmunk/constraints/cpSlideJoint.h +18 -9
  18. data/ext/chipmunk/constraints/util.h +36 -44
  19. data/ext/chipmunk/cpArbiter.c +159 -94
  20. data/ext/chipmunk/cpArbiter.h +135 -129
  21. data/ext/chipmunk/cpArray.c +37 -56
  22. data/ext/chipmunk/cpBB.c +1 -12
  23. data/ext/chipmunk/cpBB.h +80 -18
  24. data/ext/chipmunk/cpBBTree.c +891 -0
  25. data/ext/chipmunk/cpBody.c +185 -47
  26. data/ext/chipmunk/cpBody.h +156 -124
  27. data/ext/chipmunk/cpCollision.c +126 -115
  28. data/ext/chipmunk/cpConstraint.c +10 -6
  29. data/ext/chipmunk/cpDampedRotarySpring.c +26 -17
  30. data/ext/chipmunk/cpDampedSpring.c +25 -18
  31. data/ext/chipmunk/cpGearJoint.c +23 -17
  32. data/ext/chipmunk/cpGrooveJoint.c +26 -22
  33. data/ext/chipmunk/cpHashSet.c +51 -51
  34. data/ext/chipmunk/cpPinJoint.c +26 -19
  35. data/ext/chipmunk/cpPivotJoint.c +23 -19
  36. data/ext/chipmunk/cpPolyShape.c +93 -69
  37. data/ext/chipmunk/cpPolyShape.h +33 -69
  38. data/ext/chipmunk/cpRatchetJoint.c +26 -21
  39. data/ext/chipmunk/cpRotaryLimitJoint.c +28 -22
  40. data/ext/chipmunk/cpShape.c +122 -133
  41. data/ext/chipmunk/cpShape.h +146 -95
  42. data/ext/chipmunk/cpSimpleMotor.c +24 -17
  43. data/ext/chipmunk/cpSlideJoint.c +28 -26
  44. data/ext/chipmunk/cpSpace.c +251 -196
  45. data/ext/chipmunk/cpSpace.h +173 -103
  46. data/ext/chipmunk/cpSpaceComponent.c +236 -159
  47. data/ext/chipmunk/cpSpaceHash.c +259 -159
  48. data/ext/chipmunk/cpSpaceQuery.c +127 -59
  49. data/ext/chipmunk/cpSpaceStep.c +235 -197
  50. data/ext/chipmunk/cpSpatialIndex.c +69 -0
  51. data/ext/chipmunk/cpSpatialIndex.h +227 -0
  52. data/ext/chipmunk/cpSweep1D.c +254 -0
  53. data/ext/chipmunk/cpVect.c +11 -26
  54. data/ext/chipmunk/cpVect.h +76 -71
  55. data/ext/chipmunk/extconf.rb +4 -31
  56. data/ext/chipmunk/prime.h +1 -1
  57. data/ext/chipmunk/rb_chipmunk.c +36 -45
  58. data/ext/chipmunk/rb_chipmunk.h +6 -3
  59. data/ext/chipmunk/rb_cpArbiter.c +2 -2
  60. data/ext/chipmunk/rb_cpBB.c +116 -35
  61. data/ext/chipmunk/rb_cpBody.c +5 -12
  62. data/ext/chipmunk/rb_cpConstraint.c +144 -9
  63. data/ext/chipmunk/rb_cpShape.c +69 -78
  64. data/ext/chipmunk/rb_cpSpace.c +81 -76
  65. metadata +61 -61
  66. data/LICENSE +0 -22
  67. data/README +0 -110
  68. data/Rakefile +0 -102
  69. data/ext/chipmunk/cpArray.h +0 -49
  70. data/ext/chipmunk/cpCollision.h +0 -28
  71. data/ext/chipmunk/cpHashSet.h +0 -82
  72. data/ext/chipmunk/cpSpaceHash.h +0 -110
  73. data/lib/chipmunk.rb +0 -194
@@ -18,101 +18,128 @@
18
18
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
19
  * SOFTWARE.
20
20
  */
21
-
22
- struct cpArbiter;
23
- struct cpSpace;
24
- struct cpCollisionHandler;
25
-
26
- // Determines how fast penetrations resolve themselves.
27
- extern cpFloat cp_bias_coef;
28
- // Amount of allowed penetration. Used to reduce vibrating contacts.
29
- extern cpFloat cp_collision_slop;
30
-
31
- // Data structure for contact points.
32
- typedef struct cpContact {
33
- // Contact point and normal.
34
- cpVect CP_PRIVATE(p), CP_PRIVATE(n);
35
- // Penetration distance.
36
- CP_PRIVATE(cpFloat dist);
37
-
38
- // Calculated by cpArbiterPreStep().
39
- cpVect CP_PRIVATE(r1), CP_PRIVATE(r2);
40
- cpFloat CP_PRIVATE(nMass), CP_PRIVATE(tMass), CP_PRIVATE(bounce);
41
-
42
- // Persistant contact information.
43
- cpFloat CP_PRIVATE(jnAcc), CP_PRIVATE(jtAcc), CP_PRIVATE(jBias);
44
- CP_PRIVATE(cpFloat bias);
45
-
46
- // Hash value used to (mostly) uniquely identify a contact.
47
- CP_PRIVATE(cpHashValue hash);
48
- } cpContact;
49
-
50
- // Contacts are always allocated in groups.
51
- cpContact* cpContactInit(cpContact *con, cpVect p, cpVect n, cpFloat dist, cpHashValue hash);
52
-
53
- // Sum the contact impulses. (Can be used after cpSpaceStep() returns)
54
- cpVect CP_PRIVATE(cpContactsSumImpulses)(cpContact *contacts, int numContacts);
55
- cpVect CP_PRIVATE(cpContactsSumImpulsesWithFriction)(cpContact *contacts, int numContacts);
56
-
57
- #define CP_MAX_CONTACTS_PER_ARBITER 6
58
21
 
22
+ /// @defgroup cpArbiter cpArbiter
23
+ /// The cpArbiter struct controls pairs of colliding shapes.
24
+ /// They are also used in conjuction with collision handler callbacks
25
+ /// allowing you to retrieve information on the collision and control it.
26
+ /// @{
27
+
28
+ /// Collision begin event function callback type.
29
+ /// Returning false from a begin callback causes the collision to be ignored until
30
+ /// the the separate callback is called when the objects stop colliding.
31
+ typedef cpBool (*cpCollisionBeginFunc)(cpArbiter *arb, cpSpace *space, void *data);
32
+ /// Collision pre-solve event function callback type.
33
+ /// Returning false from a pre-step callback causes the collision to be ignored until the next step.
34
+ typedef cpBool (*cpCollisionPreSolveFunc)(cpArbiter *arb, cpSpace *space, void *data);
35
+ /// Collision post-solve event function callback type.
36
+ typedef void (*cpCollisionPostSolveFunc)(cpArbiter *arb, cpSpace *space, void *data);
37
+ /// Collision separate event function callback type.
38
+ typedef void (*cpCollisionSeparateFunc)(cpArbiter *arb, cpSpace *space, void *data);
39
+
40
+ /// @private
41
+ struct cpCollisionHandler {
42
+ cpCollisionType a;
43
+ cpCollisionType b;
44
+ cpCollisionBeginFunc begin;
45
+ cpCollisionPreSolveFunc preSolve;
46
+ cpCollisionPostSolveFunc postSolve;
47
+ cpCollisionSeparateFunc separate;
48
+ void *data;
49
+ };
50
+
51
+ typedef struct cpContact cpContact;
52
+
53
+ #define CP_MAX_CONTACTS_PER_ARBITER 4
54
+
55
+ /// @private
59
56
  typedef enum cpArbiterState {
60
- cpArbiterStateNormal,
57
+ // Arbiter is active and its the first collision.
61
58
  cpArbiterStateFirstColl,
59
+ // Arbiter is active and its not the first collision.
60
+ cpArbiterStateNormal,
61
+ // Collision has been explicitly ignored.
62
+ // Either by returning false from a begin collision handler or calling cpArbiterIgnore().
62
63
  cpArbiterStateIgnore,
63
- cpArbiterStateSleep,
64
+ // Collison is no longer active. A space will cache an arbiter for up to cpSpace.collisionPersistence more steps.
64
65
  cpArbiterStateCached,
65
66
  } cpArbiterState;
66
67
 
67
- // Data structure for tracking collisions between shapes.
68
- typedef struct cpArbiter {
69
- // Information on the contact points between the objects.
70
- CP_PRIVATE(int numContacts);
71
- CP_PRIVATE(cpContact *contacts);
68
+ /// @private
69
+ struct cpArbiterThread {
70
+ // Links to next and previous arbiters in the contact graph.
71
+ struct cpArbiter *next, *prev;
72
+ };
73
+
74
+ /// A colliding pair of shapes.
75
+ struct cpArbiter {
76
+ /// Calculated value to use for the elasticity coefficient.
77
+ /// Override in a pre-solve collision handler for custom behavior.
78
+ cpFloat e;
79
+ /// Calculated value to use for the friction coefficient.
80
+ /// Override in a pre-solve collision handler for custom behavior.
81
+ cpFloat u;
82
+ /// Calculated value to use for applying surface velocities.
83
+ /// Override in a pre-solve collision handler for custom behavior.
84
+ cpVect surface_vr;
72
85
 
73
- // The two shapes and bodies involved in the collision.
74
- // These variables are NOT in the order defined by the collision handler.
75
- // Using CP_ARBITER_GET_SHAPES and CP_ARBITER_GET_BODIES will save you from
76
- // many headaches
77
- cpShape CP_PRIVATE(*a), CP_PRIVATE(*b);
86
+ /// User definable data pointer.
87
+ /// The value will persist for the pair of shapes until the separate() callback is called.
88
+ /// NOTE: If you need to clean up this pointer, you should implement the separate() callback to do it.
89
+ cpDataPointer data;
78
90
 
79
- // Calculated before calling the pre-solve collision handler
80
- // Override them with custom values if you want specialized behavior
81
- CP_PRIVATE(cpFloat e);
82
- CP_PRIVATE(cpFloat u);
83
- // Used for surface_v calculations, implementation may change
84
- CP_PRIVATE(cpVect surface_vr);
91
+ CP_PRIVATE(cpShape *a);
92
+ CP_PRIVATE(cpShape *b);
93
+ CP_PRIVATE(cpBody *body_a);
94
+ CP_PRIVATE(cpBody *body_b);
85
95
 
86
- // Time stamp of the arbiter. (from cpSpace)
87
- CP_PRIVATE(cpTimestamp stamp);
96
+ CP_PRIVATE(struct cpArbiterThread thread_a);
97
+ CP_PRIVATE(struct cpArbiterThread thread_b);
88
98
 
89
- CP_PRIVATE(struct cpCollisionHandler *handler);
99
+ CP_PRIVATE(int numContacts);
100
+ CP_PRIVATE(cpContact *contacts);
90
101
 
91
- // Are the shapes swapped in relation to the collision handler?
102
+ CP_PRIVATE(cpTimestamp stamp);
103
+ CP_PRIVATE(cpCollisionHandler *handler);
92
104
  CP_PRIVATE(cpBool swappedColl);
93
105
  CP_PRIVATE(cpArbiterState state);
94
- } cpArbiter;
95
-
96
- // Arbiters are allocated in large buffers by the space and don't require a destroy function
97
- cpArbiter* CP_PRIVATE(cpArbiterInit)(cpArbiter *arb, cpShape *a, cpShape *b);
98
-
99
- // These functions are all intended to be used internally.
100
- // Inject new contact points into the arbiter while preserving contact history.
101
- void CP_PRIVATE(cpArbiterUpdate)(cpArbiter *arb, cpContact *contacts, int numContacts, struct cpCollisionHandler *handler, cpShape *a, cpShape *b);
102
- // Precalculate values used by the solver.
103
- void CP_PRIVATE(cpArbiterPreStep)(cpArbiter *arb, cpFloat dt_inv);
104
- void CP_PRIVATE(cpArbiterApplyCachedImpulse)(cpArbiter *arb);
105
- // Run an iteration of the solver on the arbiter.
106
- void CP_PRIVATE(cpArbiterApplyImpulse)(cpArbiter *arb, cpFloat eCoef);
107
-
108
- // Arbiter Helper Functions
109
- cpVect cpArbiterTotalImpulse(cpArbiter *arb);
110
- cpVect cpArbiterTotalImpulseWithFriction(cpArbiter *arb);
111
- void cpArbiterIgnore(cpArbiter *arb);
106
+ };
107
+
108
+ #define CP_DefineArbiterStructGetter(type, member, name) \
109
+ static inline type cpArbiterGet##name(const cpArbiter *arb){return arb->member;}
110
+
111
+ #define CP_DefineArbiterStructSetter(type, member, name) \
112
+ static inline void cpArbiterSet##name(cpArbiter *arb, type value){arb->member = value;}
112
113
 
114
+ #define CP_DefineArbiterStructProperty(type, member, name) \
115
+ CP_DefineArbiterStructGetter(type, member, name) \
116
+ CP_DefineArbiterStructSetter(type, member, name)
117
+
118
+ CP_DefineArbiterStructProperty(cpFloat, e, Elasticity)
119
+ CP_DefineArbiterStructProperty(cpFloat, u, Friction)
120
+ CP_DefineArbiterStructProperty(cpVect, surface_vr, SurfaceVelocity)
121
+ CP_DefineArbiterStructProperty(cpDataPointer, data, UserData)
122
+
123
+ /// Calculate the total impulse that was applied by this arbiter.
124
+ /// This function should only be called from a post-solve, post-step or cpBodyEachArbiter callback.
125
+ cpVect cpArbiterTotalImpulse(const cpArbiter *arb);
126
+ /// Calculate the total impulse including the friction that was applied by this arbiter.
127
+ /// This function should only be called from a post-solve, post-step or cpBodyEachArbiter callback.
128
+ cpVect cpArbiterTotalImpulseWithFriction(const cpArbiter *arb);
129
+ /// Calculate the amount of energy lost in a collision including static, but not dynamic friction.
130
+ /// This function should only be called from a post-solve, post-step or cpBodyEachArbiter callback.
131
+ cpFloat cpArbiterTotalKE(const cpArbiter *arb);
132
+
133
+
134
+ /// Causes a collision pair to be ignored as if you returned false from a begin callback.
135
+ /// If called from a pre-step callback, you will still need to return false
136
+ /// if you want it to be ignored in the current step.
137
+ void cpArbiterIgnore(cpArbiter *arb);
113
138
 
114
- static inline void
115
- cpArbiterGetShapes(const cpArbiter *arb, cpShape **a, cpShape **b)
139
+ /// Return the colliding shapes involved for this arbiter.
140
+ /// The order of their cpSpace.collision_type values will match
141
+ /// the order set when the collision handler was registered.
142
+ static inline void cpArbiterGetShapes(const cpArbiter *arb, cpShape **a, cpShape **b)
116
143
  {
117
144
  if(arb->CP_PRIVATE(swappedColl)){
118
145
  (*a) = arb->CP_PRIVATE(b), (*b) = arb->CP_PRIVATE(a);
@@ -120,69 +147,48 @@ cpArbiterGetShapes(const cpArbiter *arb, cpShape **a, cpShape **b)
120
147
  (*a) = arb->CP_PRIVATE(a), (*b) = arb->CP_PRIVATE(b);
121
148
  }
122
149
  }
150
+ /// A macro shortcut for defining and retrieving the shapes from an arbiter.
123
151
  #define CP_ARBITER_GET_SHAPES(arb, a, b) cpShape *a, *b; cpArbiterGetShapes(arb, &a, &b);
124
152
 
125
- static inline void
126
- cpArbiterGetBodies(const cpArbiter *arb, cpBody **a, cpBody **b)
153
+ /// Return the colliding bodies involved for this arbiter.
154
+ /// The order of the cpSpace.collision_type the bodies are associated with values will match
155
+ /// the order set when the collision handler was registered.
156
+ static inline void cpArbiterGetBodies(const cpArbiter *arb, cpBody **a, cpBody **b)
127
157
  {
128
158
  CP_ARBITER_GET_SHAPES(arb, shape_a, shape_b);
129
159
  (*a) = shape_a->body;
130
160
  (*b) = shape_b->body;
131
161
  }
162
+ /// A macro shortcut for defining and retrieving the bodies from an arbiter.
132
163
  #define CP_ARBITER_GET_BODIES(arb, a, b) cpBody *a, *b; cpArbiterGetBodies(arb, &a, &b);
133
164
 
134
- static inline cpBool
135
- cpArbiterIsFirstContact(const cpArbiter *arb)
136
- {
137
- return arb->CP_PRIVATE(state) == cpArbiterStateFirstColl;
138
- }
139
-
140
- static inline int
141
- cpArbiterGetCount(const cpArbiter *arb)
142
- {
143
- return arb->CP_PRIVATE(numContacts);
144
- }
145
-
146
- static inline cpVect
147
- cpArbiterGetNormal(const cpArbiter *arb, int i)
148
- {
149
- cpVect n = arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(n);
150
- return arb->CP_PRIVATE(swappedColl) ? cpvneg(n) : n;
151
- }
152
-
153
- static inline cpVect
154
- cpArbiterGetPoint(const cpArbiter *arb, int i)
155
- {
156
- return arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(p);
157
- }
158
-
159
- static inline cpFloat
160
- cpArbiteGetDepth(const cpArbiter *arb, int i)
161
- {
162
- return arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(dist);
163
- }
164
-
165
+ /// A struct that wraps up the important collision data for an arbiter.
165
166
  typedef struct cpContactPointSet {
167
+ /// The number of contact points in the set.
166
168
  int count;
167
169
 
170
+ /// The array of contact points.
168
171
  struct {
169
- cpVect point, normal;
172
+ /// The position of the contact point.
173
+ cpVect point;
174
+ /// The normal of the contact point.
175
+ cpVect normal;
176
+ /// The depth of the contact point.
170
177
  cpFloat dist;
171
178
  } points[CP_MAX_CONTACTS_PER_ARBITER];
172
179
  } cpContactPointSet;
173
-
174
- static inline cpContactPointSet
175
- cpArbiterGetContactPointSet(const cpArbiter *arb)
176
- {
177
- cpContactPointSet set;
178
- set.count = cpArbiterGetCount(arb);
179
-
180
- int i;
181
- for(i=0; i<set.count; i++){
182
- set.points[i].point = arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(p);
183
- set.points[i].normal = arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(n);
184
- set.points[i].dist = arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(dist);
185
- }
186
-
187
- return set;
188
- }
180
+ /// Return a contact set from an arbiter.
181
+ cpContactPointSet cpArbiterGetContactPointSet(const cpArbiter *arb);
182
+
183
+ /// Returns true if this is the first step a pair of objects started colliding.
184
+ cpBool cpArbiterIsFirstContact(const cpArbiter *arb);
185
+ /// Get the number of contact points for this arbiter.
186
+ int cpArbiterGetCount(const cpArbiter *arb);
187
+ /// Get the normal of the @c ith contact point.
188
+ cpVect cpArbiterGetNormal(const cpArbiter *arb, int i);
189
+ /// Get the position of the @c ith contact point.
190
+ cpVect cpArbiterGetPoint(const cpArbiter *arb, int i);
191
+ /// Get the depth of the @c ith contact point.
192
+ cpFloat cpArbiterGetDepth(const cpArbiter *arb, int i);
193
+
194
+ /// @}
@@ -19,52 +19,30 @@
19
19
  * SOFTWARE.
20
20
  */
21
21
 
22
- #include <stdlib.h>
23
22
  #include <string.h>
24
23
 
25
24
  #include "chipmunk_private.h"
26
25
 
27
26
 
28
- //#define CP_ARRAY_INCREMENT 10
29
-
30
- // NOTE: cpArray is rarely used and will probably go away.
31
-
32
- cpArray*
33
- cpArrayAlloc(void)
34
- {
35
- return (cpArray *)cpcalloc(1, sizeof(cpArray));
36
- }
37
-
38
- cpArray*
39
- cpArrayInit(cpArray *arr, int size)
27
+ cpArray *
28
+ cpArrayNew(int size)
40
29
  {
41
- arr->num = 0;
30
+ cpArray *arr = (cpArray *)cpcalloc(1, sizeof(cpArray));
42
31
 
43
- size = (size ? size : 4);
44
- arr->max = size;
45
- arr->arr = (void **)cpmalloc(size*sizeof(void**));
32
+ arr->num = 0;
33
+ arr->max = (size ? size : 4);
34
+ arr->arr = (void **)cpcalloc(arr->max, sizeof(void**));
46
35
 
47
36
  return arr;
48
37
  }
49
38
 
50
- cpArray*
51
- cpArrayNew(int size)
52
- {
53
- return cpArrayInit(cpArrayAlloc(), size);
54
- }
55
-
56
- void
57
- cpArrayDestroy(cpArray *arr)
58
- {
59
- cpfree(arr->arr);
60
- arr->arr = NULL;
61
- }
62
-
63
39
  void
64
40
  cpArrayFree(cpArray *arr)
65
41
  {
66
42
  if(arr){
67
- cpArrayDestroy(arr);
43
+ cpfree(arr->arr);
44
+ arr->arr = NULL;
45
+
68
46
  cpfree(arr);
69
47
  }
70
48
  }
@@ -92,45 +70,48 @@ cpArrayPop(cpArray *arr)
92
70
  return value;
93
71
  }
94
72
 
95
- void
96
- cpArrayDeleteIndex(cpArray *arr, int idx)
97
- {
98
- arr->num--;
99
-
100
- arr->arr[idx] = arr->arr[arr->num];
101
- arr->arr[arr->num] = NULL;
102
- }
73
+ //static void
74
+ //cpArrayDeleteIndex(cpArray *arr, int idx)
75
+ //{
76
+ // arr->num--;
77
+ //
78
+ // arr->arr[idx] = arr->arr[arr->num];
79
+ // arr->arr[arr->num] = NULL;
80
+ //}
103
81
 
104
82
  void
105
83
  cpArrayDeleteObj(cpArray *arr, void *obj)
106
84
  {
107
85
  for(int i=0; i<arr->num; i++){
108
86
  if(arr->arr[i] == obj){
109
- cpArrayDeleteIndex(arr, i);
87
+ arr->num--;
88
+
89
+ arr->arr[i] = arr->arr[arr->num];
90
+ arr->arr[arr->num] = NULL;
91
+
110
92
  return;
111
93
  }
112
94
  }
113
95
  }
114
96
 
115
- void
116
- cpArrayAppend(cpArray *arr, cpArray *other)
117
- {
118
- void *tail = &arr->arr[arr->num];
119
-
120
- arr->num += other->num;
121
- if(arr->num >= arr->max){
122
- arr->max = arr->num;
123
- arr->arr = (void **)cprealloc(arr->arr, arr->max*sizeof(void**));
124
- }
125
-
126
- memcpy(tail, other->arr, other->num*sizeof(void**));
127
- }
97
+ //void
98
+ //cpArrayAppend(cpArray *arr, cpArray *other)
99
+ //{
100
+ // void *tail = &arr->arr[arr->num];
101
+ //
102
+ // arr->num += other->num;
103
+ // if(arr->num >= arr->max){
104
+ // arr->max = arr->num;
105
+ // arr->arr = (void **)cprealloc(arr->arr, arr->max*sizeof(void**));
106
+ // }
107
+ //
108
+ // memcpy(tail, other->arr, other->num*sizeof(void**));
109
+ //}
128
110
 
129
111
  void
130
- cpArrayEach(cpArray *arr, cpArrayIter iterFunc, void *data)
112
+ cpArrayFreeEach(cpArray *arr, void (freeFunc)(void*))
131
113
  {
132
- for(int i=0; i<arr->num; i++)
133
- iterFunc(arr->arr[i], data);
114
+ for(int i=0; i<arr->num; i++) freeFunc(arr->arr[i]);
134
115
  }
135
116
 
136
117
  cpBool
@@ -19,18 +19,7 @@
19
19
  * SOFTWARE.
20
20
  */
21
21
 
22
- #include <math.h>
23
- #include <stdlib.h>
24
-
25
- #include "chipmunk.h"
26
-
27
- cpVect
28
- cpBBClampVect(const cpBB bb, const cpVect v)
29
- {
30
- cpFloat x = cpfmin(cpfmax(bb.l, v.x), bb.r);
31
- cpFloat y = cpfmin(cpfmax(bb.b, v.y), bb.t);
32
- return cpv(x, y);
33
- }
22
+ #include "chipmunk_private.h"
34
23
 
35
24
  cpVect
36
25
  cpBBWrapVect(const cpBB bb, const cpVect v)