diff options
Diffstat (limited to 'base')
-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 |
5 files changed, 29 insertions, 38 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: |