summaryrefslogtreecommitdiff
path: root/src/state.c
diff options
context:
space:
mode:
author0scar <qgt268@alumni.ku.dk>2023-08-15 07:10:08 +0000
committer0scar <qgt268@alumni.ku.dk>2023-08-15 07:10:08 +0000
commit479b155fa1624ccbb3df19d827088c4093b5b6a4 (patch)
tree8c359954ae7fb87ca5181c903040d8dd2296c574 /src/state.c
parent4abb242204e117edfec86a24bbecc689ace6a9a7 (diff)
Move input stuffs into input.{h,c}
Diffstat (limited to 'src/state.c')
-rw-r--r--src/state.c140
1 files changed, 0 insertions, 140 deletions
diff --git a/src/state.c b/src/state.c
index 47752bc..f963c4e 100644
--- a/src/state.c
+++ b/src/state.c
@@ -137,116 +137,9 @@ StateType State_update(StateType type, memory *mem) {
return next_state;
}
-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;
-}
-
-/* IMPLEMENT CPY(dst,src) FOR THE SAME TYPE, SO WE CAN OVERRIDE THE OLD ONE AND
- * FREE UP `ret->bindings` AND `ret` */
-i_ctx* i_ctx_dup(i_ctx **ctx, usize ctx_len) {
- usize num_binds = 0;
- for (usize c = 0; c < ctx_len; c++) {
- num_binds += ctx[c]->len;
- }
-
- binding_t *bb = calloc(num_binds, sizeof(binding_t));
- i_ctx *ret = calloc(ctx_len, sizeof(i_ctx));
-
- usize cumsum = 0;
- for (usize c = 0; c < ctx_len; c++) {
- binding_t *b = ctx[c]->bindings;
- ret[c].len = ctx[c]->len;
- ret[c].bindings = &bb[cumsum];
-
- for (isize i = 0; i < ctx[c]->len; i++) {
- switch (b[i].action.type) {
- case InputType_error:
- break;
- case InputType_action:
- bb[cumsum] = BindActionLazy(
- b[i].scancode,
- b[i].scancode_alt,
- strdup(b[i].action.action.callback_str));
- break;
- case InputType_state:
- bb[cumsum] = BindStateLazy(
- b[i].scancode,
- b[i].scancode_alt,
- strdup(b[i].action.state.activate_str),
- strdup(b[i].action.state.deactivate_str));
- break;
- case InputType_range:
- default:
- break;
- }
- cumsum++;
- }
- }
- return ret;
-}
-
#ifdef DAW_BUILD_HOTRELOAD
bool State_reload(StateType type, i_ctx **ctx, usize ctx_len) {
void* libptr = NULL;
- //i_ctx* ctx_cpy = i_ctx_dup(ctx, ctx_len);
switch (type) {
#define State(name) \
@@ -281,38 +174,5 @@ bool State_reload(StateType type, i_ctx **ctx, usize ctx_len) {
exit(EXIT_FAILURE);
}
return state_refresh_input_ctx(libptr, ctx, ctx_len);
- //state_refresh_input_ctx(libptr, &ctx_cpy, ctx_len);
- //ctx = &ctx_cpy;
}
#endif
-
-void i_ctx_t_free(i_ctx* c) {
- for (isize i = 0; i < c->len; i++) {
- binding_t_free(&c->bindings[i]);
- }
-}
-
-void binding_t_free(binding_t* b) {
- switch (b->action.type) {
- case InputType_error:
- ERROR("Cannot free binding of type InputType_error");
- break;
- case InputType_action:
- free(b->action.action.callback_str);
- return;
-
- case InputType_state:
- free(b->action.state.activate_str);
- free(b->action.state.deactivate_str);
- break;
-
- case InputType_range:
- ERROR("Cannot free binding of type InputType_rage");
- break;
-
- default:
- ERROR("Unknown bindings type");
- break;
- }
- exit(EXIT_FAILURE);
-}