diff --git a/source/engine/ffi.c b/source/engine/ffi.c index 6cbcd83..ce6c746 100644 --- a/source/engine/ffi.c +++ b/source/engine/ffi.c @@ -256,7 +256,12 @@ duk_ret_t duk_spline_cmd(duk_context *duk) int d = duk_to_int(duk, 2); cpVect points[n*d]; - ts_bspline_new(n, d, duk_to_int(duk, 1), duk_to_int(duk, 3), &spline, NULL); + tsStatus status; + ts_bspline_new(n, d, duk_to_int(duk, 1), duk_to_int(duk, 3), &spline, &status); + + if (status.code) { + YughCritical("Spline creation error %d: %s", status.code, status.message); + } for (int i = 0; i < n; i++) { duk_get_prop_index(duk, 4, i); @@ -626,6 +631,11 @@ duk_ret_t duk_cmd(duk_context *duk) { case 59: duk_push_int(duk, point2segindex(duk2vec2(duk, 1), duk2cpvec2arr(duk, 2), duk_to_number(duk, 3))); return 1; + + case 60: + if (!id2sprite(duk_to_int(duk, 1))) return 0; + id2sprite(duk_to_int(duk, 1))->layer = duk_to_int(duk, 2); + break; } return 0; @@ -852,7 +862,7 @@ duk_ret_t duk_make_sprite(duk_context *duk) { sp->pos[0] = pos.x; sp->pos[1] = pos.y; - duk_push_int(duk, sprite); + duk_push_int(duk, sprite); return 1; } diff --git a/source/engine/input.c b/source/engine/input.c index 68ab954..524886a 100644 --- a/source/engine/input.c +++ b/source/engine/input.c @@ -55,7 +55,7 @@ static void cursor_pos_cb(GLFWwindow *w, double xpos, double ypos) mouse_pos.y = ypos; for (int i = 0; i < arrlen(pawns); i++) { - if (script_eval_setup("input_mouse_pos", pawns[i])) continue; + if (!pawns[i] || script_eval_setup("input_mouse_pos", pawns[i])) continue; vect2duk(duk, mouse_pos); script_eval_exec(1); } @@ -119,7 +119,8 @@ void call_input_signal(char *signal) { } for (int i = 0; i < arrlen(pawns); i++) { - script_eval_w_env(signal, pawns[i]); + if (!pawns[i]) continue; + script_eval_w_env(signal, pawns[i]); } } @@ -215,6 +216,17 @@ const char *keyname_extd(int key, int scancode) { case GLFW_KEY_KP_SUBTRACT: kkey = "minus"; break; + case GLFW_KEY_GRAVE_ACCENT: + kkey = "backtick"; + break; + + case GLFW_KEY_LEFT_BRACKET: + kkey = "lbracket"; + break; + + case GLFW_KEY_RIGHT_BRACKET: + kkey = "rbracket"; + break; } if (kkey) return kkey; @@ -257,6 +269,7 @@ void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods case GLFW_PRESS: snprintf(keystr, 50, "input_%s_pressed", kkey); add_downkey(key); + call_input_signal("input_any_pressed"); break; case GLFW_RELEASE: diff --git a/source/engine/sprite.c b/source/engine/sprite.c index 8a54e6d..4c9762e 100644 --- a/source/engine/sprite.c +++ b/source/engine/sprite.c @@ -27,6 +27,7 @@ int make_sprite(int go) .tex = texture_loadfromfile("ph.png"), .go = go, .next = -1, + .layer = 0, .enabled = 1 }; int ret; @@ -81,13 +82,20 @@ void sprite_io(struct sprite *sprite, FILE *f, int read) } } - - void sprite_draw_all() { + static struct sprite **layers[5]; + + for (int i = 0; i < 5; i++) + arrfree(layers[i]); + for (int i = 0; i < arrlen(sprites); i++) { - if (sprites[i].go >= 0 && sprites[i].enabled) sprite_draw(&sprites[i]); + if (sprites[i].go >= 0 && sprites[i].enabled) arrpush(layers[sprites[i].layer], &sprites[i]); } + + for (int i = 4; i >= 0; i--) + for (int j = 0; j < arrlen(layers[i]); j++) + sprite_draw(layers[i][j]); } void sprite_loadtex(struct sprite *sprite, const char *path) diff --git a/source/engine/sprite.h b/source/engine/sprite.h index bd7e372..0214677 100644 --- a/source/engine/sprite.h +++ b/source/engine/sprite.h @@ -20,6 +20,7 @@ struct sprite { struct glrect *frame; int next; int enabled; + int layer; }; int make_sprite(int go);