1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00

Update game state from SDL events

This commit is contained in:
Daniel Evans 2016-06-28 23:58:41 +01:00
parent 827653a12b
commit ae55b888e0
2 changed files with 20 additions and 0 deletions

View File

@ -402,6 +402,8 @@ void IngameState::handleEvent(const SDL_Event& event)
default: break;
}
updateInputState(event);
if( player && player->isInputEnabled() )
{
handlePlayerInput(event);
@ -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()
{

View File

@ -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();