sprite layers

This commit is contained in:
John Alanbrook 2023-02-10 20:31:59 +00:00
parent 1fcdae17ba
commit 8155bddb5e
4 changed files with 39 additions and 7 deletions

View file

@ -256,7 +256,12 @@ duk_ret_t duk_spline_cmd(duk_context *duk)
int d = duk_to_int(duk, 2); int d = duk_to_int(duk, 2);
cpVect points[n*d]; 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++) { for (int i = 0; i < n; i++) {
duk_get_prop_index(duk, 4, i); duk_get_prop_index(duk, 4, i);
@ -626,6 +631,11 @@ duk_ret_t duk_cmd(duk_context *duk) {
case 59: case 59:
duk_push_int(duk, point2segindex(duk2vec2(duk, 1), duk2cpvec2arr(duk, 2), duk_to_number(duk, 3))); duk_push_int(duk, point2segindex(duk2vec2(duk, 1), duk2cpvec2arr(duk, 2), duk_to_number(duk, 3)));
return 1; 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; return 0;

View file

@ -55,7 +55,7 @@ static void cursor_pos_cb(GLFWwindow *w, double xpos, double ypos)
mouse_pos.y = ypos; mouse_pos.y = ypos;
for (int i = 0; i < arrlen(pawns); i++) { 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); vect2duk(duk, mouse_pos);
script_eval_exec(1); script_eval_exec(1);
} }
@ -119,6 +119,7 @@ void call_input_signal(char *signal) {
} }
for (int i = 0; i < arrlen(pawns); i++) { for (int i = 0; i < arrlen(pawns); i++) {
if (!pawns[i]) continue;
script_eval_w_env(signal, pawns[i]); script_eval_w_env(signal, pawns[i]);
} }
} }
@ -215,6 +216,17 @@ const char *keyname_extd(int key, int scancode) {
case GLFW_KEY_KP_SUBTRACT: case GLFW_KEY_KP_SUBTRACT:
kkey = "minus"; kkey = "minus";
break; 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; 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: case GLFW_PRESS:
snprintf(keystr, 50, "input_%s_pressed", kkey); snprintf(keystr, 50, "input_%s_pressed", kkey);
add_downkey(key); add_downkey(key);
call_input_signal("input_any_pressed");
break; break;
case GLFW_RELEASE: case GLFW_RELEASE:

View file

@ -27,6 +27,7 @@ int make_sprite(int go)
.tex = texture_loadfromfile("ph.png"), .tex = texture_loadfromfile("ph.png"),
.go = go, .go = go,
.next = -1, .next = -1,
.layer = 0,
.enabled = 1 }; .enabled = 1 };
int ret; int ret;
@ -81,13 +82,20 @@ void sprite_io(struct sprite *sprite, FILE *f, int read)
} }
} }
void sprite_draw_all() 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++) { 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) void sprite_loadtex(struct sprite *sprite, const char *path)

View file

@ -20,6 +20,7 @@ struct sprite {
struct glrect *frame; struct glrect *frame;
int next; int next;
int enabled; int enabled;
int layer;
}; };
int make_sprite(int go); int make_sprite(int go);