summaryrefslogtreecommitdiff
path: root/src
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
parent60ad04e80489e73a0765530dbfffc18322043b1c (diff)
downloadManaVerse-3eb27b1cb9b1f645ab5bf9d972ce3d73ec743226.tar.gz
ManaVerse-3eb27b1cb9b1f645ab5bf9d972ce3d73ec743226.tar.bz2
ManaVerse-3eb27b1cb9b1f645ab5bf9d972ce3d73ec743226.tar.xz
ManaVerse-3eb27b1cb9b1f645ab5bf9d972ce3d73ec743226.zip
Move some events code from client into eventsmanager.
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp111
-rw-r--r--src/eventsmanager.cpp112
-rw-r--r--src/eventsmanager.h2
-rw-r--r--src/game.cpp4
4 files changed, 114 insertions, 115 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 5d1fbdb93..b5ae5ee09 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -959,8 +959,6 @@ int Client::gameExec()
mumbleManager = new MumbleManager();
#endif
- SDL_Event event;
-
if (Theme::instance())
mSkin = Theme::instance()->load("windowmenu.xml", "");
if (mSkin)
@@ -973,113 +971,10 @@ int Client::gameExec()
{
PROFILER_START();
BLOCK_START("Client::gameExec 1")
- if (mGame)
- {
- // Let the game handle the events while it is active
- mGame->handleInput();
- }
- else
- {
- BLOCK_START("Client::gameExec 2")
- // Handle SDL events
-#ifdef USE_SDL2
- while (SDL_WaitEventTimeout(&event, 0))
-#else
- while (SDL_PollEvent(&event))
-#endif
- {
- if (eventsManager.handleEvent(event))
- continue;
-
- switch (event.type)
- {
- case SDL_QUIT:
- mState = 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
-#ifdef USE_SDL2
- // +++ need add support
-#else
- case SDL_ACTIVEEVENT:
- if ((event.active.state & SDL_APPACTIVE)
- && !event.active.gain)
- {
- mState = STATE_EXIT;
- logger->log1("exit on lost focus");
- }
- break;
-
- case SDL_KEYBOARDSHOW:
- updateScreenKeyboard(event.user.code);
- break;
-
- case SDL_ACCELEROMETER:
- break;
-#endif
-#endif
-
- default:
-// logger->log("unknown event: %d", event.type);
- break;
-
-#ifdef USE_SDL2
- case SDL_WINDOWEVENT:
- handleSDL2WindowEvent(event);
- break;
-#else
-#ifndef ANDROID
- case SDL_ACTIVEEVENT:
- handleActive(event);
- break;
-#endif
- case SDL_VIDEORESIZE:
- resizeVideo(event.resize.w, event.resize.h, false);
- break;
-#endif
- }
+ if (eventsManager.handleEvents())
+ continue;
- 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 (mState == STATE_EXIT)
- continue;
- BLOCK_END("Client::gameExec 2")
- }
+ BLOCK_END("Client::gameExec 1")
BLOCK_START("Client::gameExec 3")
if (Net::getGeneralHandler())
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;
}
diff --git a/src/eventsmanager.h b/src/eventsmanager.h
index f5e214d11..da76d7b77 100644
--- a/src/eventsmanager.h
+++ b/src/eventsmanager.h
@@ -39,7 +39,7 @@ class EventsManager final : public ConfigListener
void init();
- bool handleEvent(const SDL_Event &event);
+ bool handleEvents();
void optionChanged(const std::string &name);
diff --git a/src/game.cpp b/src/game.cpp
index 0cc8da764..6592e6ae9 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -1018,8 +1018,8 @@ void Game::handleInput()
#endif
{
BLOCK_START("Game::handleInput 2")
- if (eventsManager.handleEvent(event))
- continue;
+// if (eventsManager.handleEvent(event))
+// continue;
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
updateHistory(event);