chipmunk 4.1.0-x86-mswin32 → 5.3.4.0-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/{ext/chipmunk/cpCollision.h → LICENSE} +4 -5
- data/README +67 -0
- data/Rakefile +76 -29
- data/ext/chipmunk/extconf.rb +38 -0
- data/ext/chipmunk/rb_chipmunk.c +162 -21
- data/ext/chipmunk/rb_chipmunk.h +39 -11
- data/ext/chipmunk/rb_cpArbiter.c +253 -0
- data/ext/chipmunk/rb_cpBB.c +60 -4
- data/ext/chipmunk/rb_cpBody.c +282 -17
- data/ext/chipmunk/rb_cpConstraint.c +336 -0
- data/ext/chipmunk/rb_cpShape.c +145 -4
- data/ext/chipmunk/rb_cpSpace.c +438 -57
- data/ext/chipmunk/rb_cpVect.c +98 -2
- data/lib/1.8/chipmunk.so +0 -0
- data/lib/1.9/chipmunk.so +0 -0
- data/lib/chipmunk.rb +168 -0
- metadata +29 -41
- data/ext/chipmunk/chipmunk.c +0 -69
- data/ext/chipmunk/chipmunk.h +0 -91
- data/ext/chipmunk/cpArbiter.c +0 -263
- data/ext/chipmunk/cpArbiter.h +0 -85
- data/ext/chipmunk/cpArray.c +0 -114
- data/ext/chipmunk/cpArray.h +0 -45
- data/ext/chipmunk/cpBB.c +0 -46
- data/ext/chipmunk/cpBB.h +0 -53
- data/ext/chipmunk/cpBody.c +0 -180
- data/ext/chipmunk/cpBody.h +0 -132
- data/ext/chipmunk/cpCollision.c +0 -390
- data/ext/chipmunk/cpHashSet.c +0 -219
- data/ext/chipmunk/cpHashSet.h +0 -79
- data/ext/chipmunk/cpJoint.c +0 -553
- data/ext/chipmunk/cpJoint.h +0 -122
- data/ext/chipmunk/cpPolyShape.c +0 -139
- data/ext/chipmunk/cpPolyShape.h +0 -92
- data/ext/chipmunk/cpShape.c +0 -244
- data/ext/chipmunk/cpShape.h +0 -141
- data/ext/chipmunk/cpSpace.c +0 -530
- data/ext/chipmunk/cpSpace.h +0 -120
- data/ext/chipmunk/cpSpaceHash.c +0 -455
- data/ext/chipmunk/cpSpaceHash.h +0 -100
- data/ext/chipmunk/cpVect.c +0 -63
- data/ext/chipmunk/cpVect.h +0 -106
- data/ext/chipmunk/prime.h +0 -68
- data/ext/chipmunk/rb_cpJoint.c +0 -136
data/ext/chipmunk/rb_cpSpace.c
CHANGED
@@ -19,16 +19,22 @@
|
|
19
19
|
* SOFTWARE.
|
20
20
|
*/
|
21
21
|
|
22
|
+
#include <stdlib.h>
|
22
23
|
#include "chipmunk.h"
|
23
24
|
|
24
25
|
#include "ruby.h"
|
25
26
|
#include "rb_chipmunk.h"
|
26
27
|
|
27
|
-
ID id_call;
|
28
|
+
static ID id_call;
|
29
|
+
static ID id_begin;
|
30
|
+
static ID id_pre_solve;
|
31
|
+
static ID id_post_solve;
|
32
|
+
static ID id_separate;
|
28
33
|
|
29
34
|
|
30
35
|
VALUE c_cpSpace;
|
31
36
|
|
37
|
+
|
32
38
|
static VALUE
|
33
39
|
rb_cpSpaceAlloc(VALUE klass)
|
34
40
|
{
|
@@ -46,12 +52,41 @@ rb_cpSpaceInitialize(VALUE self)
|
|
46
52
|
rb_iv_set(self, "static_shapes", rb_ary_new());
|
47
53
|
rb_iv_set(self, "active_shapes", rb_ary_new());
|
48
54
|
rb_iv_set(self, "bodies", rb_ary_new());
|
49
|
-
rb_iv_set(self, "
|
55
|
+
rb_iv_set(self, "constraints", rb_ary_new());
|
50
56
|
rb_iv_set(self, "blocks", rb_hash_new());
|
51
57
|
|
52
58
|
return self;
|
53
59
|
}
|
54
60
|
|
61
|
+
static VALUE
|
62
|
+
SPACEWRAP(cpSpace * space) {
|
63
|
+
return Data_Wrap_Struct(c_cpSpace, NULL, cpSpaceFree, space);
|
64
|
+
}
|
65
|
+
|
66
|
+
static VALUE
|
67
|
+
rb_cpSpaceGetSleepTimeThreshold(VALUE self) {
|
68
|
+
return INT2NUM(SPACE(self)->sleepTimeThreshold);
|
69
|
+
}
|
70
|
+
|
71
|
+
static VALUE
|
72
|
+
rb_cpSpaceSetSleepTimeThreshold(VALUE self, VALUE val) {
|
73
|
+
SPACE(self)->sleepTimeThreshold = NUM2INT(val);
|
74
|
+
return val;
|
75
|
+
}
|
76
|
+
|
77
|
+
static VALUE
|
78
|
+
rb_cpSpaceGetIdleSpeedThreshold(VALUE self) {
|
79
|
+
return INT2NUM(SPACE(self)->idleSpeedThreshold);
|
80
|
+
}
|
81
|
+
|
82
|
+
static VALUE
|
83
|
+
rb_cpSpaceSetIdleSpeedThreshold(VALUE self, VALUE val) {
|
84
|
+
SPACE(self)->idleSpeedThreshold = NUM2INT(val);
|
85
|
+
return val;
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
|
55
90
|
static VALUE
|
56
91
|
rb_cpSpaceGetIterations(VALUE self)
|
57
92
|
{
|
@@ -98,50 +133,142 @@ rb_cpSpaceGetGravity(VALUE self)
|
|
98
133
|
}
|
99
134
|
|
100
135
|
static VALUE
|
101
|
-
rb_cpSpaceSetGravity(VALUE self, VALUE val)
|
102
|
-
{
|
136
|
+
rb_cpSpaceSetGravity(VALUE self, VALUE val) {
|
103
137
|
SPACE(self)->gravity = *VGET(val);
|
104
138
|
return val;
|
105
139
|
}
|
106
140
|
|
107
141
|
static int
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
142
|
+
doNothingCallback(cpArbiter *arb, cpSpace *space, void *data) {
|
143
|
+
return 0;
|
144
|
+
}
|
145
|
+
|
146
|
+
// We need this as rb_obj_method_arity is not in 1.8.7
|
147
|
+
static int cp_rb_obj_method_arity(VALUE self, ID id) {
|
148
|
+
VALUE metho = rb_funcall(self , rb_intern("method"), 1, ID2SYM(id));
|
149
|
+
VALUE arity = rb_funcall(metho, rb_intern("arity"), 0, 0);
|
150
|
+
return NUM2INT(arity);
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
// This callback function centralizes all collision callbacks.
|
156
|
+
// it also adds flexibility by changing theway the callback is called on the
|
157
|
+
// arity of the callback block or method. With arity0, no args are pased,
|
158
|
+
// with arity 1, the arbiter,
|
159
|
+
// with arity 2, body_a and body_b,
|
160
|
+
// with arity 3 or more -> body_a, body_b, arbiter
|
161
|
+
static int do_callback(void * data, ID method, cpArbiter *arb) {
|
162
|
+
int res = 0;
|
163
|
+
CP_ARBITER_GET_SHAPES(arb, a, b);
|
164
|
+
VALUE object = (VALUE) data;
|
165
|
+
VALUE va = (VALUE)a->data;
|
166
|
+
VALUE vb = (VALUE)b->data;
|
167
|
+
VALUE varb = ARBWRAP(arb);
|
168
|
+
int arity = cp_rb_obj_method_arity(object, method);
|
169
|
+
switch(arity) {
|
170
|
+
case 0:
|
171
|
+
return CP_BOOL_INT(rb_funcall(object, method, 0));
|
172
|
+
case 1:
|
173
|
+
return CP_BOOL_INT(rb_funcall(object, method, 1, varb));
|
174
|
+
case 2:
|
175
|
+
return CP_BOOL_INT(rb_funcall(object, method, 2, va, vb));
|
176
|
+
case 3:
|
177
|
+
default:
|
178
|
+
return CP_BOOL_INT(rb_funcall(object, method, 3, va, vb, varb));
|
179
|
+
}
|
180
|
+
// we never get here
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
static int
|
185
|
+
compatibilityCallback(cpArbiter *arb, cpSpace *space, void *data) {
|
186
|
+
return do_callback(data, id_call, arb);
|
187
|
+
}
|
188
|
+
|
189
|
+
static int
|
190
|
+
beginCallback(cpArbiter *arb, cpSpace *space, void *data) {
|
191
|
+
return do_callback(data, id_begin, arb);
|
192
|
+
}
|
193
|
+
|
194
|
+
static int
|
195
|
+
preSolveCallback(cpArbiter *arb, cpSpace *space, void *data) {
|
196
|
+
return do_callback(data, id_pre_solve, arb);
|
197
|
+
}
|
198
|
+
|
199
|
+
static void
|
200
|
+
postSolveCallback(cpArbiter *arb, cpSpace *space, void *data) {
|
201
|
+
do_callback(data, id_post_solve, arb);
|
202
|
+
}
|
203
|
+
|
204
|
+
static void
|
205
|
+
separateCallback(cpArbiter *arb, cpSpace *space, void *data) {
|
206
|
+
do_callback(data, id_separate, arb);
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
static int
|
211
|
+
respondsTo(VALUE obj, ID method) {
|
212
|
+
VALUE value = rb_funcall(obj, rb_intern("respond_to?"), 1, ID2SYM(method));
|
213
|
+
return RTEST(value);
|
214
|
+
}
|
215
|
+
|
216
|
+
static int
|
217
|
+
isBlock(VALUE obj) {
|
218
|
+
return respondsTo(obj, id_call);
|
115
219
|
}
|
116
220
|
|
117
221
|
static VALUE
|
118
|
-
|
222
|
+
rb_cpSpaceAddCollisionHandler(int argc, VALUE *argv, VALUE self)
|
119
223
|
{
|
120
|
-
VALUE a, b, block;
|
121
|
-
|
224
|
+
VALUE a, b, obj, block;
|
225
|
+
obj = 0;
|
226
|
+
rb_scan_args(argc, argv, "21&", &a, &b, &obj, &block);
|
122
227
|
|
123
228
|
VALUE id_a = rb_obj_id(a);
|
124
229
|
VALUE id_b = rb_obj_id(b);
|
125
|
-
if(NIL_P(block)) {
|
126
|
-
cpSpaceAddCollisionPairFunc(SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
|
127
|
-
NULL, NULL);
|
128
|
-
} else {
|
129
|
-
cpSpaceAddCollisionPairFunc(SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
|
130
|
-
collisionCallback, (void *)block);
|
131
|
-
}
|
132
|
-
|
133
230
|
VALUE blocks = rb_iv_get(self, "blocks");
|
134
|
-
rb_hash_aset(blocks, rb_ary_new3(2, id_a, id_b), block);
|
135
231
|
|
232
|
+
if(RTEST(obj) && RTEST(block)){
|
233
|
+
rb_raise(rb_eArgError, "Cannot specify both a handler object and a block.");
|
234
|
+
} else if(RTEST(block)){
|
235
|
+
cpSpaceAddCollisionHandler(
|
236
|
+
SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
|
237
|
+
NULL,
|
238
|
+
compatibilityCallback,
|
239
|
+
NULL,
|
240
|
+
NULL,
|
241
|
+
(void *)block
|
242
|
+
);
|
243
|
+
|
244
|
+
rb_hash_aset(blocks, rb_ary_new3(2, id_a, id_b), block);
|
245
|
+
} else if(RTEST(obj)) {
|
246
|
+
cpSpaceAddCollisionHandler(
|
247
|
+
SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
|
248
|
+
(respondsTo(obj, id_begin) ? beginCallback : NULL),
|
249
|
+
(respondsTo(obj, id_pre_solve) ? preSolveCallback : NULL),
|
250
|
+
(respondsTo(obj, id_post_solve) ? postSolveCallback : NULL),
|
251
|
+
(respondsTo(obj, id_separate) ? separateCallback : NULL),
|
252
|
+
(void *)obj
|
253
|
+
);
|
254
|
+
|
255
|
+
rb_hash_aset(blocks, rb_ary_new3(2, id_a, id_b), obj);
|
256
|
+
} else {
|
257
|
+
cpSpaceAddCollisionHandler(
|
258
|
+
SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
|
259
|
+
NULL, doNothingCallback, NULL, NULL, NULL
|
260
|
+
);
|
261
|
+
}
|
262
|
+
|
136
263
|
return Qnil;
|
137
264
|
}
|
138
265
|
|
139
266
|
static VALUE
|
140
|
-
|
267
|
+
rb_cpSpaceRemoveCollisionHandler(VALUE self, VALUE a, VALUE b)
|
141
268
|
{
|
142
269
|
VALUE id_a = rb_obj_id(a);
|
143
270
|
VALUE id_b = rb_obj_id(b);
|
144
|
-
|
271
|
+
cpSpaceRemoveCollisionHandler(SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b));
|
145
272
|
|
146
273
|
VALUE blocks = rb_iv_get(self, "blocks");
|
147
274
|
rb_hash_delete(blocks, rb_ary_new3(2, id_a, id_b));
|
@@ -150,22 +277,59 @@ rb_cpSpaceRemoveCollisionFunc(VALUE self, VALUE a, VALUE b)
|
|
150
277
|
}
|
151
278
|
|
152
279
|
static VALUE
|
153
|
-
|
280
|
+
rb_cpSpaceSetDefaultCollisionHandler(int argc, VALUE *argv, VALUE self)
|
154
281
|
{
|
155
|
-
VALUE block;
|
156
|
-
rb_scan_args(argc, argv, "
|
282
|
+
VALUE obj, block;
|
283
|
+
rb_scan_args(argc, argv, "01&", &obj, &block);
|
157
284
|
|
158
|
-
if(
|
159
|
-
|
285
|
+
if(RTEST(obj) && RTEST(block)){
|
286
|
+
rb_raise(rb_eArgError, "Cannot specify both a handler object and a block.");
|
287
|
+
} else if(RTEST(block)){
|
288
|
+
cpSpaceSetDefaultCollisionHandler(
|
289
|
+
SPACE(self),
|
290
|
+
NULL,
|
291
|
+
compatibilityCallback,
|
292
|
+
NULL,
|
293
|
+
NULL,
|
294
|
+
(void *)block
|
295
|
+
);
|
296
|
+
|
297
|
+
rb_hash_aset(rb_iv_get(self, "blocks"), ID2SYM(rb_intern("default")), block);
|
298
|
+
} else if(RTEST(obj)) {
|
299
|
+
cpSpaceSetDefaultCollisionHandler(
|
300
|
+
SPACE(self),
|
301
|
+
(respondsTo(obj, id_begin) ? beginCallback : NULL),
|
302
|
+
(respondsTo(obj, id_pre_solve) ? preSolveCallback : NULL),
|
303
|
+
(respondsTo(obj, id_post_solve) ? postSolveCallback : NULL),
|
304
|
+
(respondsTo(obj, id_separate) ? separateCallback : NULL),
|
305
|
+
(void *)obj
|
306
|
+
);
|
307
|
+
|
308
|
+
rb_hash_aset(rb_iv_get(self, "blocks"), ID2SYM(rb_intern("default")), obj);
|
160
309
|
} else {
|
161
|
-
|
310
|
+
cpSpaceSetDefaultCollisionHandler(
|
311
|
+
SPACE(self), NULL, doNothingCallback, NULL, NULL, NULL
|
312
|
+
);
|
162
313
|
}
|
163
|
-
|
164
|
-
rb_hash_aset(rb_iv_get(self, "blocks"), ID2SYM(rb_intern("default")), block);
|
165
314
|
|
166
315
|
return Qnil;
|
167
316
|
}
|
168
317
|
|
318
|
+
static void
|
319
|
+
poststepCallback(cpSpace *space, void *obj, void *data) {
|
320
|
+
rb_funcall((VALUE)data, id_call, 2, SPACEWRAP(space), (VALUE)obj);
|
321
|
+
}
|
322
|
+
|
323
|
+
|
324
|
+
static VALUE
|
325
|
+
rb_cpSpaceAddPostStepCallback(int argc, VALUE *argv, VALUE self) {
|
326
|
+
VALUE obj, block;
|
327
|
+
rb_scan_args(argc, argv, "10&", &obj, &block);
|
328
|
+
cpSpaceAddPostStepCallback(SPACE(self),
|
329
|
+
poststepCallback, (void *) obj, (void *) block);
|
330
|
+
return self;
|
331
|
+
}
|
332
|
+
|
169
333
|
static VALUE
|
170
334
|
rb_cpSpaceAddShape(VALUE self, VALUE shape)
|
171
335
|
{
|
@@ -191,11 +355,11 @@ rb_cpSpaceAddBody(VALUE self, VALUE body)
|
|
191
355
|
}
|
192
356
|
|
193
357
|
static VALUE
|
194
|
-
|
358
|
+
rb_cpSpaceAddConstraint(VALUE self, VALUE constraint)
|
195
359
|
{
|
196
|
-
|
197
|
-
rb_ary_push(rb_iv_get(self, "
|
198
|
-
return
|
360
|
+
cpSpaceAddConstraint(SPACE(self), CONSTRAINT(constraint));
|
361
|
+
rb_ary_push(rb_iv_get(self, "constraints"), constraint);
|
362
|
+
return constraint;
|
199
363
|
}
|
200
364
|
|
201
365
|
static VALUE
|
@@ -220,10 +384,10 @@ rb_cpSpaceRemoveBody(VALUE self, VALUE body)
|
|
220
384
|
}
|
221
385
|
|
222
386
|
static VALUE
|
223
|
-
|
387
|
+
rb_cpSpaceRemoveConstraint(VALUE self, VALUE constraint)
|
224
388
|
{
|
225
|
-
|
226
|
-
return rb_ary_delete(rb_iv_get(self, "
|
389
|
+
cpSpaceRemoveConstraint(SPACE(self), CONSTRAINT(constraint));
|
390
|
+
return rb_ary_delete(rb_iv_get(self, "constraints"), constraint);
|
227
391
|
}
|
228
392
|
|
229
393
|
static VALUE
|
@@ -247,34 +411,149 @@ rb_cpSpaceRehashStatic(VALUE self)
|
|
247
411
|
return Qnil;
|
248
412
|
}
|
249
413
|
|
414
|
+
static VALUE
|
415
|
+
rb_cpSpaceRehashShape(VALUE self, VALUE shape)
|
416
|
+
{
|
417
|
+
cpSpaceRehashShape(SPACE(self), SHAPE(shape));
|
418
|
+
return Qnil;
|
419
|
+
}
|
420
|
+
|
421
|
+
|
422
|
+
static unsigned int get_layers(VALUE layers) {
|
423
|
+
if (NIL_P(layers)) return ~0;
|
424
|
+
return NUM2UINT(layers);
|
425
|
+
}
|
426
|
+
|
427
|
+
static unsigned int get_group(VALUE group) {
|
428
|
+
if (NIL_P(group)) return 0;
|
429
|
+
return NUM2UINT(group);
|
430
|
+
}
|
431
|
+
|
250
432
|
static void
|
251
|
-
|
433
|
+
pointQueryCallback(cpShape *shape, VALUE block)
|
252
434
|
{
|
253
|
-
rb_funcall(
|
435
|
+
rb_funcall(block, id_call, 1, (VALUE)shape->data);
|
254
436
|
}
|
255
437
|
|
256
438
|
static VALUE
|
257
|
-
|
439
|
+
rb_cpSpacePointQuery(int argc, VALUE *argv, VALUE self)
|
258
440
|
{
|
259
|
-
VALUE point, block;
|
260
|
-
rb_scan_args(argc, argv, "
|
441
|
+
VALUE point, layers, group, block;
|
442
|
+
rb_scan_args(argc, argv, "12&", &point, &layers, &group, &block);
|
261
443
|
|
262
|
-
|
444
|
+
cpSpacePointQuery(
|
445
|
+
SPACE(self), *VGET(point), get_layers(layers), get_group(group),
|
446
|
+
(cpSpacePointQueryFunc)pointQueryCallback, (void *)block
|
447
|
+
);
|
263
448
|
|
264
449
|
return Qnil;
|
265
450
|
}
|
266
451
|
|
267
452
|
static VALUE
|
268
|
-
|
453
|
+
rb_cpSpacePointQueryFirst(int argc, VALUE *argv, VALUE self)
|
454
|
+
{
|
455
|
+
VALUE point, layers, group;
|
456
|
+
rb_scan_args(argc, argv, "12", &point, &layers, &group);
|
457
|
+
|
458
|
+
cpShape *shape = cpSpacePointQueryFirst(
|
459
|
+
SPACE(self), *VGET(point),
|
460
|
+
get_layers(layers), get_group(group)
|
461
|
+
);
|
462
|
+
|
463
|
+
return (shape ? (VALUE)shape->data : Qnil);
|
464
|
+
}
|
465
|
+
|
466
|
+
static void
|
467
|
+
segmentQueryCallback(cpShape *shape, cpFloat t, cpVect n, VALUE block)
|
468
|
+
{
|
469
|
+
rb_funcall(block, id_call, 1, (VALUE)shape->data, rb_float_new(t), VNEW(n));
|
470
|
+
}
|
471
|
+
|
472
|
+
static VALUE
|
473
|
+
rb_cpSpaceSegmentQuery(int argc, VALUE *argv, VALUE self)
|
269
474
|
{
|
270
|
-
VALUE
|
271
|
-
rb_scan_args(argc, argv, "
|
475
|
+
VALUE a, b, layers, group, block;
|
476
|
+
rb_scan_args(argc, argv, "22&", &a, &b, &layers, &group, &block);
|
272
477
|
|
273
|
-
|
478
|
+
cpSpaceSegmentQuery(
|
479
|
+
SPACE(self), *VGET(a), *VGET(b),
|
480
|
+
get_layers(layers), get_group(group),
|
481
|
+
(cpSpaceSegmentQueryFunc)segmentQueryCallback, (void *)block
|
482
|
+
);
|
274
483
|
|
275
484
|
return Qnil;
|
276
485
|
}
|
277
486
|
|
487
|
+
static VALUE
|
488
|
+
rb_cpSpaceSegmentQueryFirst(int argc, VALUE *argv, VALUE self)
|
489
|
+
{
|
490
|
+
VALUE a, b, layers, group, block;
|
491
|
+
cpSegmentQueryInfo info = {NULL, 1.0f, cpvzero};
|
492
|
+
|
493
|
+
rb_scan_args(argc, argv, "22&", &a, &b, &layers, &group, &block);
|
494
|
+
|
495
|
+
cpSpaceSegmentQueryFirst(
|
496
|
+
SPACE(self), *VGET(a), *VGET(b),
|
497
|
+
get_layers(layers), get_group(group),
|
498
|
+
&info
|
499
|
+
);
|
500
|
+
// contrary to the standard chipmunk bindings, we also return a
|
501
|
+
// struct here with then needed values.
|
502
|
+
if(info.shape) {
|
503
|
+
return rb_cpSegmentQueryInfoNew((VALUE)info.shape->data, rb_float_new(info.t), VNEW(info.n));
|
504
|
+
}
|
505
|
+
return Qnil;
|
506
|
+
|
507
|
+
}
|
508
|
+
|
509
|
+
|
510
|
+
static void
|
511
|
+
bbQueryCallback(cpShape *shape, VALUE block)
|
512
|
+
{
|
513
|
+
rb_funcall(block, id_call, 1, (VALUE)shape->data);
|
514
|
+
}
|
515
|
+
|
516
|
+
/* Bounding box query. */
|
517
|
+
static VALUE
|
518
|
+
rb_cpSpaceBBQuery(int argc, VALUE *argv, VALUE self)
|
519
|
+
{
|
520
|
+
VALUE bb, layers, group, block;
|
521
|
+
unsigned int l = ~0;
|
522
|
+
unsigned int g = 0;
|
523
|
+
rb_scan_args(argc, argv, "12&", &bb, &layers, &group, &block);
|
524
|
+
|
525
|
+
if (!NIL_P(layers)) l = NUM2UINT(layers);
|
526
|
+
if (!NIL_P(group)) g = NUM2UINT(group);
|
527
|
+
|
528
|
+
cpSpaceBBQuery(
|
529
|
+
SPACE(self), *BBGET(bb), l, g,
|
530
|
+
(cpSpaceBBQueryFunc)bbQueryCallback, (void *)block
|
531
|
+
);
|
532
|
+
|
533
|
+
return Qnil;
|
534
|
+
}
|
535
|
+
|
536
|
+
static void
|
537
|
+
shapeQueryCallback(cpShape *shape, cpContactPointSet *points, VALUE block)
|
538
|
+
{
|
539
|
+
rb_funcall(block, id_call, 1, (VALUE)shape->data);
|
540
|
+
}
|
541
|
+
|
542
|
+
/* Shape query. */
|
543
|
+
static VALUE
|
544
|
+
rb_cpSpaceShapeQuery(int argc, VALUE *argv, VALUE self)
|
545
|
+
{
|
546
|
+
VALUE shape, block;
|
547
|
+
rb_scan_args(argc, argv, "1&", &shape, &block);
|
548
|
+
|
549
|
+
cpSpaceShapeQuery(
|
550
|
+
SPACE(self), SHAPE(shape),
|
551
|
+
(cpSpaceShapeQueryFunc)shapeQueryCallback, (void *)block
|
552
|
+
);
|
553
|
+
|
554
|
+
return Qnil;
|
555
|
+
}
|
556
|
+
|
278
557
|
static VALUE
|
279
558
|
rb_cpSpaceStep(VALUE self, VALUE dt)
|
280
559
|
{
|
@@ -282,12 +561,44 @@ rb_cpSpaceStep(VALUE self, VALUE dt)
|
|
282
561
|
return Qnil;
|
283
562
|
}
|
284
563
|
|
564
|
+
static VALUE
|
565
|
+
rb_cpSpaceGetData(VALUE self) {
|
566
|
+
return rb_iv_get(self, "data");
|
567
|
+
}
|
568
|
+
|
569
|
+
static VALUE
|
570
|
+
rb_cpSpaceSetData(VALUE self, VALUE val) {
|
571
|
+
rb_iv_set(self, "data", val);
|
572
|
+
return val;
|
573
|
+
}
|
574
|
+
|
575
|
+
|
576
|
+
static VALUE
|
577
|
+
rb_cpSpaceActivateShapesTouchingShape(VALUE self, VALUE shape)
|
578
|
+
{
|
579
|
+
cpSpaceActivateShapesTouchingShape(SPACE(self), SHAPE(shape));
|
580
|
+
return self;
|
581
|
+
}
|
582
|
+
|
583
|
+
|
584
|
+
/** in chipmunk 6
|
585
|
+
static VALUE
|
586
|
+
rb_cpSpaceUseSpatialHash(VALUE self, VALUE dim, VALUE count) {
|
587
|
+
cpSpaceUseSpatialHash(SPACE(self), NUM2DBL(dim), NUM2INT(count));
|
588
|
+
return Qnil;
|
589
|
+
}
|
590
|
+
*/
|
591
|
+
|
285
592
|
|
286
593
|
|
287
594
|
void
|
288
595
|
Init_cpSpace(void)
|
289
596
|
{
|
290
597
|
id_call = rb_intern("call");
|
598
|
+
id_begin = rb_intern("begin");
|
599
|
+
id_pre_solve = rb_intern("pre_solve");
|
600
|
+
id_post_solve = rb_intern("post_solve");
|
601
|
+
id_separate = rb_intern("separate");
|
291
602
|
|
292
603
|
c_cpSpace = rb_define_class_under(m_Chipmunk, "Space", rb_cObject);
|
293
604
|
rb_define_alloc_func(c_cpSpace, rb_cpSpaceAlloc);
|
@@ -305,26 +616,96 @@ Init_cpSpace(void)
|
|
305
616
|
rb_define_method(c_cpSpace, "gravity", rb_cpSpaceGetGravity, 0);
|
306
617
|
rb_define_method(c_cpSpace, "gravity=", rb_cpSpaceSetGravity, 1);
|
307
618
|
|
308
|
-
rb_define_method(c_cpSpace, "add_collision_func",
|
309
|
-
|
310
|
-
|
619
|
+
rb_define_method(c_cpSpace, "add_collision_func",
|
620
|
+
rb_cpSpaceAddCollisionHandler, -1);
|
621
|
+
|
622
|
+
rb_define_method(c_cpSpace, "add_collision_handler",
|
623
|
+
rb_cpSpaceAddCollisionHandler, -1);
|
624
|
+
|
625
|
+
rb_define_method(c_cpSpace, "on_collision",
|
626
|
+
rb_cpSpaceAddCollisionHandler, -1);
|
627
|
+
|
628
|
+
rb_define_method(c_cpSpace, "remove_collision_func",
|
629
|
+
rb_cpSpaceRemoveCollisionHandler, 2);
|
630
|
+
|
631
|
+
rb_define_method(c_cpSpace, "remove_collision_handler",
|
632
|
+
rb_cpSpaceRemoveCollisionHandler, 2);
|
633
|
+
rb_define_method(c_cpSpace, "remove_collision",
|
634
|
+
rb_cpSpaceRemoveCollisionHandler, 2);
|
635
|
+
|
636
|
+
rb_define_method(c_cpSpace, "set_default_collision_func",
|
637
|
+
rb_cpSpaceSetDefaultCollisionHandler, -1);
|
638
|
+
rb_define_method(c_cpSpace, "set_default_collision_handler",
|
639
|
+
rb_cpSpaceSetDefaultCollisionHandler, -1);
|
640
|
+
rb_define_method(c_cpSpace, "on_default_collision",
|
641
|
+
rb_cpSpaceSetDefaultCollisionHandler, -1);
|
642
|
+
|
643
|
+
rb_define_method(c_cpSpace, "add_post_step_callback",
|
644
|
+
rb_cpSpaceAddPostStepCallback, -1);
|
645
|
+
rb_define_method(c_cpSpace, "on_post_step",
|
646
|
+
rb_cpSpaceAddPostStepCallback, -1);
|
647
|
+
|
648
|
+
|
649
|
+
|
311
650
|
|
312
651
|
rb_define_method(c_cpSpace, "add_shape", rb_cpSpaceAddShape, 1);
|
313
652
|
rb_define_method(c_cpSpace, "add_static_shape", rb_cpSpaceAddStaticShape, 1);
|
314
653
|
rb_define_method(c_cpSpace, "add_body", rb_cpSpaceAddBody, 1);
|
315
|
-
rb_define_method(c_cpSpace, "
|
654
|
+
rb_define_method(c_cpSpace, "add_constraint", rb_cpSpaceAddConstraint, 1);
|
316
655
|
|
317
656
|
rb_define_method(c_cpSpace, "remove_shape", rb_cpSpaceRemoveShape, 1);
|
318
657
|
rb_define_method(c_cpSpace, "remove_static_shape", rb_cpSpaceRemoveStaticShape, 1);
|
319
658
|
rb_define_method(c_cpSpace, "remove_body", rb_cpSpaceRemoveBody, 1);
|
320
|
-
rb_define_method(c_cpSpace, "
|
659
|
+
rb_define_method(c_cpSpace, "remove_constraint", rb_cpSpaceRemoveConstraint, 1);
|
321
660
|
|
322
661
|
rb_define_method(c_cpSpace, "resize_static_hash", rb_cpSpaceResizeStaticHash, 2);
|
323
662
|
rb_define_method(c_cpSpace, "resize_active_hash", rb_cpSpaceResizeActiveHash, 2);
|
324
663
|
rb_define_method(c_cpSpace, "rehash_static", rb_cpSpaceRehashStatic, 0);
|
664
|
+
rb_define_method(c_cpSpace, "rehash_shape", rb_cpSpaceRehashShape, 1);
|
665
|
+
|
666
|
+
rb_define_method(c_cpSpace, "point_query", rb_cpSpacePointQuery, -1);
|
667
|
+
rb_define_method(c_cpSpace, "point_query_first", rb_cpSpacePointQueryFirst, -1);
|
668
|
+
rb_define_method(c_cpSpace, "shape_point_query", rb_cpSpacePointQueryFirst, -1);
|
325
669
|
|
326
|
-
|
327
|
-
rb_define_method(c_cpSpace, "
|
670
|
+
|
671
|
+
rb_define_method(c_cpSpace, "segment_query", rb_cpSpaceSegmentQuery, -1);
|
672
|
+
rb_define_method(c_cpSpace, "segment_query_first", rb_cpSpaceSegmentQueryFirst, -1);
|
673
|
+
|
674
|
+
rb_define_method(c_cpSpace, "bb_query" , rb_cpSpaceBBQuery, -1);
|
675
|
+
rb_define_method(c_cpSpace, "shape_query" , rb_cpSpaceShapeQuery, -1);
|
676
|
+
|
328
677
|
|
329
678
|
rb_define_method(c_cpSpace, "step", rb_cpSpaceStep, 1);
|
679
|
+
|
680
|
+
rb_define_method(c_cpSpace, "object" , rb_cpSpaceGetData, 0);
|
681
|
+
rb_define_method(c_cpSpace, "object=", rb_cpSpaceSetData, 1);
|
682
|
+
|
683
|
+
rb_define_method(c_cpSpace, "sleep_time_threshold=",
|
684
|
+
rb_cpSpaceSetSleepTimeThreshold, 1);
|
685
|
+
rb_define_method(c_cpSpace, "sleep_time_threshold",
|
686
|
+
rb_cpSpaceGetSleepTimeThreshold, 0);
|
687
|
+
rb_define_method(c_cpSpace, "idle_speed_threshold=",
|
688
|
+
rb_cpSpaceSetIdleSpeedThreshold, 1);
|
689
|
+
rb_define_method(c_cpSpace, "idle_speed_threshold",
|
690
|
+
rb_cpSpaceGetIdleSpeedThreshold, 0);
|
691
|
+
|
692
|
+
// also define slghtly less verbose API
|
693
|
+
rb_define_method(c_cpSpace, "sleep_time=",
|
694
|
+
rb_cpSpaceSetSleepTimeThreshold, 1);
|
695
|
+
rb_define_method(c_cpSpace, "sleep_time",
|
696
|
+
rb_cpSpaceGetSleepTimeThreshold, 0);
|
697
|
+
rb_define_method(c_cpSpace, "idle_speed=",
|
698
|
+
rb_cpSpaceSetIdleSpeedThreshold, 1);
|
699
|
+
rb_define_method(c_cpSpace, "idle_speed",
|
700
|
+
rb_cpSpaceGetIdleSpeedThreshold, 0);
|
701
|
+
|
702
|
+
rb_define_method(c_cpSpace, "activate_shapes_touching_shape",
|
703
|
+
rb_cpSpaceActivateShapesTouchingShape, 1);
|
704
|
+
|
705
|
+
// this is nicer, though :)
|
706
|
+
rb_define_method(c_cpSpace, "activate_touching",
|
707
|
+
rb_cpSpaceActivateShapesTouchingShape, 1);
|
708
|
+
|
709
|
+
|
710
|
+
|
330
711
|
}
|