Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/SavedGame.cpp
Show All 29 Lines | |||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/Mod.h" | #include "ps/Mod.h" | ||||
#include "ps/Pyrogenesis.h" | #include "ps/Pyrogenesis.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
// TODO: we ought to check version numbers when loading files | // TODO: we ought to check version numbers when loading files | ||||
Status SavedGames::SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& simulation, const shared_ptr<ScriptInterface::StructuredClone>& guiMetadataClone) | Status SavedGames::SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& simulation, const ScriptInterface::StructuredClone& guiMetadataClone) | ||||
{ | { | ||||
// Determine the filename to save under | // Determine the filename to save under | ||||
const VfsPath basenameFormat(L"saves/" + prefix + L"-%04d"); | const VfsPath basenameFormat(L"saves/" + prefix + L"-%04d"); | ||||
const VfsPath filenameFormat = basenameFormat.ChangeExtension(L".0adsave"); | const VfsPath filenameFormat = basenameFormat.ChangeExtension(L".0adsave"); | ||||
VfsPath filename; | VfsPath filename; | ||||
// Don't make this a static global like NextNumberedFilename expects, because | // Don't make this a static global like NextNumberedFilename expects, because | ||||
// that wouldn't work when 'prefix' changes, and because it's not thread-safe | // that wouldn't work when 'prefix' changes, and because it's not thread-safe | ||||
size_t nextSaveNumber = 0; | size_t nextSaveNumber = 0; | ||||
vfs::NextNumberedFilename(g_VFS, filenameFormat, nextSaveNumber, filename); | vfs::NextNumberedFilename(g_VFS, filenameFormat, nextSaveNumber, filename); | ||||
return Save(filename.Filename().string(), description, simulation, guiMetadataClone); | return Save(filename.Filename().string(), description, simulation, guiMetadataClone); | ||||
} | } | ||||
Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, const shared_ptr<ScriptInterface::StructuredClone>& guiMetadataClone) | Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, const ScriptInterface::StructuredClone& guiMetadataClone) | ||||
{ | { | ||||
ScriptRequest rq(simulation.GetScriptInterface()); | ScriptRequest rq(simulation.GetScriptInterface()); | ||||
// Determine the filename to save under | // Determine the filename to save under | ||||
const VfsPath basenameFormat(L"saves/" + name); | const VfsPath basenameFormat(L"saves/" + name); | ||||
const VfsPath filename = basenameFormat.ChangeExtension(L".0adsave"); | const VfsPath filename = basenameFormat.ChangeExtension(L".0adsave"); | ||||
// ArchiveWriter_Zip can only write to OsPaths, not VfsPaths, | // ArchiveWriter_Zip can only write to OsPaths, not VfsPaths, | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | public: | ||||
* | * | ||||
* Note: We use a different approach for returning the string and the metadata JS::Value. | * Note: We use a different approach for returning the string and the metadata JS::Value. | ||||
* We use a pointer for the string to avoid copies (efficiency). We don't use this approach | * We use a pointer for the string to avoid copies (efficiency). We don't use this approach | ||||
* for the metadata because it would be error prone with rooting and the stack-based rooting | * for the metadata because it would be error prone with rooting and the stack-based rooting | ||||
* types and confusing (a chain of pointers pointing to other pointers). | * types and confusing (a chain of pointers pointing to other pointers). | ||||
*/ | */ | ||||
CGameLoader(const ScriptInterface& scriptInterface, std::string* savedState) : | CGameLoader(const ScriptInterface& scriptInterface, std::string* savedState) : | ||||
m_ScriptInterface(scriptInterface), | m_ScriptInterface(scriptInterface), | ||||
m_Metadata(scriptInterface.GetJSRuntime()), | m_Metadata(scriptInterface.GetGeneralJSContext()), | ||||
m_SavedState(savedState) | m_SavedState(savedState) | ||||
{ | { | ||||
} | } | ||||
static void ReadEntryCallback(const VfsPath& pathname, const CFileInfo& fileInfo, PIArchiveFile archiveFile, uintptr_t cbData) | static void ReadEntryCallback(const VfsPath& pathname, const CFileInfo& fileInfo, PIArchiveFile archiveFile, uintptr_t cbData) | ||||
{ | { | ||||
((CGameLoader*)cbData)->ReadEntry(pathname, fileInfo, archiveFile); | ((CGameLoader*)cbData)->ReadEntry(pathname, fileInfo, archiveFile); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator