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
@@ -20,46 +20,31 @@
20
20
  */
21
21
 
22
22
  #include <stdio.h>
23
- #include <math.h>
24
23
 
25
- #include "chipmunk.h"
26
-
27
- cpFloat
28
- cpvlength(const cpVect v)
29
- {
30
- return cpfsqrt( cpvdot(v, v) );
31
- }
24
+ #include "chipmunk_private.h"
32
25
 
33
26
  inline cpVect
34
27
  cpvslerp(const cpVect v1, const cpVect v2, const cpFloat t)
35
28
  {
36
- cpFloat omega = cpfacos(cpvdot(v1, v2));
29
+ cpFloat dot = cpvdot(cpvnormalize(v1), cpvnormalize(v2));
30
+ cpFloat omega = cpfacos(cpfclamp(dot, -1.0f, 1.0f));
37
31
 
38
- if(omega){
32
+ if(omega < 1e-3){
33
+ // If the angle between two vectors is very small, lerp instead to avoid precision issues.
34
+ return cpvlerp(v1, v2, t);
35
+ } else {
39
36
  cpFloat denom = 1.0f/cpfsin(omega);
40
37
  return cpvadd(cpvmult(v1, cpfsin((1.0f - t)*omega)*denom), cpvmult(v2, cpfsin(t*omega)*denom));
41
- } else {
42
- return v1;
43
38
  }
44
39
  }
45
40
 
46
41
  cpVect
47
42
  cpvslerpconst(const cpVect v1, const cpVect v2, const cpFloat a)
48
43
  {
49
- cpFloat angle = cpfacos(cpvdot(v1, v2));
50
- return cpvslerp(v1, v2, cpfmin(a, angle)/angle);
51
- }
52
-
53
- cpVect
54
- cpvforangle(const cpFloat a)
55
- {
56
- return cpv(cpfcos(a), cpfsin(a));
57
- }
58
-
59
- cpFloat
60
- cpvtoangle(const cpVect v)
61
- {
62
- return cpfatan2(v.y, v.x);
44
+ cpFloat dot = cpvdot(cpvnormalize(v1), cpvnormalize(v2));
45
+ cpFloat omega = cpfacos(cpfclamp(dot, -1.0f, 1.0f));
46
+
47
+ return cpvslerp(v1, v2, cpfmin(a, omega)/omega);
63
48
  }
64
49
 
65
50
  char*
@@ -19,189 +19,194 @@
19
19
  * SOFTWARE.
20
20
  */
21
21
 
22
+ /// @defgroup cpVect cpVect
23
+ /// Chipmunk's 2D vector type along with a handy 2D vector math lib.
24
+ /// @{
25
+
22
26
  /// Constant for the zero vector.
23
27
  static const cpVect cpvzero = {0.0f,0.0f};
24
28
 
25
29
  /// Convenience constructor for cpVect structs.
26
- static inline cpVect
27
- cpv(const cpFloat x, const cpFloat y)
30
+ static inline cpVect cpv(const cpFloat x, const cpFloat y)
28
31
  {
29
32
  cpVect v = {x, y};
30
33
  return v;
31
34
  }
32
35
 
33
- // non-inlined functions
34
-
35
- /// Returns the length of v.
36
- cpFloat cpvlength(const cpVect v);
37
-
38
36
  /// Spherical linearly interpolate between v1 and v2.
39
37
  cpVect cpvslerp(const cpVect v1, const cpVect v2, const cpFloat t);
40
38
 
41
39
  /// Spherical linearly interpolate between v1 towards v2 by no more than angle a radians
42
40
  cpVect cpvslerpconst(const cpVect v1, const cpVect v2, const cpFloat a);
43
41
 
44
- /// Returns the unit length vector for the given angle (in radians).
45
- cpVect cpvforangle(const cpFloat a);
46
-
47
- /// Returns the angular direction v is pointing in (in radians).
48
- cpFloat cpvtoangle(const cpVect v);
49
-
50
- /**
51
- Returns a string representation of v. Intended mostly for debugging purposes and not production use.
52
-
53
- @attention The string points to a static local and is reset every time the function is called.
54
- If you want to print more than one vector you will have to split up your printing onto separate lines.
55
- */
56
- char *cpvstr(const cpVect v);
42
+ /// Returns a string representation of v. Intended mostly for debugging purposes and not production use.
43
+ /// @attention The string points to a static local and is reset every time the function is called.
44
+ /// If you want to print more than one vector you will have to split up your printing onto separate lines.
45
+ char* cpvstr(const cpVect v);
57
46
 
58
47
  /// Check if two vectors are equal. (Be careful when comparing floating point numbers!)
59
- static inline cpBool
60
- cpveql(const cpVect v1, const cpVect v2)
48
+ static inline cpBool cpveql(const cpVect v1, const cpVect v2)
61
49
  {
62
50
  return (v1.x == v2.x && v1.y == v2.y);
63
51
  }
64
52
 
65
53
  /// Add two vectors
66
- static inline cpVect
67
- cpvadd(const cpVect v1, const cpVect v2)
54
+ static inline cpVect cpvadd(const cpVect v1, const cpVect v2)
68
55
  {
69
56
  return cpv(v1.x + v2.x, v1.y + v2.y);
70
57
  }
71
58
 
72
- /// Negate a vector.
73
- static inline cpVect
74
- cpvneg(const cpVect v)
59
+ /// Subtract two vectors.
60
+ static inline cpVect cpvsub(const cpVect v1, const cpVect v2)
75
61
  {
76
- return cpv(-v.x, -v.y);
62
+ return cpv(v1.x - v2.x, v1.y - v2.y);
77
63
  }
78
64
 
79
- /// Subtract two vectors.
80
- static inline cpVect
81
- cpvsub(const cpVect v1, const cpVect v2)
65
+ /// Negate a vector.
66
+ static inline cpVect cpvneg(const cpVect v)
82
67
  {
83
- return cpv(v1.x - v2.x, v1.y - v2.y);
68
+ return cpv(-v.x, -v.y);
84
69
  }
85
70
 
86
71
  /// Scalar multiplication.
87
- static inline cpVect
88
- cpvmult(const cpVect v, const cpFloat s)
72
+ static inline cpVect cpvmult(const cpVect v, const cpFloat s)
89
73
  {
90
74
  return cpv(v.x*s, v.y*s);
91
75
  }
92
76
 
93
77
  /// Vector dot product.
94
- static inline cpFloat
95
- cpvdot(const cpVect v1, const cpVect v2)
78
+ static inline cpFloat cpvdot(const cpVect v1, const cpVect v2)
96
79
  {
97
80
  return v1.x*v2.x + v1.y*v2.y;
98
81
  }
99
82
 
100
- /**
101
- 2D vector cross product analog.
102
- The cross product of 2D vectors results in a 3D vector with only a z component.
103
- This function returns the magnitude of the z value.
104
- */
105
- static inline cpFloat
106
- cpvcross(const cpVect v1, const cpVect v2)
83
+ /// 2D vector cross product analog.
84
+ /// The cross product of 2D vectors results in a 3D vector with only a z component.
85
+ /// This function returns the magnitude of the z value.
86
+ static inline cpFloat cpvcross(const cpVect v1, const cpVect v2)
107
87
  {
108
88
  return v1.x*v2.y - v1.y*v2.x;
109
89
  }
110
90
 
111
91
  /// Returns a perpendicular vector. (90 degree rotation)
112
- static inline cpVect
113
- cpvperp(const cpVect v)
92
+ static inline cpVect cpvperp(const cpVect v)
114
93
  {
115
94
  return cpv(-v.y, v.x);
116
95
  }
117
96
 
118
97
  /// Returns a perpendicular vector. (-90 degree rotation)
119
- static inline cpVect
120
- cpvrperp(const cpVect v)
98
+ static inline cpVect cpvrperp(const cpVect v)
121
99
  {
122
100
  return cpv(v.y, -v.x);
123
101
  }
124
102
 
125
103
  /// Returns the vector projection of v1 onto v2.
126
- static inline cpVect
127
- cpvproject(const cpVect v1, const cpVect v2)
104
+ static inline cpVect cpvproject(const cpVect v1, const cpVect v2)
128
105
  {
129
106
  return cpvmult(v2, cpvdot(v1, v2)/cpvdot(v2, v2));
130
107
  }
131
108
 
109
+ /// Returns the unit length vector for the given angle (in radians).
110
+ static inline cpVect cpvforangle(const cpFloat a)
111
+ {
112
+ return cpv(cpfcos(a), cpfsin(a));
113
+ }
114
+
115
+ /// Returns the angular direction v is pointing in (in radians).
116
+ static inline cpFloat cpvtoangle(const cpVect v)
117
+ {
118
+ return cpfatan2(v.y, v.x);
119
+ }
120
+
132
121
  /// Uses complex number multiplication to rotate v1 by v2. Scaling will occur if v1 is not a unit vector.
133
- static inline cpVect
134
- cpvrotate(const cpVect v1, const cpVect v2)
122
+ static inline cpVect cpvrotate(const cpVect v1, const cpVect v2)
135
123
  {
136
124
  return cpv(v1.x*v2.x - v1.y*v2.y, v1.x*v2.y + v1.y*v2.x);
137
125
  }
138
126
 
139
127
  /// Inverse of cpvrotate().
140
- static inline cpVect
141
- cpvunrotate(const cpVect v1, const cpVect v2)
128
+ static inline cpVect cpvunrotate(const cpVect v1, const cpVect v2)
142
129
  {
143
130
  return cpv(v1.x*v2.x + v1.y*v2.y, v1.y*v2.x - v1.x*v2.y);
144
131
  }
145
132
 
146
133
  /// Returns the squared length of v. Faster than cpvlength() when you only need to compare lengths.
147
- static inline cpFloat
148
- cpvlengthsq(const cpVect v)
134
+ static inline cpFloat cpvlengthsq(const cpVect v)
149
135
  {
150
136
  return cpvdot(v, v);
151
137
  }
152
138
 
139
+ /// Returns the length of v.
140
+ static inline cpFloat cpvlength(const cpVect v)
141
+ {
142
+ return cpfsqrt(cpvdot(v, v));
143
+ }
144
+
153
145
  /// Linearly interpolate between v1 and v2.
154
- static inline cpVect
155
- cpvlerp(const cpVect v1, const cpVect v2, const cpFloat t)
146
+ static inline cpVect cpvlerp(const cpVect v1, const cpVect v2, const cpFloat t)
156
147
  {
157
148
  return cpvadd(cpvmult(v1, 1.0f - t), cpvmult(v2, t));
158
149
  }
159
150
 
160
151
  /// Returns a normalized copy of v.
161
- static inline cpVect
162
- cpvnormalize(const cpVect v)
152
+ static inline cpVect cpvnormalize(const cpVect v)
163
153
  {
164
154
  return cpvmult(v, 1.0f/cpvlength(v));
165
155
  }
166
156
 
167
157
  /// Returns a normalized copy of v or cpvzero if v was already cpvzero. Protects against divide by zero errors.
168
- static inline cpVect
169
- cpvnormalize_safe(const cpVect v)
158
+ static inline cpVect cpvnormalize_safe(const cpVect v)
170
159
  {
171
160
  return (v.x == 0.0f && v.y == 0.0f ? cpvzero : cpvnormalize(v));
172
161
  }
173
162
 
174
163
  /// Clamp v to length len.
175
- static inline cpVect
176
- cpvclamp(const cpVect v, const cpFloat len)
164
+ static inline cpVect cpvclamp(const cpVect v, const cpFloat len)
177
165
  {
178
166
  return (cpvdot(v,v) > len*len) ? cpvmult(cpvnormalize(v), len) : v;
179
167
  }
180
168
 
181
169
  /// Linearly interpolate between v1 towards v2 by distance d.
182
- static inline cpVect
183
- cpvlerpconst(cpVect v1, cpVect v2, cpFloat d)
170
+ static inline cpVect cpvlerpconst(cpVect v1, cpVect v2, cpFloat d)
184
171
  {
185
172
  return cpvadd(v1, cpvclamp(cpvsub(v2, v1), d));
186
173
  }
187
174
 
188
175
  /// Returns the distance between v1 and v2.
189
- static inline cpFloat
190
- cpvdist(const cpVect v1, const cpVect v2)
176
+ static inline cpFloat cpvdist(const cpVect v1, const cpVect v2)
191
177
  {
192
178
  return cpvlength(cpvsub(v1, v2));
193
179
  }
194
180
 
195
181
  /// Returns the squared distance between v1 and v2. Faster than cpvdist() when you only need to compare distances.
196
- static inline cpFloat
197
- cpvdistsq(const cpVect v1, const cpVect v2)
182
+ static inline cpFloat cpvdistsq(const cpVect v1, const cpVect v2)
198
183
  {
199
184
  return cpvlengthsq(cpvsub(v1, v2));
200
185
  }
201
186
 
202
187
  /// Returns true if the distance between v1 and v2 is less than dist.
203
- static inline cpBool
204
- cpvnear(const cpVect v1, const cpVect v2, const cpFloat dist)
188
+ static inline cpBool cpvnear(const cpVect v1, const cpVect v2, const cpFloat dist)
205
189
  {
206
190
  return cpvdistsq(v1, v2) < dist*dist;
207
191
  }
192
+
193
+ /// @}
194
+
195
+ /// @defgroup cpMat2x2 cpMat2x2
196
+ /// 2x2 matrix type used for tensors and such.
197
+ /// @{
198
+
199
+ static inline cpMat2x2
200
+ cpMat2x2New(cpFloat a, cpFloat b, cpFloat c, cpFloat d)
201
+ {
202
+ cpMat2x2 m = {a, b, c, d};
203
+ return m;
204
+ }
205
+
206
+ static inline cpVect
207
+ cpMat2x2Transform(cpMat2x2 m, cpVect v)
208
+ {
209
+ return cpv(v.x*m.a + v.y*m.b, v.x*m.c + v.y*m.d);
210
+ }
211
+
212
+ ///@}
@@ -5,47 +5,20 @@ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
5
5
  if ARGV.member?('--help') || ARGV.member?('-?')
6
6
  puts "ruby extconf.rb:"
7
7
  puts "Options for the Ruby bindings to Chipmunk: "
8
- # puts "--disable-vendor Disables vendoring Chipmunk."
9
- # puts "--enable-vendor Enables vendoring Chipmunk."
10
8
  puts "--enable-macosx Enables compiling for OS-X."
11
9
  puts "--enable-64 Enables compiling to 64 bits targets."
12
10
  puts
13
11
  exit
14
12
  end
15
13
 
16
- p "pwd", Dir.pwd
17
-
18
14
  dir_config('chipmunk')
19
-
20
- # VENDORED_CHIPMUNK = 'chipmunk-5.3.4'
21
- # VENDORED_SRC_DIR = File.join($srcdir, 'vendor', VENDORED_CHIPMUNK, 'src')
22
- # VENDORED_SRC_DIR2 = File.join($srcdir, 'vendor', VENDORED_CHIPMUNK, 'src',
23
- # 'constraints')
24
- # VENDORED_INCLUDE_DIR = File.join($srcdir, 'vendor', VENDORED_CHIPMUNK, 'include'
25
- # 'chipmunk')
26
-
27
- MINGW = '/usr/i586-mingw32msvc'
28
- CHIPMUNK_HEADER = 'chipmunk.h'
29
- CHIPMUNK_NAME = 'chipmunk'
30
- CHIPMUNK_FUNCTION = 'cpMomentForPoly'
31
- CHIPMUNK_INCLUDE = [ '/usr/include',
32
- File.join(MINGW, 'include'),
33
- File.join(MINGW, 'include', 'chipmunk'),
34
- '/usr/local/include',
35
- '/usr/include/chipmunk',
36
- '/usr/local/include/chipmunk'
37
- ]
38
- CHIPMUNK_LIBDIR = ['/usr/lib', File.join(MINGW, 'lib'), '/usr/local/lib']
39
-
40
- # This is a bit of a trick to cleanly vendor the chipmunk C library.
41
- # sources = Dir.glob(File.join($srcdir, 'rb_*.c')).to_a
42
- # normally, we need the rb_xxx files...
43
-
44
15
  have_header('chipmunk.h')
45
16
 
46
17
  if enable_config("macosx", false)
47
- $CFLAGS += ' -arch ppc -arch i386 -arch x86_64'
48
- $LDFLAGS += ' -arch x86_64 -arch i386 -arch ppc'
18
+ # $CFLAGS += ' -arch ppc -arch i386 -arch x86_64'
19
+ # $LDFLAGS += ' -arch x86_64 -arch i386 -arch ppc'
20
+ # $CFLAGS += ' -arch x86_64 -arch i386'
21
+ # $LDFLAGS += ' -arch x86_64 -arch i386'
49
22
  end
50
23
 
51
24
  if enable_config("64", false)
@@ -61,7 +61,7 @@ next_prime(int n)
61
61
  int i = 0;
62
62
  while(n > primes[i]){
63
63
  i++;
64
- cpAssert(primes[i], "Tried to resize a hash table to a size greater than 1610612741 O_o"); // realistically this should never happen
64
+ cpAssertHard(primes[i], "Tried to resize a hash table to a size greater than 1610612741 O_o"); // realistically this should never happen
65
65
  }
66
66
 
67
67
  return primes[i];
@@ -29,38 +29,23 @@
29
29
  VALUE m_Chipmunk;
30
30
 
31
31
  ID id_parent;
32
+ VALUE cpObjectToIntHash;
32
33
 
33
- static VALUE
34
- rb_get_cp_bias_coef(VALUE self) {
35
- return rb_float_new(cp_bias_coef);
36
- }
37
-
38
- static VALUE
39
- rb_set_cp_bias_coef(VALUE self, VALUE num) {
40
- cp_bias_coef = NUM2DBL(num);
41
- return num;
42
- }
34
+ int
35
+ CP_OBJ2INT(VALUE object) {
36
+ VALUE intValue = rb_hash_aref(cpObjectToIntHash, object);
37
+ int nextInt = 0;
43
38
 
44
- static VALUE
45
- rb_get_cp_collision_slop(VALUE self) {
46
- return rb_float_new(cp_collision_slop);
47
- }
39
+ if(NIL_P(intValue)) {
40
+ if (RHASH(cpObjectToIntHash)->ntbl) {
41
+ nextInt = RHASH(cpObjectToIntHash)->ntbl->num_entries;
42
+ }
43
+ rb_hash_aset(cpObjectToIntHash, object, INT2NUM(nextInt));
44
+ } else {
45
+ nextInt = NUM2INT(intValue);
46
+ }
48
47
 
49
- static VALUE
50
- rb_set_cp_collision_slop(VALUE self, VALUE num) {
51
- cp_collision_slop = NUM2DBL(num);
52
- return num;
53
- }
54
-
55
- static VALUE
56
- rb_set_cp_contact_persistence(VALUE self, VALUE num) {
57
- cp_contact_persistence = NUM2UINT(num);
58
- return num;
59
- }
60
-
61
- static VALUE
62
- rb_get_cp_contact_persistence(VALUE self) {
63
- return UINT2NUM(cp_contact_persistence);
48
+ return nextInt;
64
49
  }
65
50
 
66
51
 
@@ -79,7 +64,8 @@ rb_cpMomentForSegment(VALUE self, VALUE m, VALUE v1, VALUE v2) {
79
64
  static VALUE
80
65
  rb_cpMomentForPoly(VALUE self, VALUE m, VALUE arr, VALUE offset) {
81
66
  Check_Type(arr, T_ARRAY);
82
- long numVerts = RARRAY_LEN(arr);
67
+ // TODO do not cast... use stdint.h in chipmunk
68
+ int numVerts = (int)RARRAY_LEN(arr);
83
69
  VALUE *ary_ptr = RARRAY_PTR(arr);
84
70
  cpVect verts[numVerts];
85
71
 
@@ -111,13 +97,14 @@ rb_cpAreaForSegment(VALUE self, VALUE v1, VALUE v2, VALUE r) {
111
97
  static VALUE
112
98
  rb_cpAreaForPoly(VALUE self, VALUE arr) {
113
99
  Check_Type(arr, T_ARRAY);
114
- long numVerts = RARRAY_LEN(arr);
100
+ // TODO do not cast... use stdint.h in chipmunk
101
+ int numVerts = (int)RARRAY_LEN(arr);
115
102
  VALUE *ary_ptr = RARRAY_PTR(arr);
116
103
  cpVect verts[numVerts];
117
104
 
118
- for(long i = 0; i < numVerts; i++)
105
+ for(int i = 0; i < numVerts; i++) {
119
106
  verts[i] = *VGET(ary_ptr[i]);
120
-
107
+ }
121
108
  cpFloat area = cpAreaForPoly(numVerts, verts);
122
109
  return rb_float_new(area);
123
110
  }
@@ -150,7 +137,8 @@ rb_cpflerpconst(VALUE self, VALUE f1, VALUE f2, VALUE d) {
150
137
  static VALUE
151
138
  rb_cpCentroidForPoly(VALUE self, VALUE arr) {
152
139
  Check_Type(arr, T_ARRAY);
153
- long numVerts = RARRAY_LEN(arr);
140
+ // TODO do not cast... use stdint.h in chipmunk
141
+ int numVerts = (int)RARRAY_LEN(arr);
154
142
  VALUE *ary_ptr = RARRAY_PTR(arr);
155
143
  cpVect verts[numVerts];
156
144
 
@@ -163,7 +151,8 @@ rb_cpCentroidForPoly(VALUE self, VALUE arr) {
163
151
  static VALUE
164
152
  rb_cpRecenterPoly(VALUE self, VALUE arr) {
165
153
  Check_Type(arr, T_ARRAY);
166
- long numVerts = RARRAY_LEN(arr);
154
+ // TODO do not cast... use stdint.h in chipmunk
155
+ int numVerts = (int)RARRAY_LEN(arr);
167
156
  VALUE *ary_ptr = RARRAY_PTR(arr);
168
157
  cpVect verts[numVerts];
169
158
 
@@ -177,6 +166,15 @@ rb_cpRecenterPoly(VALUE self, VALUE arr) {
177
166
  return arr;
178
167
  }
179
168
 
169
+ // We need this as rb_obj_method_arity is not in 1.8.7
170
+ int
171
+ cp_rb_obj_method_arity(VALUE self, ID id) {
172
+ VALUE metho = rb_funcall(self, rb_intern("method"), 1, ID2SYM(id));
173
+ VALUE arity = rb_funcall(metho, rb_intern("arity"), 0, 0);
174
+ return NUM2INT(arity);
175
+ }
176
+
177
+
180
178
 
181
179
 
182
180
 
@@ -185,18 +183,11 @@ Init_chipmunk(void) {
185
183
  id_parent = rb_intern("parent");
186
184
 
187
185
  cpInitChipmunk();
188
-
189
-
190
-
191
186
  m_Chipmunk = rb_define_module("CP");
192
- rb_define_module_function(m_Chipmunk, "bias_coef", rb_get_cp_bias_coef, 0);
193
- rb_define_module_function(m_Chipmunk, "bias_coef=", rb_set_cp_bias_coef, 1);
194
- rb_define_module_function(m_Chipmunk, "collision_slop", rb_get_cp_collision_slop, 0);
195
- rb_define_module_function(m_Chipmunk, "collision_slop=", rb_set_cp_collision_slop, 1);
196
- rb_define_module_function(m_Chipmunk, "contact_persistence", rb_get_cp_contact_persistence, 0);
197
- rb_define_module_function(m_Chipmunk, "contact_persistence=", rb_set_cp_contact_persistence, 1);
198
-
199
187
 
188
+ cpObjectToIntHash = rb_hash_new();
189
+ /* rb_gv_set("$__cpObj", cpObjectToIntHash); */
190
+ rb_gc_register_mark_object(cpObjectToIntHash);
200
191
 
201
192
  rb_define_module_function(m_Chipmunk, "clamp", rb_cpfclamp, 3);
202
193
  rb_define_module_function(m_Chipmunk, "flerp", rb_cpflerp, 3);