Improve input processing

This commit is contained in:
2023-12-07 18:21:14 +01:00
parent 8543cc7b43
commit 56a73fe28c
6 changed files with 117 additions and 130 deletions

View File

@@ -4,6 +4,7 @@
#include "utils/building_types.h"
#include "components.h"
#include "game_state.h"
#include "input.h"
#include "map_init.h"
#include "map_layers.h"
#include "buildings.h"
@@ -65,11 +66,7 @@ bool init(void *userData) {
ecs_singleton_set(ECS, InputState, {});
InputState *input = ecs_singleton_get_mut(ECS, InputState);
input->LMB = MOUSE_LEFT_BUTTON;
input->RMB = MOUSE_RIGHT_BUTTON;
input->MMB = MOUSE_MIDDLE_BUTTON;
input->ESC = KEY_ESCAPE;
input->CLICK_LIMIT = 0.2f;
input->mapping = inputDefaultMapping();
// Create queries
input->queries.selected = ecs_query(ECS, {
@@ -210,11 +207,14 @@ void update(float dt, void *userData) {
snprintf(titleBuf, sizeof(titleBuf), "FPS: %d | %.2f ms", GetFPS(), GetFrameTime() * 1000);
SetWindowTitle(titleBuf);
Game *game = ecs_singleton_get_mut(ECS, Game);
Game *game = ecs_singleton_get_mut(ECS, Game);
InputState *input = ecs_singleton_get_mut(ECS, InputState);
BZ_ASSERT(game->stackAlloc.allocated == 0);
bzStackAllocReset(&game->stackAlloc);
updateInputState(input, game->camera, dt);
updatePlayerInput();
}