From 5aca9dce8c6cce89df3147a6f942620155010c8d Mon Sep 17 00:00:00 2001 From: Gregory Montoir Date: Sun, 1 Apr 2007 17:36:13 +0000 Subject: [PATCH] added the instance of EventManager returned by OSystem::getEventManager as a member of the Engine base class. This allows to simply the code a bit and should more efficient too (ie. less virtual function chain calls, obj->getA()->getB()). Also updated several engines to make use of it. svn-id: r26357 --- engines/agi/agi.cpp | 3 +-- engines/agos/cursor.cpp | 2 +- engines/agos/event.cpp | 3 +-- engines/engine.cpp | 1 + engines/engine.h | 2 ++ engines/kyra/gui.cpp | 6 ++---- engines/kyra/kyra.cpp | 8 +++----- engines/kyra/sequences_v1.cpp | 3 +-- engines/kyra/text.cpp | 3 +-- engines/saga/input.cpp | 5 ++--- engines/scumm/input.cpp | 3 +-- engines/scumm/scumm.cpp | 3 +-- engines/sky/sky.cpp | 3 +-- engines/sword1/sword1.cpp | 3 +-- engines/sword2/sword2.cpp | 3 +-- engines/touche/touche.cpp | 6 ++---- engines/touche/touche.h | 2 +- 17 files changed, 23 insertions(+), 36 deletions(-) diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp index be46647b58a..626ba8f7fe8 100644 --- a/engines/agi/agi.cpp +++ b/engines/agi/agi.cpp @@ -61,8 +61,7 @@ void AgiEngine::processEvents() { Common::Event event; int key = 0; - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_QUIT: _gfx->deinitVideo(); diff --git a/engines/agos/cursor.cpp b/engines/agos/cursor.cpp index efed42202b4..33471f2e432 100644 --- a/engines/agos/cursor.cpp +++ b/engines/agos/cursor.cpp @@ -309,7 +309,7 @@ void AGOSEngine::handleMouseMoved() { } CursorMan.showMouse(true); - _mouse = _system->getEventManager()->getMousePos(); + _mouse = _eventMan->getMousePos(); if (_defaultVerb) { uint id = 101; diff --git a/engines/agos/event.cpp b/engines/agos/event.cpp index 6f465e8390c..93ab997e648 100644 --- a/engines/agos/event.cpp +++ b/engines/agos/event.cpp @@ -332,8 +332,7 @@ void AGOSEngine::delay(uint amount) { _inCallBack = false; } - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: if (event.kbd.keycode >= '0' && event.kbd.keycode <='9' diff --git a/engines/engine.cpp b/engines/engine.cpp index 0d870e51cd4..5eca4cfa253 100644 --- a/engines/engine.cpp +++ b/engines/engine.cpp @@ -48,6 +48,7 @@ Engine::Engine(OSystem *syst) : _system(syst), _mixer(_system->getMixer()), _timer(_system->getTimerManager()), + _eventMan(_system->getEventManager()), _saveFileMan(_system->getSavefileManager()), _targetName(ConfMan.getActiveDomainName()), _gameDataPath(ConfMan.get("path")) { diff --git a/engines/engine.h b/engines/engine.h index 62da2cc3ff5..37cf63e88b9 100644 --- a/engines/engine.h +++ b/engines/engine.h @@ -31,6 +31,7 @@ namespace Audio { class Mixer; } namespace Common { + class EventManager; class SaveFileManager; class TimerManager; } @@ -45,6 +46,7 @@ public: Common::TimerManager * _timer; protected: + Common::EventManager *_eventMan; Common::SaveFileManager *_saveFileMan; const Common::String _targetName; // target name for saves diff --git a/engines/kyra/gui.cpp b/engines/kyra/gui.cpp index 3573157277a..c9b8b045c26 100644 --- a/engines/kyra/gui.cpp +++ b/engines/kyra/gui.cpp @@ -811,8 +811,7 @@ void KyraEngine::gui_getInput() { uint32 now = _system->getMillis(); _mouseWheel = 0; - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_QUIT: quitGame(); @@ -1487,8 +1486,7 @@ void KyraEngine::gui_updateMainMenuAnimation() { bool KyraEngine::gui_mainMenuGetInput() { Common::Event event; - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_QUIT: quitGame(); diff --git a/engines/kyra/kyra.cpp b/engines/kyra/kyra.cpp index 6b3a2dc3a1c..aba461a2316 100644 --- a/engines/kyra/kyra.cpp +++ b/engines/kyra/kyra.cpp @@ -608,8 +608,7 @@ void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) { uint32 start = _system->getMillis(); do { - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: if (event.kbd.keycode >= '1' && event.kbd.keycode <= '9' && @@ -690,7 +689,7 @@ void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) { } Common::Point KyraEngine::getMousePos() const { - Common::Point mouse = g_system->getEventManager()->getMousePos(); + Common::Point mouse = _eventMan->getMousePos(); if (_flags.useHiResOverlay) { mouse.x >>= 1; mouse.y >>= 1; @@ -702,8 +701,7 @@ void KyraEngine::waitForEvent() { bool finished = false; Common::Event event; while (!finished && !_quitFlag) { - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: finished = true; diff --git a/engines/kyra/sequences_v1.cpp b/engines/kyra/sequences_v1.cpp index 7503462dd23..771949b852a 100644 --- a/engines/kyra/sequences_v1.cpp +++ b/engines/kyra/sequences_v1.cpp @@ -1171,8 +1171,7 @@ void KyraEngine::seq_playCredits() { _screen->updateScreen(); } - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: finished = true; diff --git a/engines/kyra/text.cpp b/engines/kyra/text.cpp index 4bc9bfc6294..dd536a87ae9 100644 --- a/engines/kyra/text.cpp +++ b/engines/kyra/text.cpp @@ -118,8 +118,7 @@ void KyraEngine::waitForChatToFinish(int vocFile, int16 chatDuration, const char uint32 nextTime = loopStart + _tickLength; while (_system->getMillis() < nextTime) { - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: if (event.kbd.keycode == '.') diff --git a/engines/saga/input.cpp b/engines/saga/input.cpp index 3f9495ce8cd..e0216ba2fa9 100644 --- a/engines/saga/input.cpp +++ b/engines/saga/input.cpp @@ -40,8 +40,7 @@ namespace Saga { int SagaEngine::processInput() { Common::Event event; - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: if (event.kbd.flags == Common::KBD_CTRL) { @@ -153,7 +152,7 @@ int SagaEngine::processInput() { } Point SagaEngine::mousePos() const { - return _system->getEventManager()->getMousePos(); + return _eventMan->getMousePos(); } } // End of namespace Saga diff --git a/engines/scumm/input.cpp b/engines/scumm/input.cpp index 4b317098f4e..54feafb115e 100644 --- a/engines/scumm/input.cpp +++ b/engines/scumm/input.cpp @@ -57,8 +57,7 @@ enum MouseButtonStatus { void ScummEngine::parseEvents() { Common::Event event; - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp index 5298593a1e0..9ff08d7e5be 100644 --- a/engines/scumm/scumm.cpp +++ b/engines/scumm/scumm.cpp @@ -851,8 +851,7 @@ int ScummEngine_vCUPhe::go() { void ScummEngine_vCUPhe::parseEvents() { Common::Event event; - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_QUIT: _quit = true; diff --git a/engines/sky/sky.cpp b/engines/sky/sky.cpp index 7cf1566f358..195aa240e2d 100644 --- a/engines/sky/sky.cpp +++ b/engines/sky/sky.cpp @@ -511,7 +511,6 @@ void SkyEngine::gotTimerTick(void) { void SkyEngine::delay(int32 amount) { - Common::EventManager *eventMan = _system->getEventManager(); Common::Event event; uint32 start = _system->getMillis(); @@ -521,7 +520,7 @@ void SkyEngine::delay(int32 amount) { amount = 0; do { - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: _keyFlags = event.kbd.flags; diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp index 7a783c63b3a..751fb0f1aca 100644 --- a/engines/sword1/sword1.cpp +++ b/engines/sword1/sword1.cpp @@ -706,8 +706,7 @@ void SwordEngine::delay(int32 amount) { //copied and mutilated from sky.cpp uint32 start = _system->getMillis(); do { - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: // Make sure backspace works right (this fixes a small issue on OS X) diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp index 075c0123c26..8f49bba8397 100644 --- a/engines/sword2/sword2.cpp +++ b/engines/sword2/sword2.cpp @@ -534,8 +534,7 @@ uint32 Sword2Engine::setInputEventFilter(uint32 filter) { void Sword2Engine::parseInputEvents() { Common::Event event; - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { + while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_KEYDOWN: if (event.kbd.flags == Common::KBD_CTRL) { diff --git a/engines/touche/touche.cpp b/engines/touche/touche.cpp index 895bb0da6c9..54503f22350 100644 --- a/engines/touche/touche.cpp +++ b/engines/touche/touche.cpp @@ -237,10 +237,8 @@ void ToucheEngine::writeConfigurationSettings() { ConfMan.flushToDisk(); } -Common::Point ToucheEngine::getMousePos() { - Common::EventManager *eventMan = _system->getEventManager(); - - return eventMan->getMousePos(); +Common::Point ToucheEngine::getMousePos() const { + return _eventMan->getMousePos(); } void ToucheEngine::mainLoop() { diff --git a/engines/touche/touche.h b/engines/touche/touche.h index 371f55d9bb6..04fb42d80a9 100644 --- a/engines/touche/touche.h +++ b/engines/touche/touche.h @@ -611,7 +611,7 @@ protected: int displayQuitDialog(); void displayTextMode(int str); - Common::Point getMousePos(); + Common::Point getMousePos() const; MidiPlayer *_midiPlayer;