diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2024-02-06 17:54:34 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2024-02-06 18:02:11 +0000 |
| commit | 7ba1a5ce817e5f57862eccd63e2bfff906172d32 (patch) | |
| tree | 1891d5b2dd748a4d7e78c23d364861b1ce6cb93c /src/core | |
| parent | 239a7ade7304ea8a1262d1f3853f6dfc671fb5b4 (diff) | |
Move refresh_input_ctx
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/include/engine/core/state.h | 3 | ||||
| -rw-r--r-- | src/core/src/state.c | 70 |
2 files changed, 73 insertions, 0 deletions
diff --git a/src/core/include/engine/core/state.h b/src/core/include/engine/core/state.h index cdba235..a4c56fa 100644 --- a/src/core/include/engine/core/state.h +++ b/src/core/include/engine/core/state.h @@ -23,9 +23,12 @@ StateType State_update(StateType type, memory* mem); #ifdef DAW_BUILD_HOTRELOAD #include <engine/ctrl/input.h> bool State_reload(StateType type, i_ctx** ctx, usize ctx_len); +bool state_refresh_input_ctx(void* lib, i_ctx** ctx, usize ctx_len); #else #define State_reload(_, _0, _1) true +#define state_refresh_input_ctx(_0, _1, _2) true + #endif #endif diff --git a/src/core/src/state.c b/src/core/src/state.c index a2af5e1..b66c565 100644 --- a/src/core/src/state.c +++ b/src/core/src/state.c @@ -175,4 +175,74 @@ bool State_reload(StateType type, i_ctx** ctx, usize ctx_len) { } return state_refresh_input_ctx(libptr, ctx, ctx_len); } + + +bool state_refresh_input_ctx(void* lib, i_ctx** ctx, usize ctx_len) { + if (ctx == NULL) return true; + if (ctx_len > 0 && ctx[0] == NULL) return false; + if (lib == NULL) return false; + + for (usize c = 0; c < ctx_len; c++) { + LOG("ctx[%d]->len = %d", c, ctx[c]->len); + for (isize b = 0; b < ctx[c]->len; b++) { + switch (ctx[c]->bindings[b].action.type) { + case InputType_error: + break; + case InputType_action: + if (strcmp("NULL", ctx[c]->bindings[b].action.action.callback_str) != + 0) { + + ctx[c]->bindings[b].action.action.callback = + (input_callback_t*)dynamic_library_get_symbol( + lib, ctx[c]->bindings[b].action.action.callback_str); + + if (ctx[c]->bindings[b].action.action.callback == NULL) { + ERROR("Failed to get binding for %s: %s", + ctx[c]->bindings[b].action.action.callback_str, + dynamic_library_get_error()); + return false; + } + } + break; + case InputType_state: + if (strcmp("NULL", ctx[c]->bindings[b].action.state.activate_str) != + 0) { + + ctx[c]->bindings[b].action.state.activate = + (input_callback_t*)dynamic_library_get_symbol( + lib, ctx[c]->bindings[b].action.state.activate_str); + + if (ctx[c]->bindings[b].action.state.activate == NULL) { + ERROR("Failed to get binding for %s: %s", + ctx[c]->bindings[b].action.state.activate_str, + dynamic_library_get_error()); + return false; + } + } + + if (strcmp("NULL", ctx[c]->bindings[b].action.state.deactivate_str) != + 0) { + + ctx[c]->bindings[b].action.state.deactivate = + (input_callback_t*)dynamic_library_get_symbol( + lib, ctx[c]->bindings[b].action.state.deactivate_str); + + if (ctx[c]->bindings[b].action.state.deactivate == NULL) { + ERROR("Failed to get binding for %s: %s", + ctx[c]->bindings[b].action.state.deactivate_str, + dynamic_library_get_error()); + return false; + } + } + break; + case InputType_range: + default: + break; + } + } + } + + return true; +} + #endif |
