summaryrefslogtreecommitdiff
path: root/src/eventsmanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-07 18:09:16 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-07 18:09:16 +0300
commit3eb27b1cb9b1f645ab5bf9d972ce3d73ec743226 (patch)
treede179f0ddf32d77da14646127fe5b612149ec73c /src/eventsmanager.cpp
parent60ad04e80489e73a0765530dbfffc18322043b1c (diff)
downloadmv-3eb27b1cb9b1f645ab5bf9d972ce3d73ec743226.tar.gz
mv-3eb27b1cb9b1f645ab5bf9d972ce3d73ec743226.tar.bz2
mv-3eb27b1cb9b1f645ab5bf9d972ce3d73ec743226.tar.xz
mv-3eb27b1cb9b1f645ab5bf9d972ce3d73ec743226.zip
Move some events code from client into eventsmanager.
Diffstat (limited to 'src/eventsmanager.cpp')
-rw-r--r--src/eventsmanager.cpp112
1 files changed, 108 insertions, 4 deletions
diff --git a/src/eventsmanager.cpp b/src/eventsmanager.cpp
index 8866b03db..c2b4b4c72 100644
--- a/src/eventsmanager.cpp
+++ b/src/eventsmanager.cpp
@@ -21,7 +21,14 @@
#include "eventsmanager.h"
#include "configuration.h"
+#include "client.h"
+#include "game.h"
#include "logger.h"
+#include "mumblemanager.h"
+
+#include "being/localplayer.h"
+
+#include "input/inputmanager.h"
#include "debug.h"
@@ -38,14 +45,111 @@ void EventsManager::init()
config.addListener("logInput", this);
}
-bool EventsManager::handleEvent(const SDL_Event &event)
+bool EventsManager::handleEvents()
{
- if (mLogInput)
- logEvent(event);
- switch (event.type)
+ if (Game::instance())
{
+ // Let the game handle the events while it is active
+ Game::instance()->handleInput();
}
+ else
+ {
+ SDL_Event event;
+
+ // Handle SDL events
+#ifdef USE_SDL2
+ while (SDL_WaitEventTimeout(&event, 0))
+#else
+ while (SDL_PollEvent(&event))
+#endif
+ {
+ if (mLogInput)
+ logEvent(event);
+
+ switch (event.type)
+ {
+ 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;
+
+#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_KEYBOARDSHOW:
+ client->updateScreenKeyboard(event.user.code);
+ break;
+
+ case SDL_ACCELEROMETER:
+ break;
+#endif
+#endif
+ default:
+ break;
+
+#ifdef USE_SDL2
+ case SDL_WINDOWEVENT:
+ client->handleSDL2WindowEvent(event);
+ break;
+#else
+#ifndef ANDROID
+ 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)
+ {
+ mumbleManager->setPos(player_node->getTileX(),
+ player_node->getTileY(), player_node->getDirection());
+ }
+#endif
+ }
+ if (client->getState() == STATE_EXIT)
+ return true;
+ }
return false;
}