diff options
author | Max Horn | 2006-04-29 00:27:20 +0000 |
---|---|---|
committer | Max Horn | 2006-04-29 00:27:20 +0000 |
commit | bf7359881115a5b041028b032ee28430bc5e36d3 (patch) | |
tree | 78c955620bb16d4b4e39f3b887eed35dd552c57b | |
parent | b00262a2fe1b8bf1d51794a9da3e735e97dfb5ee (diff) | |
download | scummvm-rg350-bf7359881115a5b041028b032ee28430bc5e36d3.tar.gz scummvm-rg350-bf7359881115a5b041028b032ee28430bc5e36d3.tar.bz2 scummvm-rg350-bf7359881115a5b041028b032ee28430bc5e36d3.zip |
* Changed the createEngine() factory function of our plugins to return an error code (the engine is now passed indirectly via a double pointer)
* Removed Engine_Empty (obsolete now that engines can return actual error codes)
svn-id: r22199
-rw-r--r-- | base/engine.cpp | 4 | ||||
-rw-r--r-- | base/engine.h | 25 | ||||
-rw-r--r-- | base/main.cpp | 6 | ||||
-rw-r--r-- | base/plugins.cpp | 10 | ||||
-rw-r--r-- | base/plugins.h | 22 | ||||
-rw-r--r-- | engines/cine/cine.cpp | 6 | ||||
-rw-r--r-- | engines/gob/gob.cpp | 6 | ||||
-rw-r--r-- | engines/kyra/kyra.cpp | 6 | ||||
-rw-r--r-- | engines/lure/lure.cpp | 6 | ||||
-rw-r--r-- | engines/queen/queen.cpp | 6 | ||||
-rw-r--r-- | engines/saga/game.cpp | 6 | ||||
-rw-r--r-- | engines/scumm/plugin.cpp | 45 | ||||
-rw-r--r-- | engines/simon/game.cpp | 6 | ||||
-rw-r--r-- | engines/sky/sky.cpp | 6 | ||||
-rw-r--r-- | engines/sword1/sword1.cpp | 6 | ||||
-rw-r--r-- | engines/sword2/sword2.cpp | 6 |
16 files changed, 92 insertions, 80 deletions
diff --git a/base/engine.cpp b/base/engine.cpp index 55cbf2f65b..ecc0f6dbf2 100644 --- a/base/engine.cpp +++ b/base/engine.cpp @@ -259,7 +259,3 @@ void Engine::GUIErrorMessage(const Common::String msg) { GUI::MessageDialog dialog(msg); dialog.runModal(); } - -Engine_Empty::Engine_Empty(OSystem *syst, const Common::String msg) : Engine(syst), _message(msg) { -} - diff --git a/base/engine.h b/base/engine.h index 49515bd40a..b9cc17a29c 100644 --- a/base/engine.h +++ b/base/engine.h @@ -75,34 +75,13 @@ public: /** On some systems, check if the game appears to be run from CD. */ void checkCD(); - /* Indicate if an autosave should be performed */ + /* Indicate if an autosave should be performed. */ bool shouldPerformAutoSave(int lastSaveTime); - /** Initialized graphics and shows error message */ + /** Initialized graphics and shows error message. */ void GUIErrorMessage(const Common::String msg); }; -// Used when no valid game was found in the directory -// Just pops up an error message and returns to launcher -class Engine_Empty : public Engine { -public: - Engine_Empty(OSystem *syst, const Common::String msg = "No valid games were found in specified directory."); - virtual ~Engine_Empty() {} - - // Displays error message and do not run go() method - int init() { GUIErrorMessage(_message); return 1; } - - // Just indicate that we want return to launcher - int go() { return 1; } - - void errorString(char *buf_input, char *buf_output) {} - -private: - Common::String _message; -}; - - - extern Engine *g_engine; #endif diff --git a/base/main.cpp b/base/main.cpp index 409a42ad9d..2a46357af4 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -180,9 +180,11 @@ static int runGame(const Plugin *plugin, OSystem &system, const Common::String & } // Create the game engine - Engine *engine = plugin->createInstance(&system); - if (!engine) { + Engine *engine = 0; + PluginError err = plugin->createInstance(&system, &engine); + if (!engine || err != kNoError) { // TODO: Show an error dialog or so? + // TODO: Also take 'err' into consideration... //GUI::MessageDialog alert("ScummVM could not find any game in the specified directory!"); //alert.runModal(); warning("Failed to instantiate engine for target %s", ConfMan.getActiveDomainName().c_str()); diff --git a/base/plugins.cpp b/base/plugins.cpp index 8cb1e1e6ae..13b18c3eab 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -28,7 +28,7 @@ #include "common/util.h" /** Type of factory functions which make new Engine objects. */ -typedef Engine *(*EngineFactory)(OSystem *syst); +typedef PluginError (*EngineFactory)(OSystem *syst, Engine **engine); typedef const char *(*NameFunc)(); typedef GameDescriptor (*GameIDQueryFunc)(const char *gameid); @@ -116,9 +116,9 @@ public: const char *getName() const { return _plugin->_name; } - Engine *createInstance(OSystem *syst) const { + PluginError createInstance(OSystem *syst, Engine **engine) const { assert(_plugin->_ef); - return (*_plugin->_ef)(syst); + return (*_plugin->_ef)(syst, engine); } GameList getSupportedGames() const { return _plugin->_games; } @@ -157,9 +157,9 @@ public: const char *getName() const { return _name.c_str(); } - Engine *createInstance(OSystem *syst) const { + PluginError createInstance(OSystem *syst, Engine **engine) const { assert(_ef); - return (*_ef)(syst); + return (*_ef)(syst, engine); } GameList getSupportedGames() const { return _games; } diff --git a/base/plugins.h b/base/plugins.h index f0318a8008..b0178f3e89 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -66,6 +66,20 @@ typedef Common::Array<DetectedGame> DetectedGameList; /** + * Error codes which mayb be reported by plugins under various circumstances. + * @todo Turn this into a global 'ErrorCode' enum used by all of ScummVM ? + */ +enum PluginError { + kNoError = 0, // No error occured + kInvalidPathError, + kNoGameDataFoundError, + kUnsupportedGameidError, + + kUnknownError // Catch-all error, used if no other error code matches +}; + + +/** * Abstract base class for the plugin system. * Subclasses for this can be used to wrap both static and dynamic * plugins. @@ -84,7 +98,7 @@ public: virtual GameDescriptor findGame(const char *gameid) const = 0; virtual DetectedGameList detectGames(const FSList &fslist) const = 0; - virtual Engine *createInstance(OSystem *syst) const = 0; + virtual PluginError createInstance(OSystem *syst, Engine **engine) const = 0; }; @@ -106,7 +120,7 @@ public: * - DetectedGameList Engine_##ID##_detectGames(const FSList &fslist) * -> scans through the given file list (usually the contents of a directory), * and attempts to detects games present in that location. - * - Engine *Engine_##ID##_create(OSystem *syst) + * - PluginError Engine_##ID##_create(OSystem *syst, Engine **engine) * -> factory function, create an instance of the Engine class. * * @todo add some means to query the plugin API version etc. @@ -130,7 +144,7 @@ public: PLUGIN_EXPORT const char *PLUGIN_name() { return name; } \ PLUGIN_EXPORT GameList PLUGIN_gameIDList() { return Engine_##ID##_gameIDList(); } \ PLUGIN_EXPORT GameDescriptor PLUGIN_findGameID(const char *gameid) { return Engine_##ID##_findGameID(gameid); } \ - PLUGIN_EXPORT Engine *PLUGIN_createEngine(OSystem *syst) { return Engine_##ID##_create(syst); } \ + PLUGIN_EXPORT PluginError PLUGIN_createEngine(OSystem *syst, Engine **engine) { return Engine_##ID##_create(syst, engine); } \ PLUGIN_EXPORT DetectedGameList PLUGIN_detectGames(const FSList &fslist) { return Engine_##ID##_detectGames(fslist); } \ } \ void dummyFuncToAllowTrailingSemicolon() @@ -145,7 +159,7 @@ class PluginRegistrator { friend class StaticPlugin; public: typedef GameDescriptor (*GameIDQueryFunc)(const char *gameid); - typedef Engine *(*EngineFactory)(OSystem *syst); + typedef PluginError (*EngineFactory)(OSystem *syst, Engine **engine); typedef DetectedGameList (*DetectFunc)(const FSList &fslist); protected: diff --git a/engines/cine/cine.cpp b/engines/cine/cine.cpp index 9f504b76f0..cb61fbf1cd 100644 --- a/engines/cine/cine.cpp +++ b/engines/cine/cine.cpp @@ -110,8 +110,10 @@ DetectedGameList Engine_CINE_detectGames(const FSList &fslist) { return detectedGames; } -Engine *Engine_CINE_create(OSystem *syst) { - return new Cine::CineEngine(syst); +PluginError Engine_CINE_create(OSystem *syst, Engine **engine) { + assert(engine); + *engine = new Cine::CineEngine(syst); + return kNoError; } REGISTER_PLUGIN(CINE, "CINE Engine"); diff --git a/engines/gob/gob.cpp b/engines/gob/gob.cpp index 108368006e..6fd6255a9a 100644 --- a/engines/gob/gob.cpp +++ b/engines/gob/gob.cpp @@ -361,7 +361,7 @@ DetectedGameList Engine_GOB_detectGames(const FSList &fslist) { return detectedGames; } -Engine *Engine_GOB_create(OSystem *syst) { +PluginError Engine_GOB_create(OSystem *syst, Engine **engine) { // Detect game features based on MD5 uint8 md5sum[16]; char md5str[32 + 1]; @@ -403,7 +403,9 @@ Engine *Engine_GOB_create(OSystem *syst) { printf("Unknown MD5 (%s)! Please report the details (language, platform, etc.) of this game to the ScummVM team\n", md5str); } - return new GobEngine(syst, features, g->lang); + assert(engine); + *engine = new GobEngine(syst, features, g->lang); + return kNoError; } REGISTER_PLUGIN(GOB, "Gob Engine"); diff --git a/engines/kyra/kyra.cpp b/engines/kyra/kyra.cpp index 920f5c02a2..81a73db6f7 100644 --- a/engines/kyra/kyra.cpp +++ b/engines/kyra/kyra.cpp @@ -204,8 +204,10 @@ DetectedGameList Engine_KYRA_detectGames(const FSList &fslist) { return detectedGames; } -Engine *Engine_KYRA_create(OSystem *system) { - return new KyraEngine(system); +PluginError Engine_KYRA_create(OSystem *syst, Engine **engine) { + assert(engine); + *engine = new KyraEngine(syst); + return kNoError; } REGISTER_PLUGIN(KYRA, "Legend of Kyrandia Engine"); diff --git a/engines/lure/lure.cpp b/engines/lure/lure.cpp index 5ec33994a3..dab02a5ca3 100644 --- a/engines/lure/lure.cpp +++ b/engines/lure/lure.cpp @@ -154,8 +154,10 @@ DetectedGameList Engine_LURE_detectGames(const FSList &fslist) { return detectedGames; } -Engine *Engine_LURE_create(OSystem *system) { - return new LureEngine(system); +PluginError Engine_LURE_create(OSystem *syst, Engine **engine) { + assert(engine); + *engine = new LureEngine(syst); + return kNoError; } REGISTER_PLUGIN(LURE, "Lure of the Temptress Engine"); diff --git a/engines/queen/queen.cpp b/engines/queen/queen.cpp index 611832c439..129d8358c2 100644 --- a/engines/queen/queen.cpp +++ b/engines/queen/queen.cpp @@ -128,8 +128,10 @@ DetectedGameList Engine_QUEEN_detectGames(const FSList &fslist) { return detectedGames; } -Engine *Engine_QUEEN_create(OSystem *syst) { - return new Queen::QueenEngine(syst); +PluginError Engine_QUEEN_create(OSystem *syst, Engine **engine) { + assert(engine); + *engine = new Queen::QueenEngine(syst); + return kNoError; } REGISTER_PLUGIN(QUEEN, "Flight of the Amazon Queen"); diff --git a/engines/saga/game.cpp b/engines/saga/game.cpp index e9b215e99d..cad25c7aff 100644 --- a/engines/saga/game.cpp +++ b/engines/saga/game.cpp @@ -83,8 +83,10 @@ DetectedGameList Engine_SAGA_detectGames(const FSList &fslist) { return Saga::GAME_detectGames(fslist); } -Engine *Engine_SAGA_create(OSystem *syst) { - return new Saga::SagaEngine(syst); +PluginError Engine_SAGA_create(OSystem *syst, Engine **engine) { + assert(engine); + *engine = new Saga::SagaEngine(syst); + return kNoError; } REGISTER_PLUGIN(SAGA, "SAGA Engine"); diff --git a/engines/scumm/plugin.cpp b/engines/scumm/plugin.cpp index abeaae20e0..12d048d308 100644 --- a/engines/scumm/plugin.cpp +++ b/engines/scumm/plugin.cpp @@ -1278,8 +1278,9 @@ DetectedGameList Engine_SCUMM_detectGames(const FSList &fslist) { * * This is heavily based on our MD5 detection scheme. */ -Engine *Engine_SCUMM_create(OSystem *syst) { - Engine *engine; +PluginError Engine_SCUMM_create(OSystem *syst, Engine **engine) { + assert(syst); + assert(engine); const char *gameid = ConfMan.get("gameid").c_str(); // We start by checking whether the specified game ID is obsolete. @@ -1313,8 +1314,8 @@ Engine *Engine_SCUMM_create(OSystem *syst) { // Unable to locate game data if (results.empty()) { - warning("ScummEngine: unable to locate game data"); - return new Engine_Empty(syst); + warning("ScummEngine: unable to locate game data at path '%s'", dir.path().c_str()); + return kNoGameDataFoundError; } DetectorResult res(*(results.begin())); @@ -1374,74 +1375,74 @@ Engine *Engine_SCUMM_create(OSystem *syst) { // instantiate the appropriate game engine. Hooray! switch (res.game.version) { case 0: - engine = new ScummEngine_c64(syst, res); + *engine = new ScummEngine_c64(syst, res); break; case 1: case 2: - engine = new ScummEngine_v2(syst, res); + *engine = new ScummEngine_v2(syst, res); break; case 3: if (res.game.features & GF_OLD_BUNDLE) - engine = new ScummEngine_v3old(syst, res); + *engine = new ScummEngine_v3old(syst, res); else - engine = new ScummEngine_v3(syst, res); + *engine = new ScummEngine_v3(syst, res); break; case 4: - engine = new ScummEngine_v4(syst, res); + *engine = new ScummEngine_v4(syst, res); break; case 5: - engine = new ScummEngine_v5(syst, res); + *engine = new ScummEngine_v5(syst, res); break; case 6: switch (res.game.heversion) { #ifndef DISABLE_HE case 100: - engine = new ScummEngine_v100he(syst, res); + *engine = new ScummEngine_v100he(syst, res); break; case 99: - engine = new ScummEngine_v99he(syst, res); + *engine = new ScummEngine_v99he(syst, res); break; case 98: case 95: case 90: - engine = new ScummEngine_v90he(syst, res); + *engine = new ScummEngine_v90he(syst, res); break; case 80: - engine = new ScummEngine_v80he(syst, res); + *engine = new ScummEngine_v80he(syst, res); break; case 73: case 72: - engine = new ScummEngine_v72he(syst, res); + *engine = new ScummEngine_v72he(syst, res); break; case 71: - engine = new ScummEngine_v71he(syst, res); + *engine = new ScummEngine_v71he(syst, res); break; case 70: - engine = new ScummEngine_v70he(syst, res); + *engine = new ScummEngine_v70he(syst, res); break; #endif #ifndef PALMOS_68K case 61: - engine = new ScummEngine_v60he(syst, res); + *engine = new ScummEngine_v60he(syst, res); break; #endif default: - engine = new ScummEngine_v6(syst, res); + *engine = new ScummEngine_v6(syst, res); } break; #ifndef DISABLE_SCUMM_7_8 case 7: - engine = new ScummEngine_v7(syst, res); + *engine = new ScummEngine_v7(syst, res); break; case 8: - engine = new ScummEngine_v8(syst, res); + *engine = new ScummEngine_v8(syst, res); break; #endif default: error("Engine_SCUMM_create(): Unknown version of game engine"); } - return engine; + return kNoError; } REGISTER_PLUGIN(SCUMM, "Scumm Engine"); diff --git a/engines/simon/game.cpp b/engines/simon/game.cpp index 34a135ef90..1685fd35b2 100644 --- a/engines/simon/game.cpp +++ b/engines/simon/game.cpp @@ -111,7 +111,7 @@ DetectedGameList Engine_SIMON_detectGames(const FSList &fslist) { return Simon::GAME_detectGames(fslist); } -Engine *Engine_SIMON_create(OSystem *syst) { +PluginError Engine_SIMON_create(OSystem *syst, Engine **engine) { const char *gameid = ConfMan.get("gameid").c_str(); for (const ObsoleteGameID *o = obsoleteGameIDsTable; o->from; ++o) { @@ -129,7 +129,9 @@ Engine *Engine_SIMON_create(OSystem *syst) { } } - return new Simon::SimonEngine(syst); + assert(engine); + *engine = new Simon::SimonEngine(syst); + return kNoError; } REGISTER_PLUGIN(SIMON, "Simon the Sorcerer"); diff --git a/engines/sky/sky.cpp b/engines/sky/sky.cpp index f3b286a5ea..941f9df017 100644 --- a/engines/sky/sky.cpp +++ b/engines/sky/sky.cpp @@ -110,8 +110,10 @@ DetectedGameList Engine_SKY_detectGames(const FSList &fslist) { return detectedGames; } -Engine *Engine_SKY_create(OSystem *syst) { - return new Sky::SkyEngine(syst); +PluginError Engine_SKY_create(OSystem *syst, Engine **engine) { + assert(engine); + *engine = new Sky::SkyEngine(syst); + return kNoError; } REGISTER_PLUGIN(SKY, "Beneath a Steel Sky"); diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp index cba1e97bb8..fd49b0de06 100644 --- a/engines/sword1/sword1.cpp +++ b/engines/sword1/sword1.cpp @@ -117,8 +117,10 @@ DetectedGameList Engine_SWORD1_detectGames(const FSList &fslist) { return detectedGames; } -Engine *Engine_SWORD1_create(OSystem *syst) { - return new SwordEngine(syst); +PluginError Engine_SWORD1_create(OSystem *syst, Engine **engine) { + assert(engine); + *engine = new SwordEngine(syst); + return kNoError; } REGISTER_PLUGIN(SWORD1, "Broken Sword"); diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp index 13e97dc0d8..fdbcbb5c07 100644 --- a/engines/sword2/sword2.cpp +++ b/engines/sword2/sword2.cpp @@ -111,8 +111,10 @@ DetectedGameList Engine_SWORD2_detectGames(const FSList &fslist) { return detectedGames; } -Engine *Engine_SWORD2_create(OSystem *syst) { - return new Sword2::Sword2Engine(syst); +PluginError Engine_SWORD2_create(OSystem *syst, Engine **engine) { + assert(engine); + *engine = new Sword2::Sword2Engine(syst); + return kNoError; } REGISTER_PLUGIN(SWORD2, "Broken Sword 2"); |