Collider commands

This commit is contained in:
John Alanbrook 2023-01-17 21:09:14 +00:00
parent 16ad36d4ce
commit 6e794848a4
5 changed files with 32 additions and 31 deletions

View file

@ -468,19 +468,19 @@ void phys2d_dbgdrawedge(struct phys2d_edge *edge)
} }
} }
cpShape *id2shape(int id) void shape_enabled(struct phys2d_shape *shape, int enabled)
{ {
return NULL; YughInfo("Setting shape %p to enabled? %d.", shape, enabled);
if (enabled)
cpSpaceAddShape(space, shape->shape);
else
cpSpaceRemoveShape(space, shape->shape);
} }
void shape_enable(struct phys2d_shape *shape) void shape_set_sensor(struct phys2d_shape *shape, int sensor)
{ {
cpSpaceAddShape(space, shape->shape); YughInfo("Setting shape %p to sensor? %d.", shape, sensor);
} cpShapeSetSensor(shape->shape, sensor);
void shape_disable(struct phys2d_shape *shape)
{
cpSpaceRemoveShape(space, shape->shape);
} }
void phys2d_reindex_body(cpBody *body) { void phys2d_reindex_body(cpBody *body) {

View file

@ -97,10 +97,8 @@ void phys2d_add_handler_type(int cmd, int go, struct callee c);
void register_collide(void *sym); void register_collide(void *sym);
void phys2d_set_gravity(cpVect v); void phys2d_set_gravity(cpVect v);
void shape_enable(struct phys2d_shape *shape); void shape_enabled(struct phys2d_shape *shape, int enabled);
void shape_disable(struct phys2d_shape *shape); void shape_set_sensor(struct phys2d_shape *shape, int sensor);
cpShape *id2shape(int id);
struct color { struct color {
unsigned char r; unsigned char r;

View file

@ -153,30 +153,23 @@ duk_ret_t duk_cmd(duk_context *duk) {
break; break;
case 18: case 18:
cpShapeSetSensor(id2shape(duk_to_int(duk, 1)), duk_to_boolean(duk, 2)); shape_set_sensor(duk_to_pointer(duk, 1), duk_to_boolean(duk, 2));
break; break;
case 19: case 19:
if (id2shape(duk_to_int(duk, 1))) mix_master_vol(duk_to_number(duk, 1));
duk_push_boolean(duk, cpShapeGetSensor(id2shape(duk_to_int(duk, 1)))); break;
else
duk_push_undefined(duk);
return 1;
case 20: case 20:
sprite_enabled(duk_to_int(duk, 1), duk_to_boolean(duk, 2)); sprite_enabled(duk_to_int(duk, 1), duk_to_boolean(duk, 2));
break; break;
case 21: case 21:
duk_push_boolean(duk, id2sprite(duk_to_int(duk, 1))->enabled); break;
return 1;
case 22: case 22:
return 0; shape_enabled(duk_to_pointer(duk, 1), duk_to_int(duk, 2));
break;
case 23:
return 0;
} }
return 0; return 0;
@ -432,7 +425,7 @@ duk_ret_t duk_make_box2d(duk_context *duk) {
phys2d_applybox(box); phys2d_applybox(box);
duk_push_pointer(duk, box); duk_push_pointer(duk, &box->shape);
return 1; return 1;
} }
@ -458,7 +451,9 @@ duk_ret_t duk_make_circle2d(duk_context *duk) {
phys2d_applycircle(circle); phys2d_applycircle(circle);
return 0; duk_push_pointer(duk, &circle->shape);
return 1;
} }
duk_ret_t duk_anim(duk_context *duk) { duk_ret_t duk_anim(duk_context *duk) {
@ -517,7 +512,6 @@ void ffi_load()
DUK_FUNC(make_sprite, 3); DUK_FUNC(make_sprite, 3);
DUK_FUNC(make_anim2d, 4); DUK_FUNC(make_anim2d, 4);
DUK_FUNC(make_box2d, 3); DUK_FUNC(make_box2d, 3);
DUK_FUNC(box2d_cmd, DUK_VARARGS);
DUK_FUNC(make_circle2d, 3); DUK_FUNC(make_circle2d, 3);
DUK_FUNC(cmd, DUK_VARARGS); DUK_FUNC(cmd, DUK_VARARGS);
DUK_FUNC(register, 3); DUK_FUNC(register, 3);

View file

@ -14,6 +14,14 @@ short mastermix[BUF_FRAMES*CHANNELS];
static int initted = 0; static int initted = 0;
static float master_volume = 1.f;
void mix_master_vol(float v) {
if (v < 0.f) v = 0.f;
if (v > 100.f) v = 100.f;
master_volume = v / 100.f;
}
void mixer_init() { void mixer_init() {
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
bus[i].next = i+1; bus[i].next = i+1;
@ -68,7 +76,7 @@ void bus_fill_buffers(short *master, int n) {
int nextbus = bus[curbus].next; /* Save this in case busses get changed during fill */ int nextbus = bus[curbus].next; /* Save this in case busses get changed during fill */
dsp_run(bus[curbus].in, bus[curbus].buf, BUF_FRAMES); dsp_run(bus[curbus].in, bus[curbus].buf, BUF_FRAMES);
for (int i = 0; i < BUF_FRAMES*CHANNELS; i++) for (int i = 0; i < BUF_FRAMES*CHANNELS; i++)
master[i] += bus[curbus].buf[i]; master[i] += bus[curbus].buf[i] * master_volume;
curbus = nextbus; curbus = nextbus;
} }

View file

@ -23,7 +23,8 @@ void mixer_init();
struct bus *first_free_bus(struct dsp_filter in); struct bus *first_free_bus(struct dsp_filter in);
void bus_fill_buffers(short *master, int n); void bus_fill_buffers(short *master, int n);
/* Set volume between 0 and 100% */
void mix_master_vol(float v);
void bus_free(struct bus *bus); void bus_free(struct bus *bus);