diff options
author | Le Philousophe | 2019-06-08 12:08:05 +0200 |
---|---|---|
committer | Le Philousophe | 2019-06-08 12:43:22 +0200 |
commit | 9fbaf9c73919258e21e420393cf053f413d37856 (patch) | |
tree | d8d554995c501d1d8003550a79a3df3e186f677e | |
parent | deb92e13ebe309fba67fab47eca003dcb0b06e97 (diff) | |
download | scummvm-rg350-9fbaf9c73919258e21e420393cf053f413d37856.tar.gz scummvm-rg350-9fbaf9c73919258e21e420393cf053f413d37856.tar.bz2 scummvm-rg350-9fbaf9c73919258e21e420393cf053f413d37856.zip |
CRYOMNI3D: Revamp loading and saving
Add support to manage saves from startup screen
-rw-r--r-- | engines/cryomni3d/cryomni3d.h | 3 | ||||
-rw-r--r-- | engines/cryomni3d/detection.cpp | 67 | ||||
-rw-r--r-- | engines/cryomni3d/versailles/engine.cpp | 32 | ||||
-rw-r--r-- | engines/cryomni3d/versailles/saveload.cpp | 36 |
4 files changed, 63 insertions, 75 deletions
diff --git a/engines/cryomni3d/cryomni3d.h b/engines/cryomni3d/cryomni3d.h index aba69e78f5..df62764a9a 100644 --- a/engines/cryomni3d/cryomni3d.h +++ b/engines/cryomni3d/cryomni3d.h @@ -99,8 +99,9 @@ public: uint8 getGameType() const; Common::Language getLanguage() const; - bool hasFeature(EngineFeature f) const; + bool hasFeature(EngineFeature f) const override; + static const uint kSaveDescriptionLen = 20; private: void pauseEngineIntern(bool); diff --git a/engines/cryomni3d/detection.cpp b/engines/cryomni3d/detection.cpp index 00f84806e9..1de22f4b1f 100644 --- a/engines/cryomni3d/detection.cpp +++ b/engines/cryomni3d/detection.cpp @@ -109,10 +109,8 @@ public: virtual bool hasFeature(MetaEngineFeature f) const; virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; virtual SaveStateList listSaves(const char *target) const; - SaveStateList listSavesForPrefix(const char *prefix, const char *extension) const; virtual int getMaximumSaveSlot() const { return 999; } virtual void removeSaveState(const char *target, int slot) const; - virtual SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; }; bool CryOmni3DMetaEngine::hasFeature(MetaEngineFeature f) const { @@ -120,50 +118,47 @@ bool CryOmni3DMetaEngine::hasFeature(MetaEngineFeature f) const { (f == kSupportsListSaves) || (f == kSupportsLoadingDuringStartup) || (f == kSupportsDeleteSave) - || (f == kSavesSupportMetaInfo) - || (f == kSavesSupportThumbnail) - || (f == kSavesSupportCreationDate) - || (f == kSavesSupportPlayTime); -} - -SaveStateList CryOmni3DMetaEngine::listSavesForPrefix(const char *prefix, - const char *extension) const { - Common::String pattern = Common::String::format("%s-###.%s", prefix, extension); - Common::StringArray filenames = g_system->getSavefileManager()->listSavefiles(pattern); - size_t prefixLen = strlen(prefix); - - SaveStateList saveList; - for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); - ++filename) { - // Extract the slot number from the filename - char slot[4]; - slot[0] = (*filename)[prefixLen + 1]; - slot[1] = (*filename)[prefixLen + 2]; - slot[2] = (*filename)[prefixLen + 3]; - slot[3] = '\0'; - - int slotNum = atoi(slot); - - saveList.push_back(SaveStateDescriptor(slotNum, "")); - } - - Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); - - return saveList; + || (f == kSimpleSavesNames); } SaveStateList CryOmni3DMetaEngine::listSaves(const char *target) const { + // Replicate constant here to shorten lines + static const uint kSaveDescriptionLen = CryOmni3D::CryOmni3DEngine::kSaveDescriptionLen; SaveStateList saveList; + Common::SaveFileManager *saveMan = g_system->getSavefileManager(); + + char saveName[kSaveDescriptionLen + 1]; + saveName[kSaveDescriptionLen] = '\0'; + Common::String pattern = Common::String::format("%s.????", target); + Common::StringArray filenames = saveMan->listSavefiles(pattern); + sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + int slotNum; + + for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); + ++file) { + // Obtain the last 4 digits of the filename, since they correspond to the save slot + slotNum = atoi(file->c_str() + file->size() - 4); + + if (slotNum >= 1 && slotNum <= 99) { + Common::InSaveFile *in = saveMan->openForLoading(*file); + if (in) { + if (in->read(saveName, kSaveDescriptionLen) == kSaveDescriptionLen) { + saveList.push_back(SaveStateDescriptor(slotNum - 1, saveName)); + } + delete in; + } + } + } + return saveList; } void CryOmni3DMetaEngine::removeSaveState(const char *target, int slot) const { + Common::String filename = Common::String::format("%s.%04d", target, slot + 1); -} - -SaveStateDescriptor CryOmni3DMetaEngine::querySaveMetaInfos(const char *target, int slot) const { - return SaveStateDescriptor(); + g_system->getSavefileManager()->removeSavefile(filename); } bool CryOmni3DMetaEngine::createInstance(OSystem *syst, Engine **engine, diff --git a/engines/cryomni3d/versailles/engine.cpp b/engines/cryomni3d/versailles/engine.cpp index 2e7373f9ad..c8a8b110ad 100644 --- a/engines/cryomni3d/versailles/engine.cpp +++ b/engines/cryomni3d/versailles/engine.cpp @@ -167,14 +167,19 @@ Common::Error CryOmni3DEngine_Versailles::run() { _isPlaying = false; _isVisiting = false; + int saveSlot = ConfMan.getInt("save_slot"); + #if !defined(DEBUG_FAST_START) || DEBUG_FAST_START<1 - playTransitionEndLevel(-2); - if (shouldAbort()) { - return Common::kNoError; - } - playTransitionEndLevel(-1); - if (shouldAbort()) { - return Common::kNoError; + if (saveSlot == -1) { + // Don't play introduction if loading directly a game + playTransitionEndLevel(-2); + if (shouldAbort()) { + return Common::kNoError; + } + playTransitionEndLevel(-1); + if (shouldAbort()) { + return Common::kNoError; + } } #endif @@ -182,11 +187,18 @@ Common::Error CryOmni3DEngine_Versailles::run() { while (!stopGame) { bool exitLoop = false; uint nextStep = 0; + if (saveSlot > -1) { + nextStep = 28; + _loadedSave = saveSlot + 1; + // Called in options + syncOmni3DSettings(); + } else { #if defined(DEBUG_FAST_START) && DEBUG_FAST_START>=2 - nextStep = 27; - // Called in options - syncOmni3DSettings(); + nextStep = 27; + // Called in options + syncOmni3DSettings(); #endif + } setCursor(181); while (!exitLoop) { _isPlaying = false; diff --git a/engines/cryomni3d/versailles/saveload.cpp b/engines/cryomni3d/versailles/saveload.cpp index afade640e9..5aec69e5ff 100644 --- a/engines/cryomni3d/versailles/saveload.cpp +++ b/engines/cryomni3d/versailles/saveload.cpp @@ -27,12 +27,9 @@ #include "cryomni3d/versailles/engine.h" -#define DEBUG_SAVE - namespace CryOmni3D { namespace Versailles { -#define SAVE_DESCRIPTION_LEN 20 Common::String CryOmni3DEngine_Versailles::getSaveFileName(bool visit, uint saveNum) const { return Common::String::format("%s%s.%04u", _targetName.c_str(), visit ? "_visit" : "", saveNum); @@ -47,13 +44,11 @@ bool CryOmni3DEngine_Versailles::canVisit() const { } void CryOmni3DEngine_Versailles::getSavesList(bool visit, Common::StringArray &saveNames) { - Common::SaveFileManager *saveMan = g_system->getSavefileManager(); - - char saveName[SAVE_DESCRIPTION_LEN + 1]; - saveName[SAVE_DESCRIPTION_LEN] = '\0'; + char saveName[kSaveDescriptionLen + 1]; + saveName[kSaveDescriptionLen] = '\0'; Common::String pattern = Common::String::format("%s%s.????", _targetName.c_str(), visit ? "_visit" : ""); - Common::StringArray filenames = saveMan->listSavefiles(pattern); + Common::StringArray filenames = _saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) saveNames.clear(); @@ -72,7 +67,7 @@ void CryOmni3DEngine_Versailles::getSavesList(bool visit, Common::StringArray &s if (!visitFile.open("game0001.sav", visitsSearchSet)) { error("Can't load visit file"); } - visitFile.read(saveName, SAVE_DESCRIPTION_LEN); + visitFile.read(saveName, kSaveDescriptionLen); saveNames.push_back(saveName); } else { warning("visiting mode but no bootstrap"); @@ -94,13 +89,9 @@ void CryOmni3DEngine_Versailles::getSavesList(bool visit, Common::StringArray &s } num++; -#ifdef DEBUG_SAVE - Common::InSaveFile *in = _saveFileMan->openRawFile(*file); -#else Common::InSaveFile *in = _saveFileMan->openForLoading(*file); -#endif if (in) { - if (in->read(saveName, SAVE_DESCRIPTION_LEN) == SAVE_DESCRIPTION_LEN) { + if (in->read(saveName, kSaveDescriptionLen) == kSaveDescriptionLen) { saveNames.push_back(saveName); } delete in; @@ -123,13 +114,7 @@ void CryOmni3DEngine_Versailles::saveGame(bool visit, uint saveNum, Common::OutSaveFile *out; - if (!(out = _saveFileMan->openForSaving(saveFileName, -#ifdef DEBUG_SAVE - false -#else - true -#endif - ))) { + if (!(out = _saveFileMan->openForSaving(saveFileName))) { return; } @@ -137,7 +122,7 @@ void CryOmni3DEngine_Versailles::saveGame(bool visit, uint saveNum, syncCountdown(); // Write save name - char saveNameC[SAVE_DESCRIPTION_LEN]; + char saveNameC[kSaveDescriptionLen]; memset(saveNameC, 0, sizeof(saveNameC)); strncpy(saveNameC, saveName.c_str(), sizeof(saveNameC)); out->write(saveNameC, sizeof(saveNameC)); @@ -216,12 +201,7 @@ bool CryOmni3DEngine_Versailles::loadGame(bool visit, uint saveNum) { in = visitFile; } else { Common::String saveFileName = getSaveFileName(visit, saveNum); - -#ifdef DEBUG_SAVE - in = _saveFileMan->openRawFile(saveFileName); -#else in = _saveFileMan->openForLoading(saveFileName); -#endif } if (!in || in->size() != 1260) { @@ -231,7 +211,7 @@ bool CryOmni3DEngine_Versailles::loadGame(bool visit, uint saveNum) { musicStop(); // Load save name but don't use it - char saveNameC[SAVE_DESCRIPTION_LEN]; + char saveNameC[kSaveDescriptionLen]; in->read(saveNameC, sizeof(saveNameC)); // dummy values |