KEYMAPPER: Make engine keymap init and cleanup more generic

This commit is contained in:
Tarek Soliman 2011-12-30 11:50:15 -06:00
parent b3f265696f
commit 40b68b41c7
4 changed files with 23 additions and 8 deletions

View file

@ -203,6 +203,9 @@ static Common::Error runGame(const EnginePlugin *plugin, OSystem &system, const
warning(_("Engine does not support debug level '%s'"), token.c_str()); warning(_("Engine does not support debug level '%s'"), token.c_str());
} }
// Initialize any game-specific keymaps
engine->initKeymap();
// Inform backend that the engine is about to be run // Inform backend that the engine is about to be run
system.engineInit(); system.engineInit();
@ -212,6 +215,9 @@ static Common::Error runGame(const EnginePlugin *plugin, OSystem &system, const
// Inform backend that the engine finished // Inform backend that the engine finished
system.engineDone(); system.engineDone();
// Clean up any game-specific keymaps
engine->deinitKeymap();
// Free up memory // Free up memory
delete engine; delete engine;

View file

@ -45,6 +45,8 @@
#include "common/textconsole.h" #include "common/textconsole.h"
#include "common/translation.h" #include "common/translation.h"
#include "backends/keymapper/keymapper.h"
#include "gui/debugger.h" #include "gui/debugger.h"
#include "gui/dialog.h" #include "gui/dialog.h"
#include "gui/message.h" #include "gui/message.h"
@ -499,6 +501,12 @@ void Engine::syncSoundSettings() {
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, soundVolumeSpeech); _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, soundVolumeSpeech);
} }
void Engine::deinitKeymap() {
#ifdef ENABLE_KEYMAPPER
_eventMan->getKeymapper()->cleanupGameKeymaps();
#endif
}
void Engine::flipMute() { void Engine::flipMute() {
// Mute will be set to true by default here. This has two reasons: // Mute will be set to true by default here. This has two reasons:
// - if the game already has an "mute" config entry, it will be overwritten anyway. // - if the game already has an "mute" config entry, it will be overwritten anyway.

View file

@ -181,10 +181,15 @@ public:
virtual void syncSoundSettings(); virtual void syncSoundSettings();
/* /*
* Initialize the engine-specific keymap * Initialize any engine-specific keymaps.
*/ */
virtual void initKeymap() {} virtual void initKeymap() {}
/*
* Cleanup any engine-specific keymaps.
*/
virtual void deinitKeymap();
/** /**
* Flip mute all sound option. * Flip mute all sound option.
*/ */

View file

@ -212,10 +212,6 @@ LoLEngine::~LoLEngine() {
setupPrologueData(false); setupPrologueData(false);
releaseTempData(); releaseTempData();
#ifdef ENABLE_KEYMAPPER
_eventMan->getKeymapper()->cleanupGameKeymaps();
#endif
delete[] _landsFile; delete[] _landsFile;
delete[] _levelLangFile; delete[] _levelLangFile;
@ -461,7 +457,9 @@ Common::Error LoLEngine::init() {
_spellProcs.push_back(new SpellProc(this, 0)); _spellProcs.push_back(new SpellProc(this, 0));
_spellProcs.push_back(new SpellProc(this, &LoLEngine::castGuardian)); _spellProcs.push_back(new SpellProc(this, &LoLEngine::castGuardian));
initKeymap(); #ifdef ENABLE_KEYMAPPER
_eventMan->getKeymapper()->pushKeymap(kKeymapName, true);
#endif
return Common::kNoError; return Common::kNoError;
} }
@ -503,8 +501,6 @@ void LoLEngine::initKeymap() {
mapper->addGameKeymap(engineKeyMap); mapper->addGameKeymap(engineKeyMap);
mapper->pushKeymap(kKeymapName, true);
#endif #endif
} }