diff --git a/engines/metaengine.cpp b/engines/metaengine.cpp index 2a8bc127bfe..4cc02fa33df 100644 --- a/engines/metaengine.cpp +++ b/engines/metaengine.cpp @@ -37,7 +37,7 @@ #include "graphics/managed_surface.h" #include "graphics/thumbnail.h" -Common::String MetaEngine::getSavegameFile(int saveGameIdx, const char *target) const { +Common::String MetaEngineConnect::getSavegameFile(int saveGameIdx, const char *target) const { if (saveGameIdx == kSavegameFilePattern) { // Pattern requested const char *pattern = hasFeature(kSavesUseExtendedFormat) ? "%s.###" : "%s.s##"; @@ -128,7 +128,7 @@ Common::KeymapArray MetaEngine::initKeymaps(const char *target) const { return Keymap::arrayOf(engineKeyMap); } -bool MetaEngine::hasFeature(MetaEngineFeature f) const { +bool MetaEngineConnect::hasFeature(MetaEngineFeature f) const { return (f == kSupportsListSaves) || (f == kSupportsDeleteSave) || @@ -140,7 +140,7 @@ bool MetaEngine::hasFeature(MetaEngineFeature f) const { (f == kSavesUseExtendedFormat); } -void MetaEngine::appendExtendedSave(Common::OutSaveFile *saveFile, uint32 playtime, +void MetaEngineConnect::appendExtendedSave(Common::OutSaveFile *saveFile, uint32 playtime, Common::String desc, bool isAutosave) { ExtendedSavegameHeader header; @@ -172,7 +172,7 @@ void MetaEngine::appendExtendedSave(Common::OutSaveFile *saveFile, uint32 playti saveFile->finalize(); } -void MetaEngine::saveScreenThumbnail(Common::OutSaveFile *saveFile) { +void MetaEngineConnect::saveScreenThumbnail(Common::OutSaveFile *saveFile) { // Create a thumbnail surface from the screen Graphics::Surface thumb; ::createThumbnailFromScreen(&thumb); @@ -182,7 +182,7 @@ void MetaEngine::saveScreenThumbnail(Common::OutSaveFile *saveFile) { thumb.free(); } -void MetaEngine::parseSavegameHeader(ExtendedSavegameHeader *header, SaveStateDescriptor *desc) { +void MetaEngineConnect::parseSavegameHeader(ExtendedSavegameHeader *header, SaveStateDescriptor *desc) { int day = (header->date >> 24) & 0xFF; int month = (header->date >> 16) & 0xFF; int year = header->date & 0xFFFF; @@ -195,14 +195,14 @@ void MetaEngine::parseSavegameHeader(ExtendedSavegameHeader *header, SaveStateDe desc->setDescription(header->description); } -void MetaEngine::fillDummyHeader(ExtendedSavegameHeader *header) { +void MetaEngineConnect::fillDummyHeader(ExtendedSavegameHeader *header) { // This is wrong header, perhaps it is original savegame. Thus fill out dummy values header->date = (20 << 24) | (9 << 16) | 2016; header->time = (9 << 8) | 56; header->playtime = 0; } -WARN_UNUSED_RESULT bool MetaEngine::readSavegameHeader(Common::InSaveFile *in, ExtendedSavegameHeader *header, bool skipThumbnail) { +WARN_UNUSED_RESULT bool MetaEngineConnect::readSavegameHeader(Common::InSaveFile *in, ExtendedSavegameHeader *header, bool skipThumbnail) { uint oldPos = in->pos(); in->seek(-4, SEEK_END); @@ -260,11 +260,11 @@ WARN_UNUSED_RESULT bool MetaEngine::readSavegameHeader(Common::InSaveFile *in, E } -/////////////////////////////////////// -// MetaEngine default implementations -/////////////////////////////////////// +////////////////////////////////////////////// +// MetaEngineConnect default implementations +////////////////////////////////////////////// -SaveStateList MetaEngine::listSaves(const char *target) const { +SaveStateList MetaEngineConnect::listSaves(const char *target) const { if (!hasFeature(kSavesUseExtendedFormat)) return SaveStateList(); @@ -305,7 +305,7 @@ SaveStateList MetaEngine::listSaves(const char *target) const { return saveList; } -SaveStateList MetaEngine::listSaves(const char *target, bool saveMode) const { +SaveStateList MetaEngineConnect::listSaves(const char *target, bool saveMode) const { SaveStateList saveList = listSaves(target); int autosaveSlot = ConfMan.getInt("autosave_period") ? getAutosaveSlot() : -1; if (!saveMode || autosaveSlot == -1) @@ -354,14 +354,14 @@ GUI::OptionsContainerWidget *MetaEngine::buildEngineOptionsWidget(GUI::GuiObject return new GUI::ExtraGuiOptionsWidget(boss, name, target, engineOptions); } -void MetaEngine::removeSaveState(const char *target, int slot) const { +void MetaEngineConnect::removeSaveState(const char *target, int slot) const { if (!hasFeature(kSavesUseExtendedFormat)) return; g_system->getSavefileManager()->removeSavefile(getSavegameFile(slot, target)); } -SaveStateDescriptor MetaEngine::querySaveMetaInfos(const char *target, int slot) const { +SaveStateDescriptor MetaEngineConnect::querySaveMetaInfos(const char *target, int slot) const { if (!hasFeature(kSavesUseExtendedFormat)) return SaveStateDescriptor(); diff --git a/engines/metaengine.h b/engines/metaengine.h index f22bb3b04c7..9089a2def94 100644 --- a/engines/metaengine.h +++ b/engines/metaengine.h @@ -103,11 +103,6 @@ struct ExtendedSavegameHeader { * See the class MetaEngineConnect below. */ class MetaEngine : public PluginObject { -private: - /** - * Converts the current screen contents to a thumbnail, and saves it - */ - static void saveScreenThumbnail(Common::OutSaveFile *saveFile); public: virtual ~MetaEngine() {} @@ -130,46 +125,6 @@ public: */ virtual DetectedGames detectGames(const Common::FSList &fslist) const = 0; - /** - * Return a list of all save states associated with the given target. - * - * The returned list is guaranteed to be sorted by slot numbers. That - * means smaller slot numbers are always stored before bigger slot numbers. - * - * The caller has to ensure that this (Meta)Engine is responsible - * for the specified target (by using findGame on it respectively - * on the associated gameid from the relevant ConfMan entry, if present). - * - * The default implementation returns an empty list. - * - * @note MetaEngines must indicate that this function has been implemented - * via the kSupportsListSaves feature flag. - * - * @param target name of a config manager target - * @return a list of save state descriptors - */ - virtual SaveStateList listSaves(const char *target) const; - - /** - * Return a list of all save states associated with the given target. - * - * This is a wrapper around the basic listSaves virtual method, but which - * has some extra logic for autosave handling - * - * @param target name of a config manager target - * @param saveMode If true, getting the list for a save dialog - * @return a list of save state descriptors - */ - SaveStateList listSaves(const char *target, bool saveMode) const; - - /** - * Returns the slot number being used for autosaves. - * @note This should match the engine getAutosaveSlot() method - */ - virtual int getAutosaveSlot() const { - return 0; - } - /** * Return a list of extra GUI options for the specified target. * If no target is specified, all of the available custom GUI options are @@ -224,6 +179,92 @@ public: return Common::AchievementsInfo(); } + /** + * Return the keymap used by the target. + */ + virtual Common::Array initKeymaps(const char *target) const; +}; + +/** + * A MetaEngineConnect is another factory for Engine instances, and is very + * similiar to meta engines. This class, however, composes of bridged functionalities + * that can be used to connect an actual Engine with a MetaEngine. + * Every engine "plugin" provides a hook to get an instance of MetaEngineConnector subclass + * for that "engine plugin.". E.g. SCUMM provides a ScummMetaEngineConnect. + * This is then in turn used for things like instantiating engine objects, listing savefiles, + * querying save metadata, etc. + * Since engine plugins can be used a external runtime libraries, these can live and build inside + * the engine, while a MetaEngine will always build into the executable to be able to detect code. + */ +class MetaEngineConnect : public PluginObject { +private: + /** + * Converts the current screen contents to a thumbnail, and saves it + */ + static void saveScreenThumbnail(Common::OutSaveFile *saveFile); +public: + /** + * Name of the engine plugin. + * Classes inheriting a MetaEngineConnect must provide a engineID here, + * which can then be used to match an Engine with MetaEngine. + * E.g. ScummMetaEngine inherits MetaEngine & provides a engineID of "Scumm". + * ScummMetaEngineConnect inherits MetaEngineConnect & provides the name "Scumm". + * This way, we can easily match a Engine with a MetaEngine. + */ + virtual const char *getName() const = 0; + + /** + * Tries to instantiate an engine instance based on the settings of + * the currently active ConfMan target. That is, the MetaEngine should + * query the ConfMan singleton for the target, gameid, path etc. data. + * + * @param syst Pointer to the global OSystem object + * @param engine Pointer to a pointer which the MetaEngine sets to + * the newly create Engine, or 0 in case of an error + * @return a Common::Error describing the error which occurred, or kNoError + */ + virtual Common::Error createInstance(OSystem *syst, Engine **engine) const = 0; + + /** + * Return a list of all save states associated with the given target. + * + * The returned list is guaranteed to be sorted by slot numbers. That + * means smaller slot numbers are always stored before bigger slot numbers. + * + * The caller has to ensure that this (Meta)Engine is responsible + * for the specified target (by using findGame on it respectively + * on the associated gameid from the relevant ConfMan entry, if present). + * + * The default implementation returns an empty list. + * + * @note MetaEngines must indicate that this function has been implemented + * via the kSupportsListSaves feature flag. + * + * @param target name of a config manager target + * @return a list of save state descriptors + */ + virtual SaveStateList listSaves(const char *target) const; + + /** + * Return a list of all save states associated with the given target. + * + * This is a wrapper around the basic listSaves virtual method, but which + * has some extra logic for autosave handling + * + * @param target name of a config manager target + * @param saveMode If true, getting the list for a save dialog + * @return a list of save state descriptors + */ + SaveStateList listSaves(const char *target, bool saveMode) const; + + /** + * Returns the slot number being used for autosaves. + * @note This should match the engine getAutosaveSlot() method + */ + virtual int getAutosaveSlot() const { + return 0; + } + /** * Return the maximum save slot that the engine supports. * @@ -283,11 +324,6 @@ public: return getSavegameFile(kSavegameFilePattern, target); } - /** - * Return the keymap used by the target. - */ - virtual Common::Array initKeymaps(const char *target) const; - /** @name MetaEngineFeature flags */ //@{ @@ -375,55 +411,18 @@ public: kSavesUseExtendedFormat }; + //@} + /** * Determine whether the engine supports the specified MetaEngine feature. * Used by e.g. the launcher to determine whether to enable the "Load" button. */ virtual bool hasFeature(MetaEngineFeature f) const; - static void appendExtendedSave(Common::OutSaveFile *saveFile, uint32 playtime, - Common::String desc, bool isAutosave); + static void appendExtendedSave(Common::OutSaveFile *saveFile, uint32 playtime, Common::String desc, bool isAutosave); static void parseSavegameHeader(ExtendedSavegameHeader *header, SaveStateDescriptor *desc); static void fillDummyHeader(ExtendedSavegameHeader *header); static WARN_UNUSED_RESULT bool readSavegameHeader(Common::InSaveFile *in, ExtendedSavegameHeader *header, bool skipThumbnail = true); - - //@} -}; - -/** - * A MetaEngineConnect is another factory for Engine instances, and is very - * similiar to meta engines. This class, however, composes of bridged functionalities - * that can be used to connect an actual Engine with a MetaEngine. - * Every engine "plugin" provides a hook to get an instance of MetaEngineConnector subclass - * for that "engine plugin.". E.g. SCUMM provides a ScummMetaEngineConnect. - * This is then in turn used for things like instantiating engine objects, listing savefiles, - * querying save metadata, etc. - * Since engine plugins can be used a external runtime libraries, these can live and build inside - * the engine, while a MetaEngine will always build into the executable to be able to detect code. - */ -class MetaEngineConnect : public PluginObject { -public: - /** - * Tries to instantiate an engine instance based on the settings of - * the currently active ConfMan target. That is, the MetaEngine should - * query the ConfMan singleton for the target, gameid, path etc. data. - * - * @param syst Pointer to the global OSystem object - * @param engine Pointer to a pointer which the MetaEngine sets to - * the newly create Engine, or 0 in case of an error - * @return a Common::Error describing the error which occurred, or kNoError - */ - virtual Common::Error createInstance(OSystem *syst, Engine **engine) const = 0; - - /** - * Name of the engine plugin. - * Classes inheriting a MetaEngineConnect must provide a engineID here, - * which can then be used to match an Engine with MetaEngine. - * E.g. ScummMetaEngine inherits MetaEngine & provides a engineID of "Scumm". - * ScummMetaEngineConnect inherits MetaEngineConnect & provides the name "Scumm". - * This way, we can easily match a Engine with a MetaEngine. - */ - virtual const char *getName() const = 0; }; /**