[Scummvm-cvs-logs] SF.net SVN: scummvm: [22199] scummvm/trunk/base
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Fri Apr 28 17:28:18 CEST 2006
Revision: 22199
Author: fingolfin
Date: 2006-04-28 17:27:20 -0700 (Fri, 28 Apr 2006)
ViewCVS: http://svn.sourceforge.net/scummvm/?rev=22199&view=rev
Log Message:
-----------
* 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)
Modified Paths:
--------------
scummvm/trunk/base/engine.cpp
scummvm/trunk/base/engine.h
scummvm/trunk/base/main.cpp
scummvm/trunk/base/plugins.cpp
scummvm/trunk/base/plugins.h
scummvm/trunk/engines/cine/cine.cpp
scummvm/trunk/engines/gob/gob.cpp
scummvm/trunk/engines/kyra/kyra.cpp
scummvm/trunk/engines/lure/lure.cpp
scummvm/trunk/engines/queen/queen.cpp
scummvm/trunk/engines/saga/game.cpp
scummvm/trunk/engines/scumm/plugin.cpp
scummvm/trunk/engines/simon/game.cpp
scummvm/trunk/engines/sky/sky.cpp
scummvm/trunk/engines/sword1/sword1.cpp
scummvm/trunk/engines/sword2/sword2.cpp
Modified: scummvm/trunk/base/engine.cpp
===================================================================
--- scummvm/trunk/base/engine.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/base/engine.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -259,7 +259,3 @@
GUI::MessageDialog dialog(msg);
dialog.runModal();
}
-
-Engine_Empty::Engine_Empty(OSystem *syst, const Common::String msg) : Engine(syst), _message(msg) {
-}
-
Modified: scummvm/trunk/base/engine.h
===================================================================
--- scummvm/trunk/base/engine.h 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/base/engine.h 2006-04-29 00:27:20 UTC (rev 22199)
@@ -75,34 +75,13 @@
/** 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
Modified: scummvm/trunk/base/main.cpp
===================================================================
--- scummvm/trunk/base/main.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/base/main.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -180,9 +180,11 @@
}
// 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());
Modified: scummvm/trunk/base/plugins.cpp
===================================================================
--- scummvm/trunk/base/plugins.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/base/plugins.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -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 @@
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 @@
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; }
Modified: scummvm/trunk/base/plugins.h
===================================================================
--- scummvm/trunk/base/plugins.h 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/base/plugins.h 2006-04-29 00:27:20 UTC (rev 22199)
@@ -66,6 +66,20 @@
/**
+ * 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 @@
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 @@
* - 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 @@
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 @@
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:
Modified: scummvm/trunk/engines/cine/cine.cpp
===================================================================
--- scummvm/trunk/engines/cine/cine.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/engines/cine/cine.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -110,8 +110,10 @@
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");
Modified: scummvm/trunk/engines/gob/gob.cpp
===================================================================
--- scummvm/trunk/engines/gob/gob.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/engines/gob/gob.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -361,7 +361,7 @@
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 @@
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");
Modified: scummvm/trunk/engines/kyra/kyra.cpp
===================================================================
--- scummvm/trunk/engines/kyra/kyra.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/engines/kyra/kyra.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -204,8 +204,10 @@
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");
Modified: scummvm/trunk/engines/lure/lure.cpp
===================================================================
--- scummvm/trunk/engines/lure/lure.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/engines/lure/lure.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -154,8 +154,10 @@
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");
Modified: scummvm/trunk/engines/queen/queen.cpp
===================================================================
--- scummvm/trunk/engines/queen/queen.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/engines/queen/queen.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -128,8 +128,10 @@
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");
Modified: scummvm/trunk/engines/saga/game.cpp
===================================================================
--- scummvm/trunk/engines/saga/game.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/engines/saga/game.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -83,8 +83,10 @@
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");
Modified: scummvm/trunk/engines/scumm/plugin.cpp
===================================================================
--- scummvm/trunk/engines/scumm/plugin.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/engines/scumm/plugin.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -1278,8 +1278,9 @@
*
* 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 @@
// 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 @@
// 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");
Modified: scummvm/trunk/engines/simon/game.cpp
===================================================================
--- scummvm/trunk/engines/simon/game.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/engines/simon/game.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -111,7 +111,7 @@
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 @@
}
}
- return new Simon::SimonEngine(syst);
+ assert(engine);
+ *engine = new Simon::SimonEngine(syst);
+ return kNoError;
}
REGISTER_PLUGIN(SIMON, "Simon the Sorcerer");
Modified: scummvm/trunk/engines/sky/sky.cpp
===================================================================
--- scummvm/trunk/engines/sky/sky.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/engines/sky/sky.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -110,8 +110,10 @@
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");
Modified: scummvm/trunk/engines/sword1/sword1.cpp
===================================================================
--- scummvm/trunk/engines/sword1/sword1.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/engines/sword1/sword1.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -117,8 +117,10 @@
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");
Modified: scummvm/trunk/engines/sword2/sword2.cpp
===================================================================
--- scummvm/trunk/engines/sword2/sword2.cpp 2006-04-28 23:43:56 UTC (rev 22198)
+++ scummvm/trunk/engines/sword2/sword2.cpp 2006-04-29 00:27:20 UTC (rev 22199)
@@ -111,8 +111,10 @@
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");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list