diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2023-08-02 14:17:17 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2023-08-14 10:11:29 +0000 |
| commit | 378f91b70c54cc111684f4a3a8f2b868af570fd8 (patch) | |
| tree | a16b67413892f3d3ee514ab30446fc87142c7566 /include | |
| parent | 1ec17aeb185ec7851a41c0ba2ae14c95a1a3942e (diff) | |
Add reloading of state-specific keybindings bindings
Diffstat (limited to 'include')
| -rw-r--r-- | include/engine/engine.h | 1 | ||||
| -rw-r--r-- | include/engine/input.h | 30 | ||||
| -rw-r--r-- | include/engine/state.h | 9 |
3 files changed, 33 insertions, 7 deletions
diff --git a/include/engine/engine.h b/include/engine/engine.h index cf2283f..d3c3e87 100644 --- a/include/engine/engine.h +++ b/include/engine/engine.h @@ -84,6 +84,7 @@ void engine_stop(Platform *p); void engine_fps_max(u64 cap); void engine_input_ctx_push(i_ctx *ctx); void engine_input_ctx_pop(void); +void engine_input_ctx_reset(void); void render_set_zoom(f32 new_zoom); void render_adjust_zoom(f32 diff); diff --git a/include/engine/input.h b/include/engine/input.h index d200e62..918312e 100644 --- a/include/engine/input.h +++ b/include/engine/input.h @@ -48,7 +48,7 @@ typedef struct i_ctx { } i_ctx; void i_flush_bindings(usize numcalls, void* state_mem, input_callback_t* c[]); -action_t i_get_action(const i_ctx *ctx, u32 time, scancode_t scancode); +action_t i_get_action(const i_ctx *restrict ctx, u32 time, scancode_t scancode); #define BindAction(key, altkey, f_action) \ (binding_t){\ @@ -76,4 +76,32 @@ action_t i_get_action(const i_ctx *ctx, u32 time, scancode_t scancode); .since_last_activation = 0\ } +// Lazy binds, used internally +#define BindActionLazy(key, altkey, action_str) \ + (binding_t){\ + .action = (action_t){.action = {\ + .type = InputType_action,\ + .callback = NULL,\ + .callback_str = action_str,\ + }},\ + .scancode = key,\ + .scancode_alt = altkey,\ + .since_last_activation = 0\ +} + +#define BindStateLazy(key, altkey, _activate_str , _deactivate_str) \ + (binding_t){\ + .action = (action_t){.state = {\ + .type = InputType_state,\ + .activate = NULL,\ + .deactivate = NULL,\ + .activate_str = _activate_str,\ + .deactivate_str = _deactivate_str,\ + }},\ + .scancode = key,\ + .scancode_alt = altkey,\ + .since_last_activation = 0\ +} + + #endif diff --git a/include/engine/state.h b/include/engine/state.h index 68228b1..9c832f5 100644 --- a/include/engine/state.h +++ b/include/engine/state.h @@ -22,14 +22,11 @@ StateType State_update(StateType type, memory *mem); /* Reloads shared object file associated with state */ #ifdef DAW_BUILD_HOTRELOAD -bool State_reload(StateType type); - -#define get_statelib_var(type) libstate_##name -#define State_load_binding(type, function_name) dynamic_library_get_symbol(get_statelib_var(type), #function_name) +#include <engine/input.h> +bool State_reload(StateType type, i_ctx **ctx, usize ctx_len); #else -#define State_reload(_) true -#define State_load_binding(_, __) true +#define State_reload(_, _0, _1) true #endif #endif |
