Beginning input refactor

This commit is contained in:
2025-09-03 11:57:48 -05:00
parent 059ccf41b6
commit 3f37b7cdb5
19 changed files with 320 additions and 137 deletions

View File

@@ -13,25 +13,57 @@ input_t INPUT;
void inputInit(void) {
memoryZero(&INPUT, sizeof(input_t));
INPUT.binds[INPUT_BIND_UP].keyboard[0] = SDL_SCANCODE_W;
INPUT.binds[INPUT_BIND_UP].keyboard[1] = SDL_SCANCODE_UP;
INPUT.binds[INPUT_BIND_CONSOLE].keyboard[0] = SDL_SCANCODE_GRAVE;
}
void inputUpdate(void) {
INPUT.previous = INPUT.current;
INPUT.current = inputStateGet();
#if INPUT_SDL2 == 1
const uint8_t *keyboardState = SDL_GetKeyboardState(NULL);
#endif
// For each input bind...
inputbinddata_t *data = INPUT.binds;
do {
data->lastValue = data->currentValue;
data->currentValue = 0.0f;
// Handle keyboard
#if INPUT_KEYBOARD == 1
for(uint32_t i = 0; i < INPUT_BIND_KEYBOARD_BUTTONS_MAX; i++) {
if(data->keyboard[i] == 0) break;
#if INPUT_SDL2 == 1
if(keyboardState[data->keyboard[i]]) {
data->currentValue = 1.0f;
break;
}
#endif
}
#endif
data++;
} while(data < INPUT.binds + INPUT_BIND_COUNT);
}
inputstate_t inputStateGet(void) {
return 0;
float_t inputGetCurrentValue(const inputbind_t bind) {
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
return INPUT.binds[bind].currentValue;
}
float_t inputGetLast(const inputbind_t bind) {
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
return INPUT.binds[bind].lastValue;
}
bool_t inputIsDown(const inputbind_t bind) {
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
return (INPUT.current & bind) != 0;
return inputGetCurrentValue(bind) > 0.0f;
}
bool_t inputWasDown(const inputbind_t bind) {
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
return (INPUT.previous & bind) != 0;
return inputGetLast(bind) > 0.0f;
}
bool_t inputPressed(const inputbind_t bind) {