diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2024-02-18 10:40:21 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2024-02-18 10:43:41 +0000 |
| commit | 0cff8325ded7d6235e84496418e6a594613b230b (patch) | |
| tree | bd35186759570a00cc829d3a5ad4556cf6fcdfa4 /src/core | |
| parent | d11abae4b6560b6574a84f41d7a34156204cdc5b (diff) | |
More reorganization
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/include/engine/engine.h | 6 | ||||
| -rw-r--r-- | src/core/src/loop.c | 62 |
2 files changed, 1 insertions, 67 deletions
diff --git a/src/core/include/engine/engine.h b/src/core/include/engine/engine.h index b4749f7..e15be11 100644 --- a/src/core/include/engine/engine.h +++ b/src/core/include/engine/engine.h @@ -45,12 +45,6 @@ void render_set_zoom(f32 new_zoom); void render_adjust_zoom(f32 diff); void render_add_unit(RenderUnit* u); -/* Input handling */ -void engine_input_ctx_push(i_ctx* ctx); -void engine_input_ctx_pop(void); -void engine_input_ctx_reset(void); -void get_mousepos(double *x, double *y); - /* move this */ void delay(uint32_t ms); diff --git a/src/core/src/loop.c b/src/core/src/loop.c index fd6c4e7..2657e9f 100644 --- a/src/core/src/loop.c +++ b/src/core/src/loop.c @@ -372,7 +372,7 @@ i32 engine_run(Platform* p, StateType initial_state, void* state_arg) { void* retval = State_free(state, mem); memory_clear(mem); - engine_input_ctx_reset(); + i_ctx_reset(); // Reset camera to default camera p->cam = &default_camera; @@ -425,63 +425,3 @@ void engine_stop(Platform* p) { /* Set the maximum framerate */ void engine_fps_max(u64 cap) { /* does nothing */ } - -/* Pushes an input context onto the input handling stack */ -void engine_input_ctx_push(i_ctx* ctx) { - if (GLOBAL_PLATFORM->bindings == NULL) { - GLOBAL_PLATFORM->bindings = calloc(8, sizeof(i_ctx*)); - GLOBAL_PLATFORM->bindings_sz = 8; - } - - if (GLOBAL_PLATFORM->bindings_len + 1 >= GLOBAL_PLATFORM->bindings_sz) { - void* m = - realloc(GLOBAL_PLATFORM->bindings, GLOBAL_PLATFORM->bindings_sz + 8); - if (m == NULL) { - ERROR("Failed to allocate 8 bytes (%d): %s", errno, strerror(errno)); - exit(EXIT_FAILURE); - } - GLOBAL_PLATFORM->bindings_sz += 8; - } - - LOG("Bindings in ctx[%d]:", GLOBAL_PLATFORM->bindings_len); - for (isize i = 0; i < ctx->len; i++) { - switch (ctx->bindings[i].action.type) { - case InputType_error: - LOG("(error)"); - break; - - case InputType_action: - LOG("(action) %s", ctx->bindings[i].action.action.callback_str); - break; - - case InputType_state: - LOG("(+state) %s", ctx->bindings[i].action.state.activate_str); - LOG("(-state) %s", ctx->bindings[i].action.state.deactivate_str); - break; - - case InputType_range: - LOG("(range) --unhandled--"); - break; - } - } - - GLOBAL_PLATFORM->bindings[GLOBAL_PLATFORM->bindings_len++] = ctx; -} - -/* Pops an input context from the input stack */ -void engine_input_ctx_pop(void) { - if (GLOBAL_PLATFORM->bindings == NULL || GLOBAL_PLATFORM->bindings_sz == 0) - return; - i_ctx_t_free(GLOBAL_PLATFORM->bindings[--GLOBAL_PLATFORM->bindings_len]); -} - -/* Removes all input contexts from the input stack */ -void engine_input_ctx_reset(void) { - while (GLOBAL_PLATFORM->bindings_len > 0) { - i_ctx_t_free(GLOBAL_PLATFORM->bindings[--GLOBAL_PLATFORM->bindings_len]); - } -} - -void get_mousepos(double *x, double *y) { - glfwGetCursorPos(GLOBAL_PLATFORM->window->window, x, y); -} |
