[Scummvm-cvs-logs] CVS: scummvm/base engine.h,1.14,1.15 main.cpp,1.56,1.57
Max Horn
fingolfin at users.sourceforge.net
Mon Nov 22 16:05:01 CET 2004
Update of /cvsroot/scummvm/scummvm/base
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32311/base
Modified Files:
engine.h main.cpp
Log Message:
Added Engine::init() method; added return value to Engine::go()
Index: engine.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/base/engine.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- engine.h 20 Nov 2004 23:49:09 -0000 1.14
+++ engine.h 23 Nov 2004 00:03:19 -0000 1.15
@@ -41,9 +41,20 @@
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;
Index: main.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/base/main.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- main.cpp 22 Nov 2004 23:25:08 -0000 1.56
+++ main.cpp 23 Nov 2004 00:03:19 -0000 1.57
@@ -190,11 +190,7 @@
// 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 @@
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 @@
!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 @@
// (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 @@
// 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
More information about the Scummvm-git-logs
mailing list