Prog
This commit is contained in:
58
src/input.c
58
src/input.c
@ -9,20 +9,6 @@
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
inputbindmap_t INPUT_BIND_MAPS[] = {
|
||||
{ KEY_W, INPUT_UP },
|
||||
{ KEY_S, INPUT_DOWN },
|
||||
{ KEY_A, INPUT_LEFT },
|
||||
{ KEY_D, INPUT_RIGHT },
|
||||
{ KEY_ENTER, INPUT_ACCEPT },
|
||||
{ KEY_ESCAPE, INPUT_CANCEL },
|
||||
{ KEY_UP, INPUT_UP },
|
||||
{ KEY_DOWN, INPUT_DOWN },
|
||||
{ KEY_LEFT, INPUT_LEFT },
|
||||
{ KEY_RIGHT, INPUT_RIGHT },
|
||||
{ KEY_GRAVE, INPUT_TOGGLE_CONSOLE }
|
||||
};
|
||||
|
||||
#define INPUT_BIND_MAP_COUNT (sizeof(INPUT_BIND_MAPS) / sizeof(inputbindmap_t))
|
||||
|
||||
input_t INPUT;
|
||||
@ -32,48 +18,4 @@ void inputInit(void) {
|
||||
}
|
||||
|
||||
void inputUpdate(void) {
|
||||
memoryCopy(
|
||||
INPUT.previous,
|
||||
INPUT.current,
|
||||
sizeof(INPUT.previous)
|
||||
);
|
||||
|
||||
memoryZero(
|
||||
INPUT.current,
|
||||
sizeof(INPUT.current)
|
||||
);
|
||||
|
||||
for(uint32_t i = 0; i < INPUT_BIND_MAP_COUNT; i++) {
|
||||
const inputbindmap_t *map = &INPUT_BIND_MAPS[i];
|
||||
if(IsKeyDown(map->key)) INPUT.current[map->bind] = true;
|
||||
}
|
||||
|
||||
INPUT.keyPressed = GetKeyPressed();
|
||||
INPUT.charPressed = GetCharPressed();
|
||||
}
|
||||
|
||||
bool_t inputIsDown(const inputbind_t input) {
|
||||
assertTrue(input < INPUT_BIND_COUNT, "Input out of range");
|
||||
return INPUT.current[input];
|
||||
}
|
||||
|
||||
bool_t inputIsUp(const inputbind_t input) {
|
||||
return !inputIsDown(input);
|
||||
}
|
||||
|
||||
bool_t inputWasDown(const inputbind_t input) {
|
||||
assertTrue(input < INPUT_BIND_COUNT, "Input out of range");
|
||||
return INPUT.previous[input];
|
||||
}
|
||||
|
||||
bool_t inputWasUp(const inputbind_t input) {
|
||||
return !inputWasDown(input);
|
||||
}
|
||||
|
||||
bool_t inputIsPressed(const inputbind_t input) {
|
||||
return inputIsDown(input) && inputWasUp(input);
|
||||
}
|
||||
|
||||
bool_t inputIsReleased(const inputbind_t input) {
|
||||
return inputIsUp(input) && inputWasDown(input);
|
||||
}
|
Reference in New Issue
Block a user