Class: Chipmunk::Space

Inherits:
Object
  • Object
show all
Defined in:
ext/chipmunk/rb_cpSpace.c

Instance Method Summary collapse

Constructor Details

#initializeObject


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'ext/chipmunk/rb_cpSpace.c', line 58

static VALUE
rb_cpSpaceInitialize(VALUE self) {
  cpSpace *space = SPACE(self);
  cpSpaceInit(space);

  // These might as well be in one shared hash.
  rb_iv_set(self, "@static_shapes", rb_ary_new());
  rb_iv_set(self, "@active_shapes", rb_ary_new());
  rb_iv_set(self, "@bodies", rb_ary_new());
  rb_iv_set(self, "@constraints", rb_ary_new());
  rb_iv_set(self, "@blocks", rb_hash_new());
  rb_iv_set(self, "@post_step_blocks", rb_hash_new());

  return self;
}

Instance Method Details

#activate_shapes_touching_shapeObject


562
563
564
565
566
# File 'ext/chipmunk/rb_cpSpace.c', line 562

static VALUE
rb_cpSpaceActivateShapesTouchingShape(VALUE self, VALUE shape) {
  cpSpaceActivateShapesTouchingShape(SPACE(self), SHAPE(shape));
  return self;
}

#activate_touchingObject

this is nicer, though :)


562
563
564
565
566
# File 'ext/chipmunk/rb_cpSpace.c', line 562

static VALUE
rb_cpSpaceActivateShapesTouchingShape(VALUE self, VALUE shape) {
  cpSpaceActivateShapesTouchingShape(SPACE(self), SHAPE(shape));
  return self;
}

#add_bodyObject


357
358
359
360
361
362
# File 'ext/chipmunk/rb_cpSpace.c', line 357

static VALUE
rb_cpSpaceAddBody(VALUE self, VALUE body) {
  cpSpaceAddBody(SPACE(self), BODY(body));
  rb_ary_push(rb_iv_get(self, "@bodies"), body);
  return body;
}

#add_collision_funcObject


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'ext/chipmunk/rb_cpSpace.c', line 225

static VALUE
rb_cpSpaceAddCollisionHandler(int argc, VALUE *argv, VALUE self) {
  VALUE a, b, obj, block;
  obj = 0;
  rb_scan_args(argc, argv, "21&", &a, &b, &obj, &block);

  VALUE id_a   = rb_obj_id(a);
  VALUE id_b   = rb_obj_id(b);
  VALUE blocks = rb_iv_get(self, "@blocks");

  if(RTEST(obj) && RTEST(block)) {
    rb_raise(rb_eArgError, "Cannot specify both a handler object and a block.");
  } else if(RTEST(block)) {
    cpSpaceAddCollisionHandler(
      SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
      NULL,
      compatibilityCallback,
      NULL,
      NULL,
      (void *)block
      );

    rb_hash_aset(blocks, rb_ary_new3(2, id_a, id_b), block);
  } else if(RTEST(obj)) {
    cpSpaceAddCollisionHandler(
      SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
      (respondsTo(obj, id_begin)      ? beginCallback     : NULL),
      (respondsTo(obj, id_pre_solve)  ? preSolveCallback  : NULL),
      (respondsTo(obj, id_post_solve) ? postSolveCallback : NULL),
      (respondsTo(obj, id_separate)   ? separateCallback  : NULL),
      (void *)obj
      );

    rb_hash_aset(blocks, rb_ary_new3(2, id_a, id_b), obj);
  } else {
    cpSpaceAddCollisionHandler(
      SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
      NULL, doNothingCallback, NULL, NULL, NULL
      );
  }

  return Qnil;
}

#add_collision_handlerObject


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'ext/chipmunk/rb_cpSpace.c', line 225

static VALUE
rb_cpSpaceAddCollisionHandler(int argc, VALUE *argv, VALUE self) {
  VALUE a, b, obj, block;
  obj = 0;
  rb_scan_args(argc, argv, "21&", &a, &b, &obj, &block);

  VALUE id_a   = rb_obj_id(a);
  VALUE id_b   = rb_obj_id(b);
  VALUE blocks = rb_iv_get(self, "@blocks");

  if(RTEST(obj) && RTEST(block)) {
    rb_raise(rb_eArgError, "Cannot specify both a handler object and a block.");
  } else if(RTEST(block)) {
    cpSpaceAddCollisionHandler(
      SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
      NULL,
      compatibilityCallback,
      NULL,
      NULL,
      (void *)block
      );

    rb_hash_aset(blocks, rb_ary_new3(2, id_a, id_b), block);
  } else if(RTEST(obj)) {
    cpSpaceAddCollisionHandler(
      SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
      (respondsTo(obj, id_begin)      ? beginCallback     : NULL),
      (respondsTo(obj, id_pre_solve)  ? preSolveCallback  : NULL),
      (respondsTo(obj, id_post_solve) ? postSolveCallback : NULL),
      (respondsTo(obj, id_separate)   ? separateCallback  : NULL),
      (void *)obj
      );

    rb_hash_aset(blocks, rb_ary_new3(2, id_a, id_b), obj);
  } else {
    cpSpaceAddCollisionHandler(
      SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
      NULL, doNothingCallback, NULL, NULL, NULL
      );
  }

  return Qnil;
}

#add_constraintObject


364
365
366
367
368
369
# File 'ext/chipmunk/rb_cpSpace.c', line 364

static VALUE
rb_cpSpaceAddConstraint(VALUE self, VALUE constraint) {
  cpSpaceAddConstraint(SPACE(self), CONSTRAINT(constraint));
  rb_ary_push(rb_iv_get(self, "@constraints"), constraint);
  return constraint;
}

#add_post_step_callbackObject


325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'ext/chipmunk/rb_cpSpace.c', line 325

static VALUE
rb_cpSpaceAddPostStepCallback(int argc, VALUE *argv, VALUE self) {
  VALUE obj, block;
  VALUE blocks = rb_iv_get(self, "@post_step_blocks");

  rb_scan_args(argc, argv, "10&", &obj, &block);
  if(!RTEST(block)) {
    rb_raise(rb_eArgError, "Cannot omit the block.");
  }

  rb_hash_aset(blocks, obj, block);

  cpSpaceAddPostStepCallback(SPACE(self),
                             poststepCallback, (void *) obj, (void *) block);

  return self;
}

#add_shapeObject


343
344
345
346
347
348
# File 'ext/chipmunk/rb_cpSpace.c', line 343

static VALUE
rb_cpSpaceAddShape(VALUE self, VALUE shape) {
  cpSpaceAddShape(SPACE(self), SHAPE(shape));
  rb_ary_push(rb_iv_get(self, "@active_shapes"), shape);
  return shape;
}

#add_static_shapeObject


350
351
352
353
354
355
# File 'ext/chipmunk/rb_cpSpace.c', line 350

static VALUE
rb_cpSpaceAddStaticShape(VALUE self, VALUE shape) {
  cpSpaceAddStaticShape(SPACE(self), SHAPE(shape));
  rb_ary_push(rb_iv_get(self, "@static_shapes"), shape);
  return shape;
}

#bb_queryObject

Bounding box query.


518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'ext/chipmunk/rb_cpSpace.c', line 518

static VALUE
rb_cpSpaceBBQuery(int argc, VALUE *argv, VALUE self) {
  VALUE bb, layers, group, block;
  unsigned int l = ~0;
  unsigned int g =  0;
  rb_scan_args(argc, argv, "12&", &bb, &layers, &group, &block);

  if (!NIL_P(layers)) l = NUM2UINT(layers);
  if (!NIL_P(group)) g = NUM2UINT(group);

  cpSpaceBBQuery(
    SPACE(self), *BBGET(bb), l, g,
    (cpSpaceBBQueryFunc)bbQueryCallback, (void *)block
    );

  return Qnil;
}

#collision_biasObject

#collision_bias=Object

#collision_persistenceObject

#collision_persistence=Object

#collision_slopObject

#collision_slop=Object

#contact_graph_enabledObject


120
121
122
123
# File 'ext/chipmunk/rb_cpSpace.c', line 120

static VALUE
rb_cpSpaceGetContactGraphEnabled(VALUE self) {
  return CP_INT_BOOL(SPACE(self)->enableContactGraph);
}

#contact_graph_enabled=Object


125
126
127
128
129
# File 'ext/chipmunk/rb_cpSpace.c', line 125

static VALUE
rb_cpSpaceSetContactGraphEnabled(VALUE self, VALUE val) {
  SPACE(self)->enableContactGraph = CP_BOOL_INT(val);
  return val;
}

#dampingObject


109
110
111
112
# File 'ext/chipmunk/rb_cpSpace.c', line 109

static VALUE
rb_cpSpaceGetDamping(VALUE self) {
  return rb_float_new(SPACE(self)->damping);
}

#damping=Object


114
115
116
117
118
# File 'ext/chipmunk/rb_cpSpace.c', line 114

static VALUE
rb_cpSpaceSetDamping(VALUE self, VALUE val) {
  SPACE(self)->damping = NUM2DBL(val);
  return val;
}

#gravityObject


132
133
134
135
# File 'ext/chipmunk/rb_cpSpace.c', line 132

static VALUE
rb_cpSpaceGetGravity(VALUE self) {
  return VWRAP(self, &SPACE(self)->gravity);
}

#gravity=Object


137
138
139
140
141
# File 'ext/chipmunk/rb_cpSpace.c', line 137

static VALUE
rb_cpSpaceSetGravity(VALUE self, VALUE val) {
  SPACE(self)->gravity = *VGET(val);
  return val;
}

#idle_speedObject


85
86
87
88
# File 'ext/chipmunk/rb_cpSpace.c', line 85

static VALUE
rb_cpSpaceGetIdleSpeedThreshold(VALUE self) {
  return UINT2NUM(SPACE(self)->idleSpeedThreshold);
}

#idle_speed=Object


90
91
92
93
94
# File 'ext/chipmunk/rb_cpSpace.c', line 90

static VALUE
rb_cpSpaceSetIdleSpeedThreshold(VALUE self, VALUE val) {
  SPACE(self)->idleSpeedThreshold = NUM2INT(val);
  return val;
}

#idle_speed_thresholdObject


85
86
87
88
# File 'ext/chipmunk/rb_cpSpace.c', line 85

static VALUE
rb_cpSpaceGetIdleSpeedThreshold(VALUE self) {
  return UINT2NUM(SPACE(self)->idleSpeedThreshold);
}

#idle_speed_threshold=Object


90
91
92
93
94
# File 'ext/chipmunk/rb_cpSpace.c', line 90

static VALUE
rb_cpSpaceSetIdleSpeedThreshold(VALUE self, VALUE val) {
  SPACE(self)->idleSpeedThreshold = NUM2INT(val);
  return val;
}

#iterationsObject


98
99
100
101
# File 'ext/chipmunk/rb_cpSpace.c', line 98

static VALUE
rb_cpSpaceGetIterations(VALUE self) {
  return INT2NUM(SPACE(self)->iterations);
}

#iterations=Object


103
104
105
106
107
# File 'ext/chipmunk/rb_cpSpace.c', line 103

static VALUE
rb_cpSpaceSetIterations(VALUE self, VALUE val) {
  SPACE(self)->iterations = NUM2INT(val);
  return val;
}

#on_collisionObject


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'ext/chipmunk/rb_cpSpace.c', line 225

static VALUE
rb_cpSpaceAddCollisionHandler(int argc, VALUE *argv, VALUE self) {
  VALUE a, b, obj, block;
  obj = 0;
  rb_scan_args(argc, argv, "21&", &a, &b, &obj, &block);

  VALUE id_a   = rb_obj_id(a);
  VALUE id_b   = rb_obj_id(b);
  VALUE blocks = rb_iv_get(self, "@blocks");

  if(RTEST(obj) && RTEST(block)) {
    rb_raise(rb_eArgError, "Cannot specify both a handler object and a block.");
  } else if(RTEST(block)) {
    cpSpaceAddCollisionHandler(
      SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
      NULL,
      compatibilityCallback,
      NULL,
      NULL,
      (void *)block
      );

    rb_hash_aset(blocks, rb_ary_new3(2, id_a, id_b), block);
  } else if(RTEST(obj)) {
    cpSpaceAddCollisionHandler(
      SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
      (respondsTo(obj, id_begin)      ? beginCallback     : NULL),
      (respondsTo(obj, id_pre_solve)  ? preSolveCallback  : NULL),
      (respondsTo(obj, id_post_solve) ? postSolveCallback : NULL),
      (respondsTo(obj, id_separate)   ? separateCallback  : NULL),
      (void *)obj
      );

    rb_hash_aset(blocks, rb_ary_new3(2, id_a, id_b), obj);
  } else {
    cpSpaceAddCollisionHandler(
      SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
      NULL, doNothingCallback, NULL, NULL, NULL
      );
  }

  return Qnil;
}

#on_default_collisionObject


281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'ext/chipmunk/rb_cpSpace.c', line 281

static VALUE
rb_cpSpaceSetDefaultCollisionHandler(int argc, VALUE *argv, VALUE self) {
  VALUE obj, block;
  rb_scan_args(argc, argv, "01&", &obj, &block);

  if(RTEST(obj) && RTEST(block)) {
    rb_raise(rb_eArgError, "Cannot specify both a handler object and a block.");
  } else if(RTEST(block)) {
    cpSpaceSetDefaultCollisionHandler(
      SPACE(self),
      NULL,
      compatibilityCallback,
      NULL,
      NULL,
      (void *)block
      );

    rb_hash_aset(rb_iv_get(self, "@blocks"), ID2SYM(rb_intern("default")), block);
  } else if(RTEST(obj)) {
    cpSpaceSetDefaultCollisionHandler(
      SPACE(self),
      (respondsTo(obj, id_begin)      ? beginCallback     : NULL),
      (respondsTo(obj, id_pre_solve)  ? preSolveCallback  : NULL),
      (respondsTo(obj, id_post_solve) ? postSolveCallback : NULL),
      (respondsTo(obj, id_separate)   ? separateCallback  : NULL),
      (void *)obj
      );

    rb_hash_aset(rb_iv_get(self, "@blocks"), ID2SYM(rb_intern("default")), obj);
  } else {
    cpSpaceSetDefaultCollisionHandler(
      SPACE(self), NULL, doNothingCallback, NULL, NULL, NULL
      );
  }

  return Qnil;
}

#on_post_stepObject


325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'ext/chipmunk/rb_cpSpace.c', line 325

static VALUE
rb_cpSpaceAddPostStepCallback(int argc, VALUE *argv, VALUE self) {
  VALUE obj, block;
  VALUE blocks = rb_iv_get(self, "@post_step_blocks");

  rb_scan_args(argc, argv, "10&", &obj, &block);
  if(!RTEST(block)) {
    rb_raise(rb_eArgError, "Cannot omit the block.");
  }

  rb_hash_aset(blocks, obj, block);

  cpSpaceAddPostStepCallback(SPACE(self),
                             poststepCallback, (void *) obj, (void *) block);

  return self;
}

#point_queryObject


448
449
450
451
452
453
454
455
456
457
458
459
# File 'ext/chipmunk/rb_cpSpace.c', line 448

static VALUE
rb_cpSpacePointQuery(int argc, VALUE *argv, VALUE self) {
  VALUE point, layers, group, block;
  rb_scan_args(argc, argv, "12&", &point, &layers, &group, &block);

  cpSpacePointQuery(
    SPACE(self), *VGET(point), get_layers(layers), get_group(group),
    (cpSpacePointQueryFunc)pointQueryCallback, (void *)block
    );

  return Qnil;
}

#point_query_firstObject


461
462
463
464
465
466
467
468
469
470
471
472
# File 'ext/chipmunk/rb_cpSpace.c', line 461

static VALUE
rb_cpSpacePointQueryFirst(int argc, VALUE *argv, VALUE self) {
  VALUE point, layers, group;
  rb_scan_args(argc, argv, "12", &point, &layers, &group);

  cpShape *shape = cpSpacePointQueryFirst(
    SPACE(self), *VGET(point),
    get_layers(layers), get_group(group)
    );

  return (shape ? (VALUE)shape->data : Qnil);
}

#reindex_shapeObject


424
425
426
427
428
# File 'ext/chipmunk/rb_cpSpace.c', line 424

static VALUE
rb_cpSpaceReindexShape(VALUE self, VALUE shape) {
  cpSpaceReindexShape(SPACE(self), SHAPE(shape));
  return Qnil;
}

#reindex_staticObject

cpSpaceResizeActiveHash(SPACE(self), NUM2DBL(dim), NUM2INT(count));

return Qnil;

418
419
420
421
422
# File 'ext/chipmunk/rb_cpSpace.c', line 418

static VALUE
rb_cpSpaceReindexStatic(VALUE self) {
  cpSpaceReindexStatic(SPACE(self));
  return Qnil;
}

#remove_bodyObject


385
386
387
388
389
390
# File 'ext/chipmunk/rb_cpSpace.c', line 385

static VALUE
rb_cpSpaceRemoveBody(VALUE self, VALUE body) {
  VALUE ok = rb_ary_delete(rb_iv_get(self, "@bodies"), body);
  if(!(NIL_P(ok))) cpSpaceRemoveBody(SPACE(self), BODY(body));
  return ok;
}

#remove_collisionObject


269
270
271
272
273
274
275
276
277
278
279
# File 'ext/chipmunk/rb_cpSpace.c', line 269

static VALUE
rb_cpSpaceRemoveCollisionHandler(VALUE self, VALUE a, VALUE b) {
  VALUE id_a   = rb_obj_id(a);
  VALUE id_b   = rb_obj_id(b);
  cpSpaceRemoveCollisionHandler(SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b));

  VALUE blocks = rb_iv_get(self, "@blocks");
  rb_hash_delete(blocks, rb_ary_new3(2, id_a, id_b));

  return Qnil;
}

#remove_collision_funcObject


269
270
271
272
273
274
275
276
277
278
279
# File 'ext/chipmunk/rb_cpSpace.c', line 269

static VALUE
rb_cpSpaceRemoveCollisionHandler(VALUE self, VALUE a, VALUE b) {
  VALUE id_a   = rb_obj_id(a);
  VALUE id_b   = rb_obj_id(b);
  cpSpaceRemoveCollisionHandler(SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b));

  VALUE blocks = rb_iv_get(self, "@blocks");
  rb_hash_delete(blocks, rb_ary_new3(2, id_a, id_b));

  return Qnil;
}

#remove_collision_handlerObject


269
270
271
272
273
274
275
276
277
278
279
# File 'ext/chipmunk/rb_cpSpace.c', line 269

static VALUE
rb_cpSpaceRemoveCollisionHandler(VALUE self, VALUE a, VALUE b) {
  VALUE id_a   = rb_obj_id(a);
  VALUE id_b   = rb_obj_id(b);
  cpSpaceRemoveCollisionHandler(SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b));

  VALUE blocks = rb_iv_get(self, "@blocks");
  rb_hash_delete(blocks, rb_ary_new3(2, id_a, id_b));

  return Qnil;
}

#remove_constraintObject


392
393
394
395
396
397
# File 'ext/chipmunk/rb_cpSpace.c', line 392

static VALUE
rb_cpSpaceRemoveConstraint(VALUE self, VALUE constraint) {
  VALUE ok = rb_ary_delete(rb_iv_get(self, "@constraints"), constraint);
  if(!(NIL_P(ok))) cpSpaceRemoveConstraint(SPACE(self), CONSTRAINT(constraint));
  return ok;
}

#remove_shapeObject


371
372
373
374
375
376
# File 'ext/chipmunk/rb_cpSpace.c', line 371

static VALUE
rb_cpSpaceRemoveShape(VALUE self, VALUE shape) {
  VALUE ok = rb_ary_delete(rb_iv_get(self, "@active_shapes"), shape);
  if(!(NIL_P(ok))) cpSpaceRemoveShape(SPACE(self), SHAPE(shape));
  return ok;
}

#remove_static_shapeObject


378
379
380
381
382
383
# File 'ext/chipmunk/rb_cpSpace.c', line 378

static VALUE
rb_cpSpaceRemoveStaticShape(VALUE self, VALUE shape) {
  VALUE ok = rb_ary_delete(rb_iv_get(self, "@static_shapes"), shape);
  if(!(NIL_P(ok))) cpSpaceRemoveStaticShape(SPACE(self), SHAPE(shape));
  return ok;
}

#resize_active_hashObject

cpSpaceResizeStaticHash(SPACE(self), NUM2DBL(dim), NUM2INT(count)); return Qnil;


409
410
411
412
413
414
415
416
# File 'ext/chipmunk/rb_cpSpace.c', line 409

static VALUE
rb_cpSpaceResizeActiveHash(VALUE self, VALUE dim, VALUE count) {
  rb_raise(rb_eArgError, "resize_active_hash is obsolete");
  return Qnil;
  /* cpSpaceResizeActiveHash(SPACE(self), NUM2DBL(dim), NUM2INT(count));  
  return Qnil;
  */
}

#resize_static_hashObject


399
400
401
402
403
404
405
406
407
# File 'ext/chipmunk/rb_cpSpace.c', line 399

static VALUE
rb_cpSpaceResizeStaticHash(VALUE self, VALUE dim, VALUE count) {
  rb_raise(rb_eArgError, "resize_static_hash is obsolete");
  return Qnil;
  /*
  cpSpaceResizeStaticHash(SPACE(self), NUM2DBL(dim), NUM2INT(count));
  return Qnil;
  */
}

#segment_queryObject


479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'ext/chipmunk/rb_cpSpace.c', line 479

static VALUE
rb_cpSpaceSegmentQuery(int argc, VALUE *argv, VALUE self) {
  VALUE a, b, layers, group, block;
  rb_scan_args(argc, argv, "22&", &a, &b, &layers, &group, &block);

  cpSpaceSegmentQuery(
    SPACE(self), *VGET(a), *VGET(b),
    get_layers(layers), get_group(group),
    (cpSpaceSegmentQueryFunc)segmentQueryCallback, (void *)block
    );

  return Qnil;
}

#segment_query_firstObject


493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'ext/chipmunk/rb_cpSpace.c', line 493

static VALUE
rb_cpSpaceSegmentQueryFirst(int argc, VALUE *argv, VALUE self) {
  VALUE a, b, layers, group, block;
  cpSegmentQueryInfo info = { NULL, 1.0f, cpvzero};

  rb_scan_args(argc, argv, "22&", &a, &b, &layers, &group, &block);

  cpSpaceSegmentQueryFirst(SPACE(self), *VGET(a), *VGET(b),
                           get_layers(layers), get_group(group), &info);
  // contrary to the standard chipmunk bindings, we also return a
  // struct here with then needed values.
  if(info.shape) {
    return rb_cpSegmentQueryInfoNew((VALUE)info.shape->data, rb_float_new(info.t), VNEW(info.n));
  }
  return Qnil;

}

#set_default_collision_funcObject


281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'ext/chipmunk/rb_cpSpace.c', line 281

static VALUE
rb_cpSpaceSetDefaultCollisionHandler(int argc, VALUE *argv, VALUE self) {
  VALUE obj, block;
  rb_scan_args(argc, argv, "01&", &obj, &block);

  if(RTEST(obj) && RTEST(block)) {
    rb_raise(rb_eArgError, "Cannot specify both a handler object and a block.");
  } else if(RTEST(block)) {
    cpSpaceSetDefaultCollisionHandler(
      SPACE(self),
      NULL,
      compatibilityCallback,
      NULL,
      NULL,
      (void *)block
      );

    rb_hash_aset(rb_iv_get(self, "@blocks"), ID2SYM(rb_intern("default")), block);
  } else if(RTEST(obj)) {
    cpSpaceSetDefaultCollisionHandler(
      SPACE(self),
      (respondsTo(obj, id_begin)      ? beginCallback     : NULL),
      (respondsTo(obj, id_pre_solve)  ? preSolveCallback  : NULL),
      (respondsTo(obj, id_post_solve) ? postSolveCallback : NULL),
      (respondsTo(obj, id_separate)   ? separateCallback  : NULL),
      (void *)obj
      );

    rb_hash_aset(rb_iv_get(self, "@blocks"), ID2SYM(rb_intern("default")), obj);
  } else {
    cpSpaceSetDefaultCollisionHandler(
      SPACE(self), NULL, doNothingCallback, NULL, NULL, NULL
      );
  }

  return Qnil;
}

#set_default_collision_handlerObject


281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'ext/chipmunk/rb_cpSpace.c', line 281

static VALUE
rb_cpSpaceSetDefaultCollisionHandler(int argc, VALUE *argv, VALUE self) {
  VALUE obj, block;
  rb_scan_args(argc, argv, "01&", &obj, &block);

  if(RTEST(obj) && RTEST(block)) {
    rb_raise(rb_eArgError, "Cannot specify both a handler object and a block.");
  } else if(RTEST(block)) {
    cpSpaceSetDefaultCollisionHandler(
      SPACE(self),
      NULL,
      compatibilityCallback,
      NULL,
      NULL,
      (void *)block
      );

    rb_hash_aset(rb_iv_get(self, "@blocks"), ID2SYM(rb_intern("default")), block);
  } else if(RTEST(obj)) {
    cpSpaceSetDefaultCollisionHandler(
      SPACE(self),
      (respondsTo(obj, id_begin)      ? beginCallback     : NULL),
      (respondsTo(obj, id_pre_solve)  ? preSolveCallback  : NULL),
      (respondsTo(obj, id_post_solve) ? postSolveCallback : NULL),
      (respondsTo(obj, id_separate)   ? separateCallback  : NULL),
      (void *)obj
      );

    rb_hash_aset(rb_iv_get(self, "@blocks"), ID2SYM(rb_intern("default")), obj);
  } else {
    cpSpaceSetDefaultCollisionHandler(
      SPACE(self), NULL, doNothingCallback, NULL, NULL, NULL
      );
  }

  return Qnil;
}

#shape_point_queryObject


461
462
463
464
465
466
467
468
469
470
471
472
# File 'ext/chipmunk/rb_cpSpace.c', line 461

static VALUE
rb_cpSpacePointQueryFirst(int argc, VALUE *argv, VALUE self) {
  VALUE point, layers, group;
  rb_scan_args(argc, argv, "12", &point, &layers, &group);

  cpShape *shape = cpSpacePointQueryFirst(
    SPACE(self), *VGET(point),
    get_layers(layers), get_group(group)
    );

  return (shape ? (VALUE)shape->data : Qnil);
}

#shape_queryObject

Shape query.


542
543
544
545
546
547
548
549
550
551
552
553
# File 'ext/chipmunk/rb_cpSpace.c', line 542

static VALUE
rb_cpSpaceShapeQuery(int argc, VALUE *argv, VALUE self) {
  VALUE shape, block;
  rb_scan_args(argc, argv, "1&", &shape, &block);

  cpSpaceShapeQuery(
    SPACE(self), SHAPE(shape),
    (cpSpaceShapeQueryFunc)shapeQueryCallback, (void *)block
    );

  return Qnil;
}

#sleep_timeObject


74
75
76
77
# File 'ext/chipmunk/rb_cpSpace.c', line 74

static VALUE
rb_cpSpaceGetSleepTimeThreshold(VALUE self) {
  return INT2NUM(SPACE(self)->sleepTimeThreshold);
}

#sleep_time=Object

also define slghtly less verbose API


79
80
81
82
83
# File 'ext/chipmunk/rb_cpSpace.c', line 79

static VALUE
rb_cpSpaceSetSleepTimeThreshold(VALUE self, VALUE val) {
  SPACE(self)->sleepTimeThreshold = NUM2UINT(val);
  return val;
}

#sleep_time_thresholdObject


74
75
76
77
# File 'ext/chipmunk/rb_cpSpace.c', line 74

static VALUE
rb_cpSpaceGetSleepTimeThreshold(VALUE self) {
  return INT2NUM(SPACE(self)->sleepTimeThreshold);
}

#sleep_time_threshold=Object


79
80
81
82
83
# File 'ext/chipmunk/rb_cpSpace.c', line 79

static VALUE
rb_cpSpaceSetSleepTimeThreshold(VALUE self, VALUE val) {
  SPACE(self)->sleepTimeThreshold = NUM2UINT(val);
  return val;
}

#stepObject


555
556
557
558
559
560
# File 'ext/chipmunk/rb_cpSpace.c', line 555

static VALUE
rb_cpSpaceStep(VALUE self, VALUE dt) {
  cpSpaceStep(SPACE(self), NUM2DBL(dt));
  rb_iv_set(self, "@post_step_blocks", rb_hash_new());
  return Qnil;
}