Engines: Fused several init&go methods into a single run method

svn-id: r39003
This commit is contained in:
Max Horn 2009-03-01 04:42:46 +00:00
parent 3fcbda829a
commit dd98126423
28 changed files with 128 additions and 295 deletions

View File

@ -74,7 +74,7 @@ CineEngine::~CineEngine() {
Common::clearAllDebugChannels();
}
Common::Error CineEngine::init() {
Common::Error CineEngine::run() {
// Initialize backend
initGraphics(320, 200, false);
@ -88,10 +88,6 @@ Common::Error CineEngine::init() {
initialize();
return Common::kNoError;
}
Common::Error CineEngine::go() {
CursorMan.showMouse(true);
mainLoop(1);

View File

@ -71,15 +71,7 @@ class CineEngine : public Engine {
protected:
// Engine APIs
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
virtual bool hasFeature(EngineFeature f) const;
void shutdown();

View File

@ -71,7 +71,7 @@ CruiseEngine::~CruiseEngine() {
freeSystem();
}
Common::Error CruiseEngine::init() {
Common::Error CruiseEngine::run() {
// Initialize backend
initGraphics(320, 200, false);
@ -80,10 +80,6 @@ Common::Error CruiseEngine::init() {
initialize();
return Common::kNoError;
}
Common::Error CruiseEngine::go() {
Cruise::changeCursor(Cruise::CURSOR_NORMAL);
CursorMan.showMouse(true);

View File

@ -61,15 +61,7 @@ private:
protected:
// Engine APIs
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
void shutdown();

View File

@ -54,9 +54,42 @@ static const GameSettings drasculaSettings[] = {
DrasculaEngine::DrasculaEngine(OSystem *syst, const DrasculaGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
// Setup mixer
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
_charMap = 0;
_itemLocations = 0;
_polX = 0;
_polY = 0;
_verbBarX = 0;
_x1d_menu = 0;
_y1d_menu = 0;
_frameX = 0;
_candleX = 0;
_candleY = 0;
_pianistX = 0;
_drunkX = 0;
_roomPreUpdates = 0;
_roomUpdates = 0;
_roomActions = 0;
_text = 0;
_textd = 0;
_textb = 0;
_textbj = 0;
_texte = 0;
_texti = 0;
_textl = 0;
_textp = 0;
_textt = 0;
_textvb = 0;
_textsys = 0;
_texthis = 0;
_textverbs = 0;
_textmisc = 0;
_textd1 = 0;
_color = 0;
blinking = 0;
leftMouseButton = 0;
rightMouseButton = 0;
*textName = 0;
_rnd = new Common::RandomSource();
syst->getEventManager()->registerRandomSource(*_rnd, "drascula");
@ -106,7 +139,7 @@ DrasculaEngine::~DrasculaEngine() {
freeTexts(_textd1);
}
Common::Error DrasculaEngine::init() {
Common::Error DrasculaEngine::run() {
// Initialize backend
initGraphics(320, 200, false);
@ -131,53 +164,16 @@ Common::Error DrasculaEngine::init() {
_lang = kEnglish;
}
_charMap = 0;
_itemLocations = 0;
_polX = 0;
_polY = 0;
_verbBarX = 0;
_x1d_menu = 0;
_y1d_menu = 0;
_frameX = 0;
_candleX = 0;
_candleY = 0;
_pianistX = 0;
_drunkX = 0;
_roomPreUpdates = 0;
_roomUpdates = 0;
_roomActions = 0;
_text = 0;
_textd = 0;
_textb = 0;
_textbj = 0;
_texte = 0;
_texti = 0;
_textl = 0;
_textp = 0;
_textt = 0;
_textvb = 0;
_textsys = 0;
_texthis = 0;
_textverbs = 0;
_textmisc = 0;
_textd1 = 0;
_color = 0;
blinking = 0;
leftMouseButton = 0;
rightMouseButton = 0;
*textName = 0;
if (!loadDrasculaDat())
return Common::kUnknownError;
setupRoomsTable();
loadArchives();
return Common::kNoError;
}
// Setup mixer
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
Common::Error DrasculaEngine::go() {
currentChapter = 1; // values from 1 to 6 will start each part of game
loadedDifferentChapter = 0;

View File

@ -276,15 +276,7 @@ static const int interf_y[] ={ 51, 51, 51, 51, 83, 83, 83 };
class DrasculaEngine : public ::Engine {
protected:
// Engine APIs
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
public:
DrasculaEngine(OSystem *syst, const DrasculaGameDescription *gameDesc);

View File

@ -110,12 +110,6 @@ GobEngine::~GobEngine() {
delete[] _startTot0;
}
Common::Error GobEngine::go() {
_init->initGame(0);
return Common::kNoError;
}
const char *GobEngine::getLangDesc(int16 language) const {
if ((language < 0) || (language > 10))
language = 2;
@ -177,7 +171,7 @@ bool GobEngine::hasAdlib() const {
return (_features & kFeaturesAdlib) != 0;
}
Common::Error GobEngine::init() {
Common::Error GobEngine::run() {
if (!initGameParts()) {
GUIErrorMessage("GobEngine::init(): Unknown version of game engine");
return Common::kUnknownError;
@ -255,6 +249,8 @@ Common::Error GobEngine::init() {
}
_global->_languageWanted = _global->_language;
_init->initGame(0);
return Common::kNoError;
}

View File

@ -191,15 +191,7 @@ private:
uint32 _pauseStart;
// Engine APIs
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
virtual bool hasFeature(EngineFeature f) const;
virtual void pauseEngineIntern(bool pause);

View File

@ -88,13 +88,6 @@ IgorEngine::~IgorEngine() {
delete _midiPlayer;
}
Common::Error IgorEngine::init() {
initGraphics(320, 200, false);
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
return Common::kNoError;
}
void IgorEngine::restart() {
_screenVGAVOffset = 0;
@ -166,7 +159,10 @@ void IgorEngine::restart() {
_gameTicks = 0;
}
Common::Error IgorEngine::go() {
Common::Error IgorEngine::run() {
initGraphics(320, 200, false);
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
restart();
setupDefaultPalette();
_currentPart = ConfMan.getInt("boot_param");

View File

@ -312,15 +312,8 @@ public:
IgorEngine(OSystem *system, const DetectedGameVersion *dgv);
virtual ~IgorEngine();
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
// Engine APIs
virtual Common::Error run();
void handleOptionsMenu_paintSave();
bool handleOptionsMenu_handleKeyDownSave(int key);

View File

@ -141,7 +141,7 @@ M4Engine::~M4Engine() {
delete _resourceManager;
}
Common::Error M4Engine::init() {
Common::Error M4Engine::run() {
// Initialize backend
if (isM4())
initGraphics(640, 480, true);
@ -194,7 +194,10 @@ Common::Error M4Engine::init() {
_random = new Common::RandomSource();
g_system->getEventManager()->registerRandomSource(*_random, "m4");
return Common::kNoError;
if (isM4())
return goM4();
else
return goMADS();
}
void M4Engine::eventHandler() {
@ -269,13 +272,6 @@ void M4Engine::loadMenu(MenuType menuType, bool loadSaveFromHotkey, bool calledF
_viewManager->moveToFront(view);
}
Common::Error M4Engine::go() {
if (isM4())
return goM4();
else
return goMADS();
}
Common::Error M4Engine::goMADS() {
_palette->setMadsSystemPalette();

View File

@ -112,15 +112,7 @@ private:
protected:
// Engine APIs
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
void shutdown();

View File

@ -135,13 +135,6 @@ MadeEngine::~MadeEngine() {
delete _music;
}
Common::Error MadeEngine::init() {
// Initialize backend
initGraphics(320, 200, false);
return Common::kNoError;
}
void MadeEngine::syncSoundSettings() {
_music->setVolume(ConfMan.getInt("music_volume"));
_mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, ConfMan.getInt("sfx_volume"));
@ -247,7 +240,10 @@ void MadeEngine::handleEvents() {
}
Common::Error MadeEngine::go() {
Common::Error MadeEngine::run() {
// Initialize backend
initGraphics(320, 200, false);
resetAllTimers();

View File

@ -80,15 +80,7 @@ class MadeEngine : public ::Engine {
protected:
// Engine APIs
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
public:
MadeEngine(OSystem *syst, const MadeGameDescription *gameDesc);

View File

@ -444,35 +444,7 @@ GUI::Debugger *QueenEngine::getDebugger() {
return _debugger;
}
Common::Error QueenEngine::go() {
_logic->start();
if (ConfMan.hasKey("save_slot") && canLoadOrSave()) {
loadGameState(ConfMan.getInt("save_slot"));
}
_lastSaveTime = _lastUpdateTime = _system->getMillis();
while (!shouldQuit()) {
if (_logic->newRoom() > 0) {
_logic->update();
_logic->oldRoom(_logic->currentRoom());
_logic->currentRoom(_logic->newRoom());
_logic->changeRoom();
_display->fullscreen(false);
if (_logic->currentRoom() == _logic->newRoom()) {
_logic->newRoom(0);
}
} else if (_logic->joeWalk() == JWM_EXECUTE) {
_logic->joeWalk(JWM_NORMAL);
_command->executeCurrentAction();
} else {
_logic->joeWalk(JWM_NORMAL);
update(true);
}
}
return Common::kNoError;
}
Common::Error QueenEngine::init() {
Common::Error QueenEngine::run() {
initGraphics(GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT, false);
_resource = new Resource();
@ -501,6 +473,31 @@ Common::Error QueenEngine::init() {
registerDefaultSettings();
readOptionSettings();
_logic->start();
if (ConfMan.hasKey("save_slot") && canLoadOrSave()) {
loadGameState(ConfMan.getInt("save_slot"));
}
_lastSaveTime = _lastUpdateTime = _system->getMillis();
while (!shouldQuit()) {
if (_logic->newRoom() > 0) {
_logic->update();
_logic->oldRoom(_logic->currentRoom());
_logic->currentRoom(_logic->newRoom());
_logic->changeRoom();
_display->fullscreen(false);
if (_logic->currentRoom() == _logic->newRoom()) {
_logic->newRoom(0);
}
} else if (_logic->joeWalk() == JWM_EXECUTE) {
_logic->joeWalk(JWM_NORMAL);
_command->executeCurrentAction();
} else {
_logic->joeWalk(JWM_NORMAL);
update(true);
}
}
return Common::kNoError;
}

View File

@ -129,15 +129,7 @@ public:
protected:
// Engine APIs
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
virtual GUI::Debugger *getDebugger();
virtual bool hasFeature(EngineFeature f) const;
virtual void syncSoundSettings();

View File

@ -147,7 +147,7 @@ SagaEngine::~SagaEngine() {
delete _resource;
}
Common::Error SagaEngine::init() {
Common::Error SagaEngine::run() {
// Assign default values to the config manager, in case settings are missing
ConfMan.registerDefault("talkspeed", "255");
ConfMan.registerDefault("subtitles", "true");
@ -279,10 +279,6 @@ Common::Error SagaEngine::init() {
_system->setFeatureState(OSystem::kFeatureAutoComputeDirtyRects, true);
#endif
return Common::kNoError;
}
Common::Error SagaEngine::go() {
int msec = 0;
_previousTicks = _system->getMillis();

View File

@ -443,15 +443,7 @@ class SagaEngine : public Engine {
public:
// Engine APIs
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
bool hasFeature(EngineFeature f) const;
void syncSoundSettings();
void pauseEngineIntern(bool pause);

View File

@ -170,7 +170,7 @@ SciEngine::~SciEngine() {
delete _console;
}
Common::Error SciEngine::init() {
Common::Error SciEngine::run() {
initGraphics(320, 200, false);
// Create debugger console. It requires GFX to be initialized
@ -178,11 +178,6 @@ Common::Error SciEngine::init() {
// Additional setup.
printf("SciEngine::init\n");
return Common::kNoError;
}
Common::Error SciEngine::go() {
// Your main even loop should be (invoked from) here.
/* bool end = false;
Common::EventManager *em = _system->getEventManager();

View File

@ -76,17 +76,9 @@ public:
SciEngine(OSystem *syst, const SciGameDescription *desc);
~SciEngine();
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
GUI::Debugger *getDebugger() { return _console; }
// Engine APIs
virtual Common::Error run();
virtual GUI::Debugger *getDebugger() { return _console; }
const char* getGameID() const;
int getResourceVersion() const;

View File

@ -361,7 +361,7 @@ void Sword2Engine::setupPersistentResources() {
_resman->openResource(CUR_PLAYER_ID);
}
Common::Error Sword2Engine::init() {
Common::Error Sword2Engine::run() {
// Get some falling RAM and put it in your pocket, never let it slip
// away
@ -445,10 +445,6 @@ Common::Error Sword2Engine::init() {
_screen->initialiseRenderCycle();
return Common::kNoError;
}
Common::Error Sword2Engine::go() {
while (1) {
if (_debugger->isAttached())
_debugger->onFrame();

View File

@ -124,15 +124,7 @@ private:
protected:
// Engine APIs
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
virtual GUI::Debugger *getDebugger();
virtual bool hasFeature(EngineFeature f) const;
virtual void syncSoundSettings();

View File

@ -916,7 +916,24 @@ TinselEngine::~TinselEngine() {
delete _scheduler;
}
Common::Error TinselEngine::init() {
void TinselEngine::syncSoundSettings() {
// Sync the engine with the config manager
int soundVolumeMusic = ConfMan.getInt("music_volume");
int soundVolumeSFX = ConfMan.getInt("sfx_volume");
int soundVolumeSpeech = ConfMan.getInt("speech_volume");
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic);
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, soundVolumeSFX);
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, soundVolumeSpeech);
}
Common::String TinselEngine::getSavegameFilename(int16 saveNum) const {
char filename[256];
snprintf(filename, 256, "%s.%03d", getTargetName().c_str(), saveNum);
return filename;
}
Common::Error TinselEngine::run() {
// Initialize backend
if (getGameID() == GID_DW2) {
#ifndef DW2_EXACT_SIZE
@ -971,29 +988,6 @@ Common::Error TinselEngine::init() {
// Actors, globals and inventory icons
LoadBasicChunks();
return Common::kNoError;
}
void TinselEngine::syncSoundSettings() {
// Sync the engine with the config manager
int soundVolumeMusic = ConfMan.getInt("music_volume");
int soundVolumeSFX = ConfMan.getInt("sfx_volume");
int soundVolumeSpeech = ConfMan.getInt("speech_volume");
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic);
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, soundVolumeSFX);
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, soundVolumeSpeech);
}
Common::String TinselEngine::getSavegameFilename(int16 saveNum) const {
char filename[256];
snprintf(filename, 256, "%s.%03d", getTargetName().c_str(), saveNum);
return filename;
}
Common::Error TinselEngine::go() {
uint32 timerVal = 0;
// Continuous game processes
CreateConstProcesses();
@ -1013,7 +1007,7 @@ Common::Error TinselEngine::go() {
}
// Foreground loop
uint32 timerVal = 0;
while (!shouldQuit()) {
assert(_console);
if (_console->isAttached())

View File

@ -141,15 +141,7 @@ class TinselEngine : public Engine {
protected:
// Engine APIs
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
virtual bool hasFeature(EngineFeature f) const;
Common::Error loadGameState(int slot);
#if 0

View File

@ -81,7 +81,7 @@ ToucheEngine::~ToucheEngine() {
delete _midiPlayer;
}
Common::Error ToucheEngine::init() {
Common::Error ToucheEngine::run() {
initGraphics(kScreenWidth, kScreenHeight, true);
Graphics::setupFont(_language);
@ -93,10 +93,7 @@ Common::Error ToucheEngine::init() {
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
return Common::kNoError;
}
Common::Error ToucheEngine::go() {
res_openDataFile();
res_allocateTables();
res_loadSpriteImage(18, _menuKitData);

View File

@ -370,15 +370,7 @@ public:
virtual ~ToucheEngine();
// Engine APIs
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
virtual bool hasFeature(EngineFeature f) const;
virtual void syncSoundSettings();

View File

@ -41,12 +41,6 @@ TuckerEngine::TuckerEngine(OSystem *system, Common::Language language, uint32 fl
TuckerEngine::~TuckerEngine() {
}
Common::Error TuckerEngine::init() {
initGraphics(kScreenWidth, kScreenHeight, false);
syncSoundSettings();
return Common::kNoError;
}
bool TuckerEngine::hasFeature(EngineFeature f) const {
switch (f) {
case kSupportsRTL:
@ -58,7 +52,10 @@ bool TuckerEngine::hasFeature(EngineFeature f) const {
}
}
Common::Error TuckerEngine::go() {
Common::Error TuckerEngine::run() {
initGraphics(kScreenWidth, kScreenHeight, false);
syncSoundSettings();
handleIntroSequence();
if ((_gameFlags & kGameFlagIntroOnly) == 0 && !shouldQuit()) {
mainLoop();

View File

@ -240,15 +240,7 @@ public:
TuckerEngine(OSystem *system, Common::Language language, uint32 flags);
virtual ~TuckerEngine();
Common::Error init();
Common::Error go();
virtual Common::Error run() {
Common::Error err;
err = init();
if (err != Common::kNoError)
return err;
return go();
}
virtual Common::Error run();
virtual bool hasFeature(EngineFeature f) const;
virtual void syncSoundSettings();