diff options
| -rw-r--r-- | src/core/include/engine/core/state.h | 3 | ||||
| -rw-r--r-- | src/core/src/state.c | 70 | ||||
| -rw-r--r-- | src/ctrl/src/input.c | 68 |
3 files changed, 73 insertions, 68 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 diff --git a/src/ctrl/src/input.c b/src/ctrl/src/input.c index 2fd025e..3b6a4df 100644 --- a/src/ctrl/src/input.c +++ b/src/ctrl/src/input.c @@ -156,74 +156,6 @@ action_t i_get_action(const i_ctx* restrict ctx, u32 time, return (action_t){.type = InputType_error}; } -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; -} - /* Make a lazy duplication of a binding. See comments on BindActionLazy and * friends above. */ i_ctx* i_ctx_dup(i_ctx** ctx, usize ctx_len) { |
