AutosaveService class
Keeps a copy of unsaved changes, so they aren't lost if the game ends unexpectedly.
While a level has unsaved changes, it's written every minute — and when the application is suspended — into Editor/Recovery of the user content (see ContentResolver::
Where there are threads, a copy of the level is taken and written on a thread of its own, the editor doesn't stop while it's compressed.
Public static variables
-
static std::
uint32_t RecoveryChunk constexpr - Chunk with the path of the level file the copy belongs to.
Public static functions
- static auto FindRecovery(StringView filePath) -> String
- Returns the copy of a level file if it's newer than the file, or an empty string.
- static auto GetRecoveryDirectory(bool create = false) -> String
- Returns the directory the copies are kept in.
- static auto GetRecoveryPath(StringView filePath, bool create = false) -> String
- Returns where the copy of a level file is kept, each run has its own for a level that wasn't saved yet.
Constructors, destructors, conversion operators
- AutosaveService()
- ~AutosaveService()
- AutosaveService(const AutosaveService&) deleted
Public functions
- auto operator=(const AutosaveService&) -> AutosaveService& deleted
- void SetSource(StringView filePath)
- Sets the level file the copy belongs to, empty for a level that wasn't saved yet.
- void Update(float timeMult, LevelDocument& document, CommandHistory& history)
- Writes the copy when it's time to.
- auto SaveNow(LevelDocument& document, CommandHistory& history, bool wait = false) -> bool
- Writes the copy now if there are unsaved changes.
- void Discard()
- Removes the copy.
Public variables
- Function<void()> BeforeSave
- Called before the copy is written, to put into the level what isn't kept in it all the time.
Function documentation
static String Jazz2:: Editor:: AutosaveService:: FindRecovery(StringView filePath)
Returns the copy of a level file if it's newer than the file, or an empty string.
For a level that wasn't saved yet, the newest copy of such a level is returned, of any run, and it becomes the copy of this run — discarding the changes removes it, new changes are written over it.
static String Jazz2:: Editor:: AutosaveService:: GetRecoveryDirectory(bool create = false)
Returns the directory the copies are kept in.
With create the user content directory is created if it doesn't exist yet.
bool Jazz2:: Editor:: AutosaveService:: SaveNow(LevelDocument& document,
CommandHistory& history,
bool wait = false)
Writes the copy now if there are unsaved changes.
With wait it's written before this returns, as when the application is suspended, otherwise it may be written on a thread of its own and taken as written by a later Update().