summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-07 18:35:19 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-07 18:35:19 +0300
commit29cae530ae1796f37fe923fe372c695783b559de (patch)
tree0b02e47dbd52b1fada0b94b2b9956ab0b6308f6c
parent3eb27b1cb9b1f645ab5bf9d972ce3d73ec743226 (diff)
downloadManaVerse-29cae530ae1796f37fe923fe372c695783b559de.tar.gz
ManaVerse-29cae530ae1796f37fe923fe372c695783b559de.tar.bz2
ManaVerse-29cae530ae1796f37fe923fe372c695783b559de.tar.xz
ManaVerse-29cae530ae1796f37fe923fe372c695783b559de.zip
Move some events code from game into eventsmanager.
-rw-r--r--src/eventsmanager.cpp62
-rw-r--r--src/eventsmanager.h2
-rw-r--r--src/game.cpp57
-rw-r--r--src/game.h2
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;