COMPOSER: Preliminary (non-functional) game saving/loading support

This commit is contained in:
upthorn 2012-05-22 14:22:57 -07:00 committed by angstsmurf
parent 1efb11818d
commit 49fad58b2a
3 changed files with 310 additions and 1 deletions

View file

@ -21,6 +21,11 @@
*/
#include "base/plugins.h"
#ifdef SAVING_ANYWHERE
#include "common/savefile.h"
#include "common/serializer.h"
#include "common/str-array.h"
#endif //SAVING_ANYWHERE
#include "engines/advancedDetector.h"
#include "composer/composer.h"
@ -448,6 +453,8 @@ public:
virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const;
virtual bool hasFeature(MetaEngineFeature f) const;
virtual int getMaximumSaveSlot() const;
virtual SaveStateList listSaves(const char* target) const;
};
bool ComposerMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
@ -459,11 +466,60 @@ bool ComposerMetaEngine::createInstance(OSystem *syst, Engine **engine, const AD
}
bool ComposerMetaEngine::hasFeature(MetaEngineFeature f) const {
#ifdef SAVING_ANYWHERE
return (f == kSupportsListSaves);
#else
return false;
#endif //SAVING_ANYWHERE
}
#ifdef SAVING_ANYWHERE
Common::String getSaveName(Common::InSaveFile *in) {
Common::Serializer ser(in,NULL);
Common::String name;
uint32 tmp;
ser.syncAsUint32LE(tmp);
ser.syncAsUint32LE(tmp);
ser.syncString(name);
return name;
}
int ComposerMetaEngine::getMaximumSaveSlot() const {
return 99;
}
SaveStateList ComposerMetaEngine::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames;
Common::String saveDesc;
Common::String pattern = Common::String::format("%s.??",target);
filenames = saveFileMan->listSavefiles(pattern);
sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)
SaveStateList saveList;
for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
// Obtain the last 3 digits of the filename, since they correspond to the save slot
int slotNum = atoi(file->c_str() + file->size() - 2);
if (slotNum >= 0 && slotNum <= 99) {
Common::InSaveFile *in = saveFileMan->openForLoading(*file);
if (in) {
saveDesc = getSaveName(in);
saveList.push_back(SaveStateDescriptor(slotNum, saveDesc));
delete in;
}
}
}
return saveList;
}
#endif //SAVING_ANYWHERE
bool Composer::ComposerEngine::hasFeature(EngineFeature f) const {
return (f == kSupportsRTL);
return (f == kSupportsRTL
#ifdef SAVING_ANYWHERE
|| f == kSupportsSavingDuringRuntime || f == kSupportsLoadingDuringRuntime
#endif //SAVING_ANYWHERE
);
}
#if PLUGIN_ENABLED_DYNAMIC(COMPOSER)