chipmunk 5.3.4.5 → 6.1.3.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,28 +0,0 @@
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
- //TODO delete this header?
23
-
24
- // Collides two cpShape structures.
25
- // Returns the number of contact points added to arr
26
- // which should be at least CP_MAX_CONTACTS_PER_ARBITER in length.
27
- // This function is very lonely in this header :(
28
- int cpCollideShapes(const cpShape *a, const cpShape *b, cpContact *arr);
@@ -1,82 +0,0 @@
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
- // cpHashSet uses a chained hashtable implementation.
23
- // Other than the transformation functions, there is nothing fancy going on.
24
-
25
- // cpHashSetBin's form the linked lists in the chained hash table.
26
- typedef struct cpHashSetBin {
27
- // Pointer to the element.
28
- CP_PRIVATE(void *elt);
29
- // Hash value of the element.
30
- CP_PRIVATE(cpHashValue hash);
31
- // Next element in the chain.
32
- CP_PRIVATE(struct cpHashSetBin *next);
33
- } cpHashSetBin;
34
-
35
- // Equality function. Returns true if ptr is equal to elt.
36
- typedef cpBool (*cpHashSetEqlFunc)(void *ptr, void *elt);
37
- // Used by cpHashSetInsert(). Called to transform the ptr into an element.
38
- typedef void *(*cpHashSetTransFunc)(void *ptr, void *data);
39
-
40
- typedef struct cpHashSet {
41
- // Number of elements stored in the table.
42
- CP_PRIVATE(int entries);
43
- // Number of cells in the table.
44
- CP_PRIVATE(int size);
45
-
46
- CP_PRIVATE(cpHashSetEqlFunc eql);
47
- CP_PRIVATE(cpHashSetTransFunc trans);
48
-
49
- // Default value returned by cpHashSetFind() when no element is found.
50
- // Defaults to NULL.
51
- CP_PRIVATE(void *default_value);
52
-
53
- // The table and recycled bins
54
- CP_PRIVATE(cpHashSetBin **table);
55
- CP_PRIVATE(cpHashSetBin *pooledBins);
56
-
57
- CP_PRIVATE(cpArray *allocatedBuffers);
58
- } cpHashSet;
59
-
60
- // Basic allocation/destruction functions.
61
- void cpHashSetDestroy(cpHashSet *set);
62
- void cpHashSetFree(cpHashSet *set);
63
-
64
- cpHashSet *cpHashSetAlloc(void);
65
- cpHashSet *cpHashSetInit(cpHashSet *set, int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans);
66
- cpHashSet *cpHashSetNew(int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans);
67
-
68
- // Insert an element into the set, returns the element.
69
- // If it doesn't already exist, the transformation function is applied.
70
- void *cpHashSetInsert(cpHashSet *set, cpHashValue hash, void *ptr, void *data);
71
- // Remove and return an element from the set.
72
- void *cpHashSetRemove(cpHashSet *set, cpHashValue hash, void *ptr);
73
- // Find an element in the set. Returns the default value if the element isn't found.
74
- void *cpHashSetFind(cpHashSet *set, cpHashValue hash, void *ptr);
75
-
76
- // Iterate over a hashset.
77
- typedef void (*cpHashSetIterFunc)(void *elt, void *data);
78
- void cpHashSetEach(cpHashSet *set, cpHashSetIterFunc func, void *data);
79
-
80
- // Iterate over a hashset, drop the element if the func returns false.
81
- typedef cpBool (*cpHashSetFilterFunc)(void *elt, void *data);
82
- void cpHashSetFilter(cpHashSet *set, cpHashSetFilterFunc func, void *data);
@@ -1,110 +0,0 @@
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);
@@ -1,194 +0,0 @@
1
- # this redirection script by John Mair (banisterfiend)
2
-
3
- require 'rbconfig'
4
-
5
- direc = File.dirname(__FILE__)
6
- dlext = Config::CONFIG['DLEXT']
7
- begin
8
- if RUBY_VERSION && RUBY_VERSION =~ /1.9/
9
- require "#{direc}/1.9/chipmunk.#{dlext}"
10
- else
11
- require "#{direc}/1.8/chipmunk.#{dlext}"
12
- end
13
- rescue LoadError => e
14
- require "#{direc}/chipmunk.#{dlext}"
15
- end
16
-
17
-
18
- # Add some constants to CP here, so we don't need
19
- # to do it in the C code.
20
- # Let's cheat a bit here.. :p
21
-
22
- module CP
23
- VERSION = '5.4.3'
24
- ZERO_VEC_2 = Vec2.new(0,0).freeze
25
- ALL_ONES = Vec2.new(1,1).freeze
26
- end
27
-
28
- # Extra functionality added by Slembkce and Beoran.
29
-
30
- module CP
31
- # Chipmunk Object
32
- # Makes it easier to manage complex objects that reference many primitive
33
- # Chipmunk objects such as bodies shapes and constraints.
34
- # New composite objects simply need to include CP::Object and call
35
- # init_chipmunk_object(*objects) with the composite and primitive Chipmunk
36
- # objects that make up itself.
37
- module Object
38
- # Returns the list of primitive Chipmunk objects (bodies, shapes and
39
- # constraints that this composite object references directly and indirectly.
40
- def chipmunk_objects
41
- if @chipmunk_objects
42
- return @chipmunk_objects
43
- else
44
- raise "This CP::Object (#{self.class}) did not call #init_chipmunk_object."
45
- end
46
- end
47
-
48
- private
49
- # Should be called during initialization of a CP::Object to set what primitive
50
- # and composite Chipmunk objects this object references.
51
- def init_chipmunk_object(*objs)
52
- bad_objs = objs.reject{|obj| obj.is_a?(CP::Object)}
53
- unless bad_objs.empty?
54
- raise(ArgumentError, "The following objects: #{bad_objs.inspect} are not CP::Objects")
55
- end
56
- @chipmunk_objects = objs.inject([]){|sum, obj| sum + obj.chipmunk_objects}.uniq
57
- end
58
- end
59
-
60
- class Body
61
- include CP::Object
62
-
63
- def chipmunk_objects
64
- [self]
65
- end
66
-
67
- def add_to_space(space)
68
- space.add_body(self)
69
- end
70
-
71
- def remove_from_space(space)
72
- space.remove_body(self)
73
- end
74
-
75
- end
76
-
77
- module Shape
78
- include CP::Object
79
-
80
- def chipmunk_objects
81
- [self]
82
- end
83
-
84
- def add_to_space(space)
85
- space.add_shape(self)
86
- end
87
-
88
- def remove_from_space(space)
89
- space.remove_shape(self)
90
- end
91
- end
92
-
93
- module Constraint
94
- include CP::Object
95
-
96
- def chipmunk_objects
97
- [self]
98
- end
99
-
100
- def add_to_space(space)
101
- space.add_constraint(self)
102
- end
103
-
104
- def remove_from_space(space)
105
- space.remove_constraint(self)
106
- end
107
- end
108
-
109
- class Space
110
- def add_object(obj)
111
- obj.chipmunk_objects.each{|elt| elt.add_to_space(self)}
112
- end
113
-
114
- def add_objects(*objs)
115
- objs.each{|obj| add_object(obj)}
116
- end
117
-
118
- def remove_object(obj)
119
- obj.chipmunk_objects.each{|elt| elt.remove_from_space(self)}
120
- end
121
-
122
- def remove_objects(*objs)
123
- objs.each{|obj| remove_object(obj)}
124
- end
125
-
126
- end
127
-
128
- class Vec2
129
- ZERO = Vec2.new(0,0).freeze
130
- end
131
-
132
- # define the helpers here( easier than in the extension.
133
- class SegmentQueryInfo
134
- def hit_point(start, stop)
135
- return start.lerp(stop, self.t)
136
- end
137
-
138
- def hit_dist(start, stop)
139
- return start.dist(stop) * self.t
140
- end
141
- end
142
-
143
-
144
- end
145
-
146
-
147
- # Create derived static objects that know to add themselves as static.
148
- module CP
149
- class BodyStatic < Body
150
- def initialize
151
- super(Float::INFINITY, Float::INFINITY)
152
- end
153
-
154
- def chipmunk_objects
155
- # return [] instead of [self] so the static body will not be added.
156
- []
157
- end
158
- end
159
-
160
- class StaticBody
161
- def chipmunk_objects
162
- # return [] instead of [self] so the static body will not be added.
163
- []
164
- end
165
- end
166
-
167
- module StaticShape
168
- include Shape
169
-
170
- class Circle < Shape::Circle
171
- include StaticShape
172
- end
173
-
174
- class Segment < Shape::Segment
175
- include StaticShape
176
- end
177
-
178
- class Poly < Shape::Poly
179
- include StaticShape
180
- end
181
-
182
- def add_to_space(space)
183
- space.add_static_shape(self)
184
- end
185
-
186
- def remove_from_space(space)
187
- space.remove_static_shape(self)
188
- end
189
- end
190
- end
191
-
192
-
193
-
194
-