diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index 5988e57..9262c53 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -368,6 +368,8 @@ void phys2d_applycircle(struct phys2d_circle *circle) float s = go->scale; cpVect offset = { circle->offset[0] * s, circle->offset[1] * s }; + YughInfo("Setting radius to %g ...", radius); + cpCircleShapeSetRadius(circle->shape.shape, radius); cpCircleShapeSetOffset(circle->shape.shape, offset); cpBodySetMoment(go->body, cpMomentForCircle(go->mass, 0, radius, offset)); diff --git a/source/engine/ffi.c b/source/engine/ffi.c index c4f8e4e..261b844 100644 --- a/source/engine/ffi.c +++ b/source/engine/ffi.c @@ -63,6 +63,34 @@ duk_ret_t duk_gui_img(duk_context *duk) { return 0; } +duk_ret_t duk_nuke(duk_context *duk) +{ + int cmd = duk_to_int(duk, 0); + float editnum; + + switch(cmd) { + case 0: + nuke_begin_win(duk_to_string(duk, 1)); + break; + + case 1: + nuke_stop(); + break; + + case 2: + editnum = duk_to_number(duk, 2); + nuke_property_float(duk_to_string(duk, 1), 0.f, &editnum, 100.f, 0.01f, 0.01f); + duk_push_number(duk, editnum); + return 1; + + case 3: + nuke_nel(duk_to_number(duk, 1)); + return 0; + } + + return 0; +} + duk_ret_t duk_win_make(duk_context *duk) { const char *title = duk_to_string(duk, 0); int w = duk_to_int(duk, 1); @@ -246,6 +274,10 @@ duk_ret_t duk_register(duk_context *duk) { case 2: register_gui(c); break; + + case 3: + register_nk_gui(c); + break; } return 0; @@ -504,6 +536,20 @@ duk_ret_t duk_make_circle2d(duk_context *duk) { duk_ret_t duk_cmd_circle2d(duk_context *duk) { + int cmd = duk_to_int(duk, 0); + struct phys2d_circle *circle = duk_to_pointer(duk, 1); + + YughInfo("DOING CIRCLE CMD"); + + switch(cmd) { + case 0: + circle->radius = duk_to_number(duk, 2); + phys2d_applycircle(circle); + return 0; + + } + + return 0; } @@ -553,6 +599,7 @@ duk_ret_t duk_make_timer(duk_context *duk) { void ffi_load() { DUK_FUNC(yughlog, 4); + DUK_FUNC(nuke, DUK_VARARGS); DUK_FUNC(make_gameobject, 7); DUK_FUNC(set_body, 3); DUK_FUNC(q_body, 2); diff --git a/source/engine/nuke.c b/source/engine/nuke.c index ce6a483..d28c10e 100644 --- a/source/engine/nuke.c +++ b/source/engine/nuke.c @@ -10,7 +10,6 @@ #define NK_GLFW_GL3_IMPLEMENTATION #define NK_KEYSTATE_BASED_INPUT - #include "nuke.h" #include "nuklear_glfw_gl3.h" @@ -33,7 +32,7 @@ void nuke_init(struct window *win) { struct nk_font_atlas *atlas; nk_glfw3_font_stash_begin(&nkglfw, &atlas); - struct nk_font *noto = nk_font_atlas_add_from_file(atlas, "fonts/notosans.tff", 14, 0); + struct nk_font *noto = nk_font_atlas_add_from_file(atlas, "fonts/teenytinypixels.tff", 14, 0); nk_glfw3_font_stash_end(&nkglfw); } @@ -51,6 +50,12 @@ void nuke_end() int nuke_begin(const char *lbl, struct nk_rect rect, int flags) { return nk_begin(ctx, lbl, rect, flags); } + +int nuke_begin_win(const char *lbl) +{ + return nk_begin(ctx, lbl, nk_rect(10, 10, 400, 600), NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE | NK_WINDOW_TITLE); +} + void nuke_stop() { nk_end(ctx); } diff --git a/source/engine/nuke.h b/source/engine/nuke.h index 7156559..e241d70 100644 --- a/source/engine/nuke.h +++ b/source/engine/nuke.h @@ -10,6 +10,7 @@ void nuke_start(); void nuke_end(); int nuke_begin(const char *lbl, struct nk_rect rect, int flags); +int nuke_begin_win(const char *lbl); void nuke_stop(); struct nk_rect nuke_win_get_bounds(); diff --git a/source/engine/openglrender.c b/source/engine/openglrender.c index effebd0..3eae7fb 100644 --- a/source/engine/openglrender.c +++ b/source/engine/openglrender.c @@ -162,7 +162,12 @@ void openglRender(struct window *window) ////// TEXT && GUI glBindBuffer(GL_UNIFORM_BUFFER, projUBO); glBufferSubData(GL_UNIFORM_BUFFER, 0, 64, ui_projection); + call_gui(); + + nuke_start(); + call_nk_gui(); + nuke_end(); } void BindUniformBlock(GLuint shaderID, const char *bufferName, GLuint bufferBind) diff --git a/source/engine/script.c b/source/engine/script.c index fd303af..dd9336f 100644 --- a/source/engine/script.c +++ b/source/engine/script.c @@ -143,6 +143,7 @@ void script_call_sym_args(void *sym, void *args) struct callee *updates = NULL; struct callee *physics = NULL; struct callee *guis = NULL; +struct callee *nk_guis = NULL; void register_update(struct callee c) { arrput(updates, c); @@ -152,6 +153,8 @@ void register_gui(struct callee c) { arrput(guis, c); } +void register_nk_gui(struct callee c) { arrput(nk_guis, c); } + void register_physics(struct callee c) { arrput(physics, c); } @@ -188,6 +191,11 @@ void call_gui() { call_callee(&guis[i]); } +void call_nk_gui() { + for (int i = 0; i < arrlen(nk_guis); i++) + call_callee(&nk_guis[i]); +} + void call_physics(double dt) { for (int i = 0; i < arrlen(physics); i++) { callee_dbl(updates[i], dt); diff --git a/source/engine/script.h b/source/engine/script.h index 7fff712..ac5f13f 100644 --- a/source/engine/script.h +++ b/source/engine/script.h @@ -30,7 +30,9 @@ void register_update(struct callee c); void call_updates(double dt); void register_gui(struct callee c); +void register_nk_gui(struct callee c); void call_gui(); +void call_nk_gui(); void register_physics(struct callee c); void call_physics(double dt); diff --git a/source/engine/window.c b/source/engine/window.c index 1189adc..37d840e 100644 --- a/source/engine/window.c +++ b/source/engine/window.c @@ -275,15 +275,6 @@ int window_hasfocus(struct window *w) void window_render(struct window *w) { window_makecurrent(w); openglRender(w); - - - if (w->nuke_gui != NULL) { - nuke_start(); - w->nuke_gui(); - nuke_end(); - } - - window_swap(w); }