Files
dusk/archive/dusk/input.c
2025-08-20 19:18:38 -05:00

39 lines
899 B
C

/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "input.h"
#include "assert/assert.h"
#include "util/memory.h"
input_t INPUT;
void inputInit(void) {
memoryZero(&INPUT, sizeof(input_t));
}
void inputUpdate(void) {
INPUT.previous = INPUT.current;
INPUT.current = inputStateGet();
}
bool_t inputIsDown(const inputbind_t bind) {
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
return (INPUT.current & bind) != 0;
}
bool_t inputWasDown(const inputbind_t bind) {
assertTrue(bind < INPUT_BIND_COUNT, "Input bind out of bounds");
return (INPUT.previous & bind) != 0;
}
bool_t inputPressed(const inputbind_t bind) {
return inputIsDown(bind) && !inputWasDown(bind);
}
bool_t inputReleased(const inputbind_t bind) {
return !inputIsDown(bind) && inputWasDown(bind);
}