summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-07 17:00:02 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-07 17:07:42 +0300
commit60ad04e80489e73a0765530dbfffc18322043b1c (patch)
tree1018764a38a68418519d7606c43e20fea85ed161 /src
parent422d65e9407eb9a7ed18b894ad665a7925397ebf (diff)
downloadmanaplus-60ad04e80489e73a0765530dbfffc18322043b1c.tar.gz
manaplus-60ad04e80489e73a0765530dbfffc18322043b1c.tar.bz2
manaplus-60ad04e80489e73a0765530dbfffc18322043b1c.tar.xz
manaplus-60ad04e80489e73a0765530dbfffc18322043b1c.zip
Create events manager class.
Move events logging into EventsManager.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/client.cpp220
-rw-r--r--src/client.h3
-rw-r--r--src/eventsmanager.cpp260
-rw-r--r--src/eventsmanager.h54
-rw-r--r--src/game.cpp7
-rw-r--r--src/game.h1
8 files changed, 329 insertions, 220 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0a0fec949..1d2662d79 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -614,6 +614,8 @@ SET(SRCS
emoteshortcut.cpp
emoteshortcut.h
equipment.h
+ eventsmanager.cpp
+ eventsmanager.h
flooritem.cpp
flooritem.h
game.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index b300d71a5..8f90991ae 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -629,6 +629,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
emoteshortcut.cpp \
emoteshortcut.h \
equipment.h \
+ eventsmanager.cpp \
+ eventsmanager.h \
flooritem.cpp \
flooritem.h \
game.cpp \
diff --git a/src/client.cpp b/src/client.cpp
index 8762a0456..5d1fbdb93 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -29,6 +29,7 @@
#include "configuration.h"
#include "dropshortcut.h"
#include "emoteshortcut.h"
+#include "eventsmanager.h"
#include "game.h"
#include "guild.h"
#include "guildmanager.h"
@@ -321,8 +322,7 @@ Client::Client(const Options &options) :
mIsMinimized(false),
mInputFocused(true),
mMouseFocused(true),
- mNewMessageFlag(false),
- mLogInput(false)
+ mNewMessageFlag(false)
{
// Initialize frame limiting
mFpsManager.framecount = 0;
@@ -654,6 +654,8 @@ void Client::gameInit()
logger->log("Warning: %s", err);
}
+ eventsManager.init();
+
// Initialize keyboard
keyboard.init();
inputManager.init();
@@ -724,7 +726,6 @@ void Client::gameInit()
config.addListener("repeateInterval", this);
config.addListener("logInput", this);
setGuiAlpha(config.getFloatValue("guialpha"));
- mLogInput = config.getBoolValue("logInput");
optionChanged("fpslimit");
start_time = static_cast<int>(time(nullptr));
@@ -987,8 +988,9 @@ int Client::gameExec()
while (SDL_PollEvent(&event))
#endif
{
- if (mLogInput)
- logEvent(event);
+ if (eventsManager.handleEvent(event))
+ continue;
+
switch (event.type)
{
case SDL_QUIT:
@@ -1890,10 +1892,6 @@ void Client::optionChanged(const std::string &name)
{
applyKeyRepeat();
}
- else if (name == "logInput")
- {
- mLogInput = config.getBoolValue("logInput");
- }
}
void Client::action(const gcn::ActionEvent &event)
@@ -2926,210 +2924,6 @@ void Client::logVars()
#endif
}
-void Client::logEvent(const SDL_Event &event)
-{
- switch (event.type)
- {
- case SDL_MOUSEMOTION:
- logger->log("event: SDL_MOUSEMOTION: %d,%d,%d",
- event.motion.state, event.motion.x, event.motion.y);
- break;
-#ifdef USE_SDL2
-#define winEventLog(name, name2) \
- case name: \
- str = name2; \
- break
-
- case SDL_FINGERDOWN:
- {
- const SDL_TouchFingerEvent &touch = event.tfinger;
- const int w = mainGraphics->mWidth;
- const int h = mainGraphics->mHeight;
- logger->log("event: SDL_FINGERDOWN: %lld,%lld (%f,%f) (%f,%f)",
- touch.touchId, touch.fingerId, touch.x * w, touch.y * w,
- touch.dx * w, touch.dy * h);
- break;
- }
- case SDL_FINGERUP:
- {
- const SDL_TouchFingerEvent &touch = event.tfinger;
- const int w = mainGraphics->mWidth;
- const int h = mainGraphics->mHeight;
- logger->log("event: SDL_FINGERUP: %lld,%lld (%f,%f) (%f,%f)",
- touch.touchId, touch.fingerId, touch.x * w, touch.y * h,
- touch.dx * w, touch.dy * h);
- break;
- }
- case SDL_FINGERMOTION:
- {
- const SDL_TouchFingerEvent &touch = event.tfinger;
- const int w = mainGraphics->mWidth;
- const int h = mainGraphics->mHeight;
- logger->log("event: SDL_FINGERMOTION: %lld,%lld (%f,%f) (%f,%f)",
- touch.touchId, touch.fingerId,
- touch.x * w, touch.y * h,
- touch.dx * w, touch.dy * h);
- break;
- }
- case SDL_MULTIGESTURE:
- {
- const SDL_MultiGestureEvent &gesture = event.mgesture;
- const int w = mainGraphics->mWidth;
- const int h = mainGraphics->mHeight;
- logger->log("event: SDL_MULTIGESTURE: %lld %f,%f (%f,%f) %d,%d",
- gesture.touchId, gesture.dTheta, gesture.dDist,
- gesture.x * w, gesture.y * h, (int)gesture.numFingers,
- (int)gesture.padding);
- break;
- }
- case SDL_KEYDOWN:
- logger->log("event: SDL_KEYDOWN: %d,%d", event.key.state,
- event.key.keysym.scancode);
- break;
- case SDL_KEYUP:
- logger->log("event: SDL_KEYUP: %d,%d", event.key.state,
- event.key.keysym.scancode);
- break;
- case SDL_WINDOWEVENT:
- {
- const int data1 = event.window.data1;
- const int data2 = event.window.data2;
- std::string str;
- switch (event.window.event)
- {
- winEventLog(SDL_WINDOWEVENT_NONE, "SDL_WINDOWEVENT_NONE");
- winEventLog(SDL_WINDOWEVENT_SHOWN, "SDL_WINDOWEVENT_SHOWN");
- winEventLog(SDL_WINDOWEVENT_HIDDEN, "SDL_WINDOWEVENT_HIDDEN");
- winEventLog(SDL_WINDOWEVENT_EXPOSED,
- "SDL_WINDOWEVENT_EXPOSED");
- winEventLog(SDL_WINDOWEVENT_MOVED, "SDL_WINDOWEVENT_MOVED");
- winEventLog(SDL_WINDOWEVENT_RESIZED,
- "SDL_WINDOWEVENT_RESIZED");
- winEventLog(SDL_WINDOWEVENT_SIZE_CHANGED,
- "SDL_WINDOWEVENT_SIZE_CHANGED");
- winEventLog(SDL_WINDOWEVENT_MINIMIZED,
- "SDL_WINDOWEVENT_MINIMIZED");
- winEventLog(SDL_WINDOWEVENT_MAXIMIZED,
- "SDL_WINDOWEVENT_MAXIMIZED");
- winEventLog(SDL_WINDOWEVENT_RESTORED,
- "SDL_WINDOWEVENT_RESTORED");
- winEventLog(SDL_WINDOWEVENT_ENTER, "SDL_WINDOWEVENT_ENTER");
- winEventLog(SDL_WINDOWEVENT_LEAVE, "SDL_WINDOWEVENT_LEAVE");
- winEventLog(SDL_WINDOWEVENT_FOCUS_GAINED,
- "SDL_WINDOWEVENT_FOCUS_GAINED");
- winEventLog(SDL_WINDOWEVENT_FOCUS_LOST,
- "SDL_WINDOWEVENT_FOCUS_LOST");
- winEventLog(SDL_WINDOWEVENT_CLOSE, "SDL_WINDOWEVENT_CLOSE");
- default:
- str = "unknown";
- break;
- }
- logger->log("event: SDL_WINDOWEVENT: %s: %d,%d",
- str.c_str(), data1, data2);
- break;
- }
- case SDL_TEXTINPUT:
- {
- const char *const text = event.text.text;
- logger->log("event: SDL_TEXTINPUT: %s", text);
- const int sz = strlen(event.text.text);
- for (int f = 0; f < sz; f ++)
- logger->log("dec: %d", text[f]);
- break;
- }
- case SDL_APP_TERMINATING:
- logger->log("SDL_APP_TERMINATING");
- break;
- case SDL_APP_LOWMEMORY:
- logger->log("SDL_APP_LOWMEMORY");
- break;
- case SDL_APP_WILLENTERBACKGROUND:
- logger->log("SDL_APP_WILLENTERBACKGROUND");
- break;
- case SDL_APP_WILLENTERFOREGROUND:
- logger->log("SDL_APP_WILLENTERFOREGROUND");
- break;
- case SDL_APP_DIDENTERFOREGROUND:
- logger->log("SDL_APP_DIDENTERFOREGROUND");
- break;
- case SDL_APP_DIDENTERBACKGROUND:
- logger->log("SDL_APP_DIDENTERBACKGROUND");
- break;
-#else
- case SDL_KEYDOWN:
- logger->log("event: SDL_KEYDOWN: %d,%d,%d", event.key.state,
- event.key.keysym.scancode, event.key.keysym.unicode);
- break;
- case SDL_KEYUP:
- logger->log("event: SDL_KEYUP: %d,%d,%d", event.key.state,
- event.key.keysym.scancode, event.key.keysym.unicode);
- break;
- case SDL_VIDEORESIZE:
- logger->log("event: SDL_VIDEORESIZE");
- break;
- case SDL_VIDEOEXPOSE:
- logger->log("event: SDL_VIDEOEXPOSE");
- break;
- case SDL_ACTIVEEVENT:
- logger->log("event: SDL_ACTIVEEVENT: %d %d",
- event.active.state, event.active.gain);
- break;
-#endif
- case SDL_MOUSEBUTTONDOWN:
- logger->log("event: SDL_MOUSEBUTTONDOWN: %d,%d,%d,%d",
- event.button.button, event.button.state,
- event.button.x, event.button.y);
- break;
- case SDL_MOUSEBUTTONUP:
- logger->log("event: SDL_MOUSEBUTTONUP: %d,%d,%d,%d",
- event.button.button, event.button.state,
- event.button.x, event.button.y);
- break;
- case SDL_JOYAXISMOTION:
- logger->log("event: SDL_JOYAXISMOTION: %d,%d,%d",
- event.jaxis.which, event.jaxis.axis, event.jaxis.value);
- break;
- case SDL_JOYBALLMOTION:
- logger->log("event: SDL_JOYBALLMOTION: %d,%d,%d,%d",
- event.jball.which, event.jball.ball,
- event.jball.xrel, event.jball.yrel);
- break;
- case SDL_JOYHATMOTION:
- logger->log("event: SDL_JOYHATMOTION: %d,%d,%d", event.jhat.which,
- event.jhat.hat, event.jhat.value);
- break;
- case SDL_JOYBUTTONDOWN:
- logger->log("event: SDL_JOYBUTTONDOWN: %d,%d,%d",
- event.jbutton.which, event.jbutton.button,
- event.jbutton.state);
- break;
- case SDL_JOYBUTTONUP:
- logger->log("event: SDL_JOYBUTTONUP: %d,%d,%d",
- event.jbutton.which, event.jbutton.button,
- event.jbutton.state);
- break;
- case SDL_QUIT:
- logger->log("event: SDL_QUIT");
- break;
- case SDL_SYSWMEVENT:
- logger->log("event: SDL_SYSWMEVENT");
- break;
- case SDL_USEREVENT:
- logger->log("event: SDL_USEREVENT");
- break;
-#ifdef ANDROID
-#ifndef USE_SDL2
- case SDL_ACCELEROMETER:
- logger->log("event: SDL_ACCELEROMETER");
- break;
-#endif
-#endif
- default:
- logger->log("event: other: %d", event.type);
- break;
- };
-}
-
void Client::windowRemoved(const Window *const window)
{
if (mCurrentDialog == window)
diff --git a/src/client.h b/src/client.h
index 957c49fed..d107632a5 100644
--- a/src/client.h
+++ b/src/client.h
@@ -336,8 +336,6 @@ public:
bool checkPackets(const int type) const A_WARN_UNUSED;
- static void logEvent(const SDL_Event &event);
-
PacketLimit mPacketLimits[PACKET_SIZE + 1];
void windowRemoved(const Window *const window);
@@ -448,7 +446,6 @@ private:
bool mInputFocused;
bool mMouseFocused;
bool mNewMessageFlag;
- bool mLogInput;
};
extern Client *client;
diff --git a/src/eventsmanager.cpp b/src/eventsmanager.cpp
new file mode 100644
index 000000000..8866b03db
--- /dev/null
+++ b/src/eventsmanager.cpp
@@ -0,0 +1,260 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "eventsmanager.h"
+
+#include "configuration.h"
+#include "logger.h"
+
+#include "debug.h"
+
+EventsManager eventsManager;
+
+EventsManager::EventsManager() :
+ mLogInput(false)
+{
+}
+
+void EventsManager::init()
+{
+ mLogInput = config.getBoolValue("logInput");
+ config.addListener("logInput", this);
+}
+
+bool EventsManager::handleEvent(const SDL_Event &event)
+{
+ if (mLogInput)
+ logEvent(event);
+ switch (event.type)
+ {
+ }
+
+ return false;
+}
+
+void EventsManager::optionChanged(const std::string &name)
+{
+ if (name == "logInput")
+ mLogInput = config.getBoolValue("logInput");
+}
+
+void EventsManager::logEvent(const SDL_Event &event)
+{
+ switch (event.type)
+ {
+ case SDL_MOUSEMOTION:
+ logger->log("event: SDL_MOUSEMOTION: %d,%d,%d",
+ event.motion.state, event.motion.x, event.motion.y);
+ break;
+#ifdef USE_SDL2
+#define winEventLog(name, name2) \
+ case name: \
+ str = name2; \
+ break
+
+ case SDL_FINGERDOWN:
+ {
+ const SDL_TouchFingerEvent &touch = event.tfinger;
+ const int w = mainGraphics->mWidth;
+ const int h = mainGraphics->mHeight;
+ logger->log("event: SDL_FINGERDOWN: %lld,%lld (%f,%f) (%f,%f)",
+ touch.touchId, touch.fingerId, touch.x * w, touch.y * w,
+ touch.dx * w, touch.dy * h);
+ break;
+ }
+ case SDL_FINGERUP:
+ {
+ const SDL_TouchFingerEvent &touch = event.tfinger;
+ const int w = mainGraphics->mWidth;
+ const int h = mainGraphics->mHeight;
+ logger->log("event: SDL_FINGERUP: %lld,%lld (%f,%f) (%f,%f)",
+ touch.touchId, touch.fingerId, touch.x * w, touch.y * h,
+ touch.dx * w, touch.dy * h);
+ break;
+ }
+ case SDL_FINGERMOTION:
+ {
+ const SDL_TouchFingerEvent &touch = event.tfinger;
+ const int w = mainGraphics->mWidth;
+ const int h = mainGraphics->mHeight;
+ logger->log("event: SDL_FINGERMOTION: %lld,%lld (%f,%f) (%f,%f)",
+ touch.touchId, touch.fingerId,
+ touch.x * w, touch.y * h,
+ touch.dx * w, touch.dy * h);
+ break;
+ }
+ case SDL_MULTIGESTURE:
+ {
+ const SDL_MultiGestureEvent &gesture = event.mgesture;
+ const int w = mainGraphics->mWidth;
+ const int h = mainGraphics->mHeight;
+ logger->log("event: SDL_MULTIGESTURE: %lld %f,%f (%f,%f) %d,%d",
+ gesture.touchId, gesture.dTheta, gesture.dDist,
+ gesture.x * w, gesture.y * h, (int)gesture.numFingers,
+ (int)gesture.padding);
+ break;
+ }
+ case SDL_KEYDOWN:
+ logger->log("event: SDL_KEYDOWN: %d,%d", event.key.state,
+ event.key.keysym.scancode);
+ break;
+ case SDL_KEYUP:
+ logger->log("event: SDL_KEYUP: %d,%d", event.key.state,
+ event.key.keysym.scancode);
+ break;
+ case SDL_WINDOWEVENT:
+ {
+ const int data1 = event.window.data1;
+ const int data2 = event.window.data2;
+ std::string str;
+ switch (event.window.event)
+ {
+ winEventLog(SDL_WINDOWEVENT_NONE, "SDL_WINDOWEVENT_NONE");
+ winEventLog(SDL_WINDOWEVENT_SHOWN, "SDL_WINDOWEVENT_SHOWN");
+ winEventLog(SDL_WINDOWEVENT_HIDDEN, "SDL_WINDOWEVENT_HIDDEN");
+ winEventLog(SDL_WINDOWEVENT_EXPOSED,
+ "SDL_WINDOWEVENT_EXPOSED");
+ winEventLog(SDL_WINDOWEVENT_MOVED, "SDL_WINDOWEVENT_MOVED");
+ winEventLog(SDL_WINDOWEVENT_RESIZED,
+ "SDL_WINDOWEVENT_RESIZED");
+ winEventLog(SDL_WINDOWEVENT_SIZE_CHANGED,
+ "SDL_WINDOWEVENT_SIZE_CHANGED");
+ winEventLog(SDL_WINDOWEVENT_MINIMIZED,
+ "SDL_WINDOWEVENT_MINIMIZED");
+ winEventLog(SDL_WINDOWEVENT_MAXIMIZED,
+ "SDL_WINDOWEVENT_MAXIMIZED");
+ winEventLog(SDL_WINDOWEVENT_RESTORED,
+ "SDL_WINDOWEVENT_RESTORED");
+ winEventLog(SDL_WINDOWEVENT_ENTER, "SDL_WINDOWEVENT_ENTER");
+ winEventLog(SDL_WINDOWEVENT_LEAVE, "SDL_WINDOWEVENT_LEAVE");
+ winEventLog(SDL_WINDOWEVENT_FOCUS_GAINED,
+ "SDL_WINDOWEVENT_FOCUS_GAINED");
+ winEventLog(SDL_WINDOWEVENT_FOCUS_LOST,
+ "SDL_WINDOWEVENT_FOCUS_LOST");
+ winEventLog(SDL_WINDOWEVENT_CLOSE, "SDL_WINDOWEVENT_CLOSE");
+ default:
+ str = "unknown";
+ break;
+ }
+ logger->log("event: SDL_WINDOWEVENT: %s: %d,%d",
+ str.c_str(), data1, data2);
+ break;
+ }
+ case SDL_TEXTINPUT:
+ {
+ const char *const text = event.text.text;
+ logger->log("event: SDL_TEXTINPUT: %s", text);
+ const int sz = strlen(event.text.text);
+ for (int f = 0; f < sz; f ++)
+ logger->log("dec: %d", text[f]);
+ break;
+ }
+ case SDL_APP_TERMINATING:
+ logger->log("SDL_APP_TERMINATING");
+ break;
+ case SDL_APP_LOWMEMORY:
+ logger->log("SDL_APP_LOWMEMORY");
+ break;
+ case SDL_APP_WILLENTERBACKGROUND:
+ logger->log("SDL_APP_WILLENTERBACKGROUND");
+ break;
+ case SDL_APP_WILLENTERFOREGROUND:
+ logger->log("SDL_APP_WILLENTERFOREGROUND");
+ break;
+ case SDL_APP_DIDENTERFOREGROUND:
+ logger->log("SDL_APP_DIDENTERFOREGROUND");
+ break;
+ case SDL_APP_DIDENTERBACKGROUND:
+ logger->log("SDL_APP_DIDENTERBACKGROUND");
+ break;
+#else
+ case SDL_KEYDOWN:
+ logger->log("event: SDL_KEYDOWN: %d,%d,%d", event.key.state,
+ event.key.keysym.scancode, event.key.keysym.unicode);
+ break;
+ case SDL_KEYUP:
+ logger->log("event: SDL_KEYUP: %d,%d,%d", event.key.state,
+ event.key.keysym.scancode, event.key.keysym.unicode);
+ break;
+ case SDL_VIDEORESIZE:
+ logger->log("event: SDL_VIDEORESIZE");
+ break;
+ case SDL_VIDEOEXPOSE:
+ logger->log("event: SDL_VIDEOEXPOSE");
+ break;
+ case SDL_ACTIVEEVENT:
+ logger->log("event: SDL_ACTIVEEVENT: %d %d",
+ event.active.state, event.active.gain);
+ break;
+#endif
+ case SDL_MOUSEBUTTONDOWN:
+ logger->log("event: SDL_MOUSEBUTTONDOWN: %d,%d,%d,%d",
+ event.button.button, event.button.state,
+ event.button.x, event.button.y);
+ break;
+ case SDL_MOUSEBUTTONUP:
+ logger->log("event: SDL_MOUSEBUTTONUP: %d,%d,%d,%d",
+ event.button.button, event.button.state,
+ event.button.x, event.button.y);
+ break;
+ case SDL_JOYAXISMOTION:
+ logger->log("event: SDL_JOYAXISMOTION: %d,%d,%d",
+ event.jaxis.which, event.jaxis.axis, event.jaxis.value);
+ break;
+ case SDL_JOYBALLMOTION:
+ logger->log("event: SDL_JOYBALLMOTION: %d,%d,%d,%d",
+ event.jball.which, event.jball.ball,
+ event.jball.xrel, event.jball.yrel);
+ break;
+ case SDL_JOYHATMOTION:
+ logger->log("event: SDL_JOYHATMOTION: %d,%d,%d", event.jhat.which,
+ event.jhat.hat, event.jhat.value);
+ break;
+ case SDL_JOYBUTTONDOWN:
+ logger->log("event: SDL_JOYBUTTONDOWN: %d,%d,%d",
+ event.jbutton.which, event.jbutton.button,
+ event.jbutton.state);
+ break;
+ case SDL_JOYBUTTONUP:
+ logger->log("event: SDL_JOYBUTTONUP: %d,%d,%d",
+ event.jbutton.which, event.jbutton.button,
+ event.jbutton.state);
+ break;
+ case SDL_QUIT:
+ logger->log("event: SDL_QUIT");
+ break;
+ case SDL_SYSWMEVENT:
+ logger->log("event: SDL_SYSWMEVENT");
+ break;
+ case SDL_USEREVENT:
+ logger->log("event: SDL_USEREVENT");
+ break;
+#ifdef ANDROID
+#ifndef USE_SDL2
+ case SDL_ACCELEROMETER:
+ logger->log("event: SDL_ACCELEROMETER");
+ break;
+#endif
+#endif
+ default:
+ logger->log("event: other: %d", event.type);
+ break;
+ };
+}
diff --git a/src/eventsmanager.h b/src/eventsmanager.h
new file mode 100644
index 000000000..f5e214d11
--- /dev/null
+++ b/src/eventsmanager.h
@@ -0,0 +1,54 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EVENTSMANAGER_H
+#define EVENTSMANAGER_H
+
+#include "configlistener.h"
+
+#include <string>
+#include <map>
+
+#include <SDL_events.h>
+
+#include "localconsts.h"
+
+class EventsManager final : public ConfigListener
+{
+ public:
+ EventsManager();
+
+ A_DELETE_COPY(EventsManager)
+
+ void init();
+
+ bool handleEvent(const SDL_Event &event);
+
+ void optionChanged(const std::string &name);
+
+ void logEvent(const SDL_Event &event);
+
+ protected:
+ bool mLogInput;
+};
+
+extern EventsManager eventsManager;
+
+#endif // EVENTSMANAGER_H
diff --git a/src/game.cpp b/src/game.cpp
index c3d0aa36f..0cc8da764 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -32,6 +32,7 @@
#include "configuration.h"
#include "effectmanager.h"
#include "emoteshortcut.h"
+#include "eventsmanager.h"
#include "guildmanager.h"
#include "itemshortcut.h"
#include "soundmanager.h"
@@ -390,7 +391,6 @@ Game::Game():
mAdjustPerfomance(config.getBoolValue("adjustPerfomance")),
mLowerCounter(0),
mPing(0),
- mLogInput(config.getBoolValue("logInput")),
mTime(cur_time + 1)
{
touchManager.setInGame(true);
@@ -1018,8 +1018,9 @@ void Game::handleInput()
#endif
{
BLOCK_START("Game::handleInput 2")
- if (mLogInput)
- Client::logEvent(event);
+ if (eventsManager.handleEvent(event))
+ continue;
+
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
updateHistory(event);
checkKeys();
diff --git a/src/game.h b/src/game.h
index b7db9c7b9..1d7c6821f 100644
--- a/src/game.h
+++ b/src/game.h
@@ -140,7 +140,6 @@ class Game final
bool mAdjustPerfomance;
int mLowerCounter;
int mPing;
- bool mLogInput;
int mTime;
static Game *mInstance;