diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/eventsmanager.cpp | 62 | ||||
-rw-r--r-- | src/eventsmanager.h | 2 | ||||
-rw-r--r-- | src/game.cpp | 57 | ||||
-rw-r--r-- | src/game.h | 2 |
4 files changed, 66 insertions, 57 deletions
diff --git a/src/eventsmanager.cpp b/src/eventsmanager.cpp index c2b4b4c72..203a7679f 100644 --- a/src/eventsmanager.cpp +++ b/src/eventsmanager.cpp @@ -153,6 +153,68 @@ bool EventsManager::handleEvents() return false; } +void EventsManager::handleGameEvents() +{ + Game *const game = Game::instance(); + + // Events + SDL_Event event; +#ifdef USE_SDL2 + while (SDL_WaitEventTimeout(&event, 0)) +#else + while (SDL_PollEvent(&event)) +#endif + { + BLOCK_START("Game::handleInput 2") + if (mLogInput) + logEvent(event); + + if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) + game->updateHistory(event); + game->checkKeys(); + + if (inputManager.handleEvent(event)) + { + BLOCK_END("Game::handleInput 2") + BLOCK_END("Game::handleInput 1") + return; + } + + switch (event.type) + { +#ifdef USE_SDL2 + case SDL_WINDOWEVENT: + { + game->handleSDL2WindowEvent(event); + break; + } +#else + case SDL_VIDEORESIZE: + client->resizeVideo(event.resize.w, event.resize.h); + break; + // Active event + case SDL_ACTIVEEVENT: + game->handleActive(event); + break; +#endif + // Quit event + case SDL_QUIT: + client->setState(STATE_EXIT); + break; +#ifdef ANDROID +#ifndef USE_SDL2 + case SDL_KEYBOARDSHOW: + client->updateScreenKeyboard(event.user.code); + break; +#endif +#endif + default: + break; + } + BLOCK_END("Game::handleInput 2") + } // End while +} + void EventsManager::optionChanged(const std::string &name) { if (name == "logInput") diff --git a/src/eventsmanager.h b/src/eventsmanager.h index da76d7b77..9f1aa5731 100644 --- a/src/eventsmanager.h +++ b/src/eventsmanager.h @@ -41,6 +41,8 @@ class EventsManager final : public ConfigListener bool handleEvents(); + void handleGameEvents(); + void optionChanged(const std::string &name); void logEvent(const SDL_Event &event); diff --git a/src/game.cpp b/src/game.cpp index 6592e6ae9..971352234 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1009,62 +1009,7 @@ void Game::handleInput() if (joystick) joystick->logic(); - // Events - SDL_Event event; -#ifdef USE_SDL2 - while (SDL_WaitEventTimeout(&event, 0)) -#else - while (SDL_PollEvent(&event)) -#endif - { - BLOCK_START("Game::handleInput 2") -// if (eventsManager.handleEvent(event)) -// continue; - - if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) - updateHistory(event); - checkKeys(); - - if (inputManager.handleEvent(event)) - { - BLOCK_END("Game::handleInput 2") - BLOCK_END("Game::handleInput 1") - return; - } - - switch (event.type) - { -#ifdef USE_SDL2 - case SDL_WINDOWEVENT: - { - handleSDL2WindowEvent(event); - break; - } -#else - case SDL_VIDEORESIZE: - client->resizeVideo(event.resize.w, event.resize.h); - break; - // Active event - case SDL_ACTIVEEVENT: - handleActive(event); - break; -#endif - // Quit event - case SDL_QUIT: - client->setState(STATE_EXIT); - break; -#ifdef ANDROID -#ifndef USE_SDL2 - case SDL_KEYBOARDSHOW: - client->updateScreenKeyboard(event.user.code); - break; -#endif -#endif - default: - break; - } - BLOCK_END("Game::handleInput 2") - } // End while + eventsManager.handleGameEvents(); // If the user is configuring the keys then don't respond. if (!player_node || !keyboard.isEnabled() || player_node->getAway()) diff --git a/src/game.h b/src/game.h index 1d7c6821f..34d6d5107 100644 --- a/src/game.h +++ b/src/game.h @@ -124,11 +124,11 @@ class Game final static bool saveScreenshot(SDL_Surface *const screenshot); - private: void updateHistory(const SDL_Event &event); void checkKeys(); + private: void clearKeysArray(); Map *mCurrentMap; |