java
This commit is contained in:
parent
3e4edf1ea3
commit
3baec775a8
|
@ -23,12 +23,13 @@ float phys2d_gravity = -50.f;
|
||||||
void phys2d_init()
|
void phys2d_init()
|
||||||
{
|
{
|
||||||
space = cpSpaceNew();
|
space = cpSpaceNew();
|
||||||
phys2d_set_gravity(0, phys2d_gravity);
|
cpVect grav = {0, phys2d_gravity};
|
||||||
|
phys2d_set_gravity(grav);
|
||||||
cpSpaceSetGravity(space, cpv(0, phys2d_gravity));
|
cpSpaceSetGravity(space, cpv(0, phys2d_gravity));
|
||||||
}
|
}
|
||||||
|
|
||||||
void phys2d_set_gravity(float x, float y) {
|
void phys2d_set_gravity(cpVect v) {
|
||||||
cpSpaceSetGravity(space, cpv(x, y));
|
cpSpaceSetGravity(space, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void phys2d_update(float deltaT)
|
void phys2d_update(float deltaT)
|
||||||
|
@ -36,11 +37,6 @@ void phys2d_update(float deltaT)
|
||||||
cpSpaceStep(space, deltaT);
|
cpSpaceStep(space, deltaT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void phys2d_apply()
|
|
||||||
{
|
|
||||||
phys2d_set_gravity(0, phys2d_gravity);
|
|
||||||
}
|
|
||||||
|
|
||||||
void phys2d_shape_apply(struct phys2d_shape *shape)
|
void phys2d_shape_apply(struct phys2d_shape *shape)
|
||||||
{
|
{
|
||||||
cpShapeSetFriction(shape->shape, shape->go->f);
|
cpShapeSetFriction(shape->shape, shape->go->f);
|
||||||
|
|
|
@ -97,10 +97,9 @@ void edge_gui(struct phys2d_edge *edge);
|
||||||
|
|
||||||
void phys2d_init();
|
void phys2d_init();
|
||||||
void phys2d_update(float deltaT);
|
void phys2d_update(float deltaT);
|
||||||
void phys2d_apply();
|
|
||||||
|
|
||||||
void phys2d_add_handler_type(int cmd, struct gameobject *go, void *cb);
|
void phys2d_add_handler_type(int cmd, struct gameobject *go, void *cb);
|
||||||
void phys2d_set_gravity(float x, float y);
|
void phys2d_set_gravity(cpVect v);
|
||||||
|
|
||||||
void shape_gui(struct phys2d_shape *shape);
|
void shape_gui(struct phys2d_shape *shape);
|
||||||
|
|
||||||
|
|
|
@ -557,7 +557,7 @@ void editor_project_gui() {
|
||||||
|
|
||||||
if (nuke_push_tree_id("Physics", 0)) {
|
if (nuke_push_tree_id("Physics", 0)) {
|
||||||
nuke_prop_float("2d Gravity", -5000.f, &phys2d_gravity, 0.f, 1.f, 0.1f);
|
nuke_prop_float("2d Gravity", -5000.f, &phys2d_gravity, 0.f, 1.f, 0.1f);
|
||||||
phys2d_apply();
|
//phys2d_apply();
|
||||||
nk_tree_pop(ctx);
|
nk_tree_pop(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,13 @@ duk_ret_t duk_gui_text(duk_context *duk) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duk_ret_t duk_gui_img(duk_context *duk) {
|
||||||
|
const char *img = duk_to_string(duk, 0);
|
||||||
|
cpVect pos = duk2vec2(duk, 1);
|
||||||
|
gui_draw_img(img, pos.x, pos.y);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
duk_ret_t duk_win_make(duk_context *duk) {
|
duk_ret_t duk_win_make(duk_context *duk) {
|
||||||
const char *title = duk_to_string(duk, 0);
|
const char *title = duk_to_string(duk, 0);
|
||||||
int w = duk_to_int(duk, 1);
|
int w = duk_to_int(duk, 1);
|
||||||
|
@ -65,6 +72,31 @@ duk_ret_t duk_cmd(duk_context *duk) {
|
||||||
case 2:
|
case 2:
|
||||||
register_gui(duk_get_heapptr(duk, 1));
|
register_gui(duk_get_heapptr(duk, 1));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
set_timescale(duk_get_number(duk,1));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
debug_draw_phys(duk_get_boolean(duk, 1));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
renderMS = duk_get_number(duk, 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
updateMS = duk_get_number(duk, 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 7:
|
||||||
|
physMS = duk_get_number(duk, 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
phys2d_set_gravity(duk2vec2(duk, 1));
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -231,6 +263,75 @@ duk_ret_t duk_q_body(duk_context *duk) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duk_ret_t duk_make_box2d(duk_context *duk) {
|
||||||
|
int go = duk_to_int(duk, 0);
|
||||||
|
cpVect size = duk2vec2(duk, 1);
|
||||||
|
cpVect offset = duk2vec2(duk, 2);
|
||||||
|
|
||||||
|
struct phys2d_box *box = Make2DBox(get_gameobject_from_id(go));
|
||||||
|
box->w = size.x;
|
||||||
|
box->h = size.y;
|
||||||
|
box->offset[0] = offset.x;
|
||||||
|
box->offset[1] = offset.y;
|
||||||
|
phys2d_boxinit(box, get_gameobject_from_id(go));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
duk_ret_t duk_make_circle2d(duk_context *duk) {
|
||||||
|
int go = duk_to_int(duk, 0);
|
||||||
|
double radius = duk2vec2(duk, 1);
|
||||||
|
cpVect offset = duk2vec2(duk, 2);
|
||||||
|
|
||||||
|
struct phys2d_circle *circle = Make2DCircle(get_gameobject_from_id(go));
|
||||||
|
circle->radius = radius;
|
||||||
|
circle->offset[0] = offset.x;
|
||||||
|
circle->offset[1] = offset.y;
|
||||||
|
|
||||||
|
phys2d_circleinit(circle, get_gameobject_from_id(go));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
duk_ret_t duk_anim(duk_context *duk) {
|
||||||
|
void *prop = duk_get_heapptr(duk, 0);
|
||||||
|
int keyframes = duk_get_length(duk, 1);
|
||||||
|
YughInfo("Processing %d keyframes.", keyframes);
|
||||||
|
|
||||||
|
struct anim a = make_anim();
|
||||||
|
|
||||||
|
for (int i = 0; i < keyframes; i++) {
|
||||||
|
struct keyframe k;
|
||||||
|
duk_get_prop_index(duk, 1, i); /* End of stack is now the keyframe */
|
||||||
|
cpVect v = duk2vec2(duk, duk_get_top_index(duk));
|
||||||
|
k.time = v.y;
|
||||||
|
k.val = v.x;
|
||||||
|
a = anim_add_keyframe(a, k);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (double i = 0; i < 3.0; i = i + 0.1) {
|
||||||
|
YughInfo("Val is now %f at time %f", anim_val(a, i), i);
|
||||||
|
duk_push_heapptr(duk, prop);
|
||||||
|
duk_push_number(duk, anim_val(a, i));
|
||||||
|
duk_call(duk, 1);
|
||||||
|
duk_pop(duk);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
duk_ret_t duk_anim_cmd(duk_context *duk) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
duk_ret_t duk_timer(duk_context *duk) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
duk_ret_t duk_timer_cmd(duk_context *duk) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#define DUK_FUNC(NAME, ARGS) duk_push_c_function(duk, duk_##NAME, ARGS); duk_put_global_string(duk, #NAME);
|
#define DUK_FUNC(NAME, ARGS) duk_push_c_function(duk, duk_##NAME, ARGS); duk_put_global_string(duk, #NAME);
|
||||||
|
|
||||||
void ffi_load()
|
void ffi_load()
|
||||||
|
@ -242,7 +343,18 @@ void ffi_load()
|
||||||
DUK_FUNC(register, 3);
|
DUK_FUNC(register, 3);
|
||||||
DUK_FUNC(sys_cmd, 1);
|
DUK_FUNC(sys_cmd, 1);
|
||||||
DUK_FUNC(win_make, 3);
|
DUK_FUNC(win_make, 3);
|
||||||
DUK_FUNC(gui_text, 3);
|
|
||||||
DUK_FUNC(make_sprite, 3);
|
DUK_FUNC(make_sprite, 3);
|
||||||
|
DUK_FUNC(make_box2d, 3);
|
||||||
|
DUK_FUNC(make_circle2d, 3);
|
||||||
DUK_FUNC(cmd, 2);
|
DUK_FUNC(cmd, 2);
|
||||||
|
|
||||||
|
DUK_FUNC(gui_text, 3);
|
||||||
|
DUK_FUNC(gui_img, 2);
|
||||||
|
|
||||||
|
DUK_FUNC(timer, 2);
|
||||||
|
DUK_FUNC(timer_cmd, 2);
|
||||||
|
|
||||||
|
DUK_FUNC(anim, 2);
|
||||||
|
DUK_FUNC(anim_cmd, 3);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue