diff options
author | Max Horn | 2004-11-23 00:03:25 +0000 |
---|---|---|
committer | Max Horn | 2004-11-23 00:03:25 +0000 |
commit | aad9f122c0c37b152e70a01da48dc86a441ef819 (patch) | |
tree | a8dbee1f4e1e57de1ee5088e707f295df4986d12 /base | |
parent | 8ac347fd952a3811e6a948dfca3dec081882c335 (diff) | |
download | scummvm-rg350-aad9f122c0c37b152e70a01da48dc86a441ef819.tar.gz scummvm-rg350-aad9f122c0c37b152e70a01da48dc86a441ef819.tar.bz2 scummvm-rg350-aad9f122c0c37b152e70a01da48dc86a441ef819.zip |
Added Engine::init() method; added return value to Engine::go()
svn-id: r15865
Diffstat (limited to 'base')
-rw-r--r-- | base/engine.h | 15 | ||||
-rw-r--r-- | base/main.cpp | 61 |
2 files changed, 43 insertions, 33 deletions
diff --git a/base/engine.h b/base/engine.h index 509d8cd526..3774c52ac8 100644 --- a/base/engine.h +++ b/base/engine.h @@ -41,9 +41,20 @@ protected: public: Engine(OSystem *syst); virtual ~Engine(); + + /** + * Init the engine. + * @return 0 for success, else an error code. + */ + virtual int init() = 0; - /** Start the main engine loop. */ - virtual void go() = 0; + /** + * Start the main engine loop. + * The return value is not yet used, but could indicate whether the user + * wants to return to the launch or to fully quit ScummVM. + * @return a result code + */ + virtual int go() = 0; /** Get the path to the save game directory. */ virtual const char *getSavePath() const; diff --git a/base/main.cpp b/base/main.cpp index 15870d7a0b..695df68546 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -190,11 +190,7 @@ static int launcherDialog(GameDetector &detector, OSystem *system) { // Set the user specified graphics mode (if any). system->setGraphicsMode(ConfMan.get("gfx_mode").c_str()); - // FIXME - we need to call initSize() here so that we can display for example - // the launcher dialog. But the Engine object will also call it again (possibly - // with a different widht/height!9 However, this method is not for all OSystem - // implementations reentrant (it is so now for the SDL backend). Thus we need - // to fix all backends to support it, if they don't already. + // GUI is (currently) always running at 320x200 system->initSize(320, 200); system->endGFXTransaction(); @@ -239,7 +235,7 @@ static int launcherDialog(GameDetector &detector, OSystem *system) { return dlg.runModal(); } -static void runGame(GameDetector &detector, OSystem *system) { +static int runGame(GameDetector &detector, OSystem *system) { // Set the window caption to the game name Common::String caption(ConfMan.get("description", detector._targetName)); @@ -256,6 +252,20 @@ static void runGame(GameDetector &detector, OSystem *system) { !scumm_stricmp(ConfMan.get("gfx_mode", detector._targetName).c_str(), "normal") || !scumm_stricmp(ConfMan.get("gfx_mode", detector._targetName).c_str(), "default"); + // Create the game engine + Engine *engine = detector.createEngine(system); + assert(engine); + + // Add extrapath (if any) to the directory search list + if (ConfMan.hasKey("extrapath")) + File::addDefaultDirectory(ConfMan.get("extrapath")); + + if (ConfMan.hasKey("extrapath", Common::ConfigManager::kApplicationDomain)) + File::addDefaultDirectory(ConfMan.get("extrapath", Common::ConfigManager::kApplicationDomain)); + + int result; + + // Start GFX transaction system->beginGFXTransaction(); // See if the game should default to 1x scaler @@ -274,39 +284,23 @@ static void runGame(GameDetector &detector, OSystem *system) { // (De)activate fullscreen mode as determined by the config settings system->setFeatureState(OSystem::kFeatureFullscreenMode, ConfMan.getBool("fullscreen")); - // TODO / FIXME: this transaction sould also contain the initial call to initSize - // which all engines perform. However, as long as that is contained within - // the "engine->go()", this is not possible. - // Multiple solutions come to mind, including these: - // * Don't let the engine invoke initSize(); rather, add a method to them which we can - // use to query their desired res, then we set it for them - // * Move the setGraphicsMode/setFeatureState calls here to the Engine class, which the - // engines invoke (in other words: move this transaction into the engines - // * Add an explicit Engine::init() method, which all engines have to implement, - // and into which they should put their call to initSize. Then, make sure this transaction - // surrounds the call to engine->init(); + // Init the engine (this might change the screen parameters + result = engine->init(); system->endGFXTransaction(); - // Create the game engine - Engine *engine = detector.createEngine(system); - assert(engine); - - // Add extrapath (if any) to the directory search list - if (ConfMan.hasKey("extrapath")) - File::addDefaultDirectory(ConfMan.get("extrapath")); - - if (ConfMan.hasKey("extrapath", Common::ConfigManager::kApplicationDomain)) - File::addDefaultDirectory(ConfMan.get("extrapath", Common::ConfigManager::kApplicationDomain)); - - // Run the game engine - engine->go(); + // Run the game engine if the initialization was successful. + if (result == 0) { + result = engine->go(); + } // Free up memory delete engine; // Stop all sound processing now (this prevents some race conditions later on) system->clearSoundCallback(); + + return result; } #ifndef _WIN32_WCE @@ -419,7 +413,12 @@ extern "C" int scummvm_main(GameDetector &detector, int argc, char *argv[]) { // to save memory PluginManager::instance().unloadPluginsExcept(detector._plugin); - runGame(detector, system); + int result = runGame(detector, system); + // TODO: for now, return code 0 (which is currently the only return + // code anyway) is interpreted to mean "return to launcher". This is + // *not* fixed, we could (and probably will) change the meaning etc. + if (result != 0) + running = false; // There are some command-line options that it's // unlikely that we want to preserve now that we're |