From ae55b888e0b0de2b51da15b1265d439439e6a876 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Tue, 28 Jun 2016 23:58:41 +0100 Subject: [PATCH] Update game state from SDL events --- rwgame/ingamestate.cpp | 19 +++++++++++++++++++ rwgame/ingamestate.hpp | 1 + 2 files changed, 20 insertions(+) diff --git a/rwgame/ingamestate.cpp b/rwgame/ingamestate.cpp index cebb9ef4..c5f44918 100644 --- a/rwgame/ingamestate.cpp +++ b/rwgame/ingamestate.cpp @@ -401,6 +401,8 @@ void IngameState::handleEvent(const SDL_Event& event) break; default: break; } + + updateInputState(event); if( player && player->isInputEnabled() ) { @@ -495,6 +497,23 @@ void IngameState::handlePlayerInput(const SDL_Event& event) } } +void IngameState::updateInputState(const SDL_Event& event) +{ + switch (event.type) { + case SDL_KEYDOWN: + case SDL_KEYUP: { + auto sym = event.key.keysym.sym; + auto level = event.type == SDL_KEYDOWN ? 1.f : 0.f; + auto& levels = getWorld()->state->input.currentLevels; + + auto range = kDefaultControls.equal_range(sym); + for (auto it = range.first; it != range.second; ++it) { + levels[it->second] = level; + } + } break; + } +} + bool IngameState::shouldWorldUpdate() { diff --git a/rwgame/ingamestate.hpp b/rwgame/ingamestate.hpp index 68ed28f1..b289f8b6 100644 --- a/rwgame/ingamestate.hpp +++ b/rwgame/ingamestate.hpp @@ -55,6 +55,7 @@ public: virtual void handleEvent(const SDL_Event& event); virtual void handlePlayerInput(const SDL_Event& event); + void updateInputState(const SDL_Event& event); virtual bool shouldWorldUpdate();