summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-07 19:09:52 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-07 19:09:52 +0300
commitc89329623cbe5a2c3d5baf25fc58808f13af6069 (patch)
tree0a92ea20ea5fee2136d69b0ff7ba2b5dc6473dac
parent29cae530ae1796f37fe923fe372c695783b559de (diff)
downloadmanaverse-c89329623cbe5a2c3d5baf25fc58808f13af6069.tar.gz
manaverse-c89329623cbe5a2c3d5baf25fc58808f13af6069.tar.bz2
manaverse-c89329623cbe5a2c3d5baf25fc58808f13af6069.tar.xz
manaverse-c89329623cbe5a2c3d5baf25fc58808f13af6069.zip
Move shared event handling code into common handler.
-rw-r--r--src/eventsmanager.cpp142
-rw-r--r--src/eventsmanager.h2
2 files changed, 57 insertions, 87 deletions
diff --git a/src/eventsmanager.cpp b/src/eventsmanager.cpp
index 203a7679f..7e9c24970 100644
--- a/src/eventsmanager.cpp
+++ b/src/eventsmanager.cpp
@@ -45,6 +45,39 @@ void EventsManager::init()
config.addListener("logInput", this);
}
+bool EventsManager::handleCommonEvents(const SDL_Event &event)
+{
+ if (mLogInput)
+ logEvent(event);
+
+ switch (event.type)
+ {
+ case SDL_QUIT:
+ client->setState(STATE_EXIT);
+ logger->log1("force exit");
+ return true;
+#ifndef USE_SDL2
+ case SDL_VIDEORESIZE:
+ client->resizeVideo(event.resize.w, event.resize.h);
+ return true;
+#ifdef ANDROID
+ case SDL_KEYBOARDSHOW:
+ client->updateScreenKeyboard(event.user.code);
+ return true;
+ case SDL_ACCELEROMETER:
+ break;
+#endif
+#endif
+ default:
+ break;
+ }
+
+ if (inputManager.handleEvent(event))
+ return true;
+
+ return false;
+}
+
bool EventsManager::handleEvents()
{
if (Game::instance())
@@ -63,82 +96,39 @@ bool EventsManager::handleEvents()
while (SDL_PollEvent(&event))
#endif
{
- if (mLogInput)
- logEvent(event);
-
- switch (event.type)
+ if (!handleCommonEvents(event))
{
- case SDL_QUIT:
- client->setState(STATE_EXIT);
- logger->log1("force exit");
- break;
-
- case SDL_KEYDOWN:
- if (inputManager.handleAssignKey(
- event, INPUT_KEYBOARD))
- {
- continue;
- }
- inputManager.updateConditionMask();
- break;
-
- case SDL_KEYUP:
- if (inputManager.handleAssignKey(
- event, INPUT_KEYBOARD))
- {
- continue;
- }
- inputManager.updateConditionMask();
- break;
-
- case SDL_JOYBUTTONDOWN:
- inputManager.handleAssignKey(event, INPUT_JOYSTICK);
- break;
-
- case SDL_MOUSEMOTION:
- break;
-
+ switch (event.type)
+ {
#ifdef ANDROID
#ifndef USE_SDL2
- case SDL_ACTIVEEVENT:
- if ((event.active.state & SDL_APPACTIVE)
- && !event.active.gain)
- {
- client->setState(STATE_EXIT);
- logger->log1("exit on lost focus");
- }
- break;
+ case SDL_ACTIVEEVENT:
+ if ((event.active.state & SDL_APPACTIVE)
+ && !event.active.gain)
+ {
+ client->setState(STATE_EXIT);
+ logger->log1("exit on lost focus");
+ }
+ break;
- case SDL_KEYBOARDSHOW:
- client->updateScreenKeyboard(event.user.code);
- break;
-
- case SDL_ACCELEROMETER:
- break;
#endif
#endif
- default:
- break;
-
+ default:
+ break;
#ifdef USE_SDL2
- case SDL_WINDOWEVENT:
- client->handleSDL2WindowEvent(event);
- break;
+ case SDL_WINDOWEVENT:
+ client->handleSDL2WindowEvent(event);
+ break;
#else
#ifndef ANDROID
- case SDL_ACTIVEEVENT:
- client->handleActive(event);
- break;
+ case SDL_ACTIVEEVENT:
+ client->handleActive(event);
+ break;
#endif
- case SDL_VIDEORESIZE:
- client->resizeVideo(event.resize.w, event.resize.h, false);
- break;
#endif
+ }
}
- if (inputManager.handleEvent(event))
- continue;
-
#ifdef USE_MUMBLE
if (player_node && mumbleManager)
{
@@ -165,20 +155,12 @@ void EventsManager::handleGameEvents()
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;
- }
+ if (handleCommonEvents(event))
+ break;
switch (event.type)
{
@@ -189,25 +171,11 @@ void EventsManager::handleGameEvents()
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;
}
diff --git a/src/eventsmanager.h b/src/eventsmanager.h
index 9f1aa5731..fc977d3be 100644
--- a/src/eventsmanager.h
+++ b/src/eventsmanager.h
@@ -41,6 +41,8 @@ class EventsManager final : public ConfigListener
bool handleEvents();
+ bool handleCommonEvents(const SDL_Event &event);
+
void handleGameEvents();
void optionChanged(const std::string &name);