forked from kdx/jtmm2-old
Base of input buffering structure.
This commit is contained in:
parent
03b2204811
commit
fefdd06257
|
@ -25,10 +25,11 @@ enum {
|
|||
typedef struct Input {
|
||||
uint8_t keys[KEYS_COUNT];
|
||||
uint8_t states[KEYS_COUNT];
|
||||
uint last_press[KEYS_COUNT];
|
||||
} Input;
|
||||
|
||||
/* will check for new key inputs and update states[] */
|
||||
void input_step(Input *input);
|
||||
void input_step(Input *input, uint step);
|
||||
|
||||
/* initialize values */
|
||||
void input_init(Input *input);
|
||||
|
|
21
src/input.c
21
src/input.c
|
@ -3,18 +3,25 @@
|
|||
|
||||
#include "input.h"
|
||||
|
||||
void input_step(Input *input) {
|
||||
void input_step(Input *input, uint step) {
|
||||
/* read all inputs */
|
||||
clearevents();
|
||||
/* for each key, update it's state */
|
||||
/* For each key, update it's state and --if needed-- last press
|
||||
* time. */
|
||||
for (int i = 0; i < KEYS_COUNT; ++i) {
|
||||
uint8_t *state = &input->states[i];
|
||||
uint8_t key = input->keys[i];
|
||||
/* get if the key is pressed */
|
||||
bool pressed = keydown(key);
|
||||
const uint8_t key = input->keys[i];
|
||||
/* see if the key is pressed */
|
||||
const bool pressed = keydown(key);
|
||||
/* update input status */
|
||||
if (pressed) {
|
||||
*state = (*state == S_RELEASED || *state == S_UP) ? S_PRESSED : S_DOWN;
|
||||
if (*state == S_RELEASED || *state == S_UP) {
|
||||
*state = S_PRESSED;
|
||||
input->last_press[i] = step;
|
||||
}
|
||||
else {
|
||||
*state = S_DOWN;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*state = (*state == S_PRESSED || *state == S_DOWN) ? S_RELEASED : S_UP;
|
||||
|
@ -32,6 +39,7 @@ void input_init(Input *input) {
|
|||
input->keys[K_EXIT] = KEY_EXIT;
|
||||
for (int i = 0; i < KEYS_COUNT; ++i) {
|
||||
input->states[i] = S_UP;
|
||||
input->last_press[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +52,6 @@ void input_draw_debug(Input *input) {
|
|||
dprint(48, i * 10, C_BLACK, "P%d", input_is_pressed(input, i));
|
||||
dprint(64, i * 10, C_BLACK, "U%d", input_is_up(input, i));
|
||||
dprint(80, i * 10, C_BLACK, "R%d", input_is_released(input, i));
|
||||
dprint(96, i * 10, C_BLACK, "V%d", (int)input_is_down(input, i));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ int callback(volatile void *arg) {
|
|||
|
||||
void step_event(Player *player, const Level *level, Camera *camera, Input *input, uint step) {
|
||||
//getkey();
|
||||
input_step(input);
|
||||
input_step(input, step);
|
||||
player_step(player, input, level);
|
||||
level_step(level);
|
||||
camera_step(camera);
|
||||
|
@ -95,7 +95,7 @@ void draw_event(Player *player, const Level *level, Camera *camera, Input *input
|
|||
level_draw(level, camera);
|
||||
player_draw(player, camera);
|
||||
#ifdef DEBUG
|
||||
camera_draw_debug(camera);
|
||||
//camera_draw_debug(camera);
|
||||
//input_draw_debug(input);
|
||||
//player_draw_debug(player, step, level, 0);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue