272
edits
(→Loading/Saving during run time: Implemented in supernova engine) |
Dreammaster (talk | contribs) (Reworked savegame sections) |
||
Line 95: | Line 95: | ||
In this section, we present various MetaEngine and Engine APIs which greatly experience | In this section, we present various MetaEngine and Engine APIs which greatly experience | ||
the user experience with regards to savestates. | the user experience with regards to savestates. These days, the bulk of logic for listing, loading, saving, or deleting savegames is provided by the Engine class. As engine writers you only need to override loadGameStream & saveGameStream to read and write data from savefiles. | ||
Line 114: | Line 114: | ||
'''How to implement it'''<br> | '''How to implement it'''<br> | ||
You | You probably don't. Newly created engines, which use loadGameStream & saveGameStream, automatically use the extended savegame format. With this, the Engine class already provides a default implementation of listSaves for you. However, if for some reason you want to override it, such as if you're providing your own custom savegame implementation from scratch, the method is passed a parameter indicating the target for which the list of savestates is requested. From this, you can (using the config manager) determine the path to the game data, if necessary, or just directly compute all available savestates. Details necessarily depend on your Engine, but looking at existing implementations should give you a fairly good idea how to tackle this. | ||
Another requirement is MetaEngine::getMaximumSaveSlot, which returns the maximum save slot number supported by your engine. This is for example used by the GUI to show up empty slots correctly. | Another requirement is MetaEngine::getMaximumSaveSlot, which returns the maximum save slot number supported by your engine. This is for example used by the GUI to show up empty slots correctly. | ||
Line 214: | Line 214: | ||
Next, for each of the two, you have to implement two Engine methods (so up to four). We focus on adding loading support here: For that, first implement Engine::canLoadGameStateCurrently(). This method should only return true if loading a savestate is possible right now. If this is always possible, just always return true. But if loading is not possible at some points, say while a cutscene is playing, make it return false at these times. | Next, for each of the two, you have to implement two Engine methods (so up to four). We focus on adding loading support here: For that, first implement Engine::canLoadGameStateCurrently(). This method should only return true if loading a savestate is possible right now. If this is always possible, just always return true. But if loading is not possible at some points, say while a cutscene is playing, make it return false at these times. | ||
Next, the Engine:: | Next, the Engine::loadGameStream() is used to load save file data. Previously, this was loadGameState, but engines using it had to manually open the save files, so it's now deprecated. The GMM will invoke this method with a valid stream from an opened save file, allowing the engine to read from it. If there is an immediate error, you can indicate so with its return value (for details, refer to the doxygen comments), in which case the GMM will show an appropriate error dialog. In | ||
'''Relevant Engine API''' | '''Relevant Engine API''' | ||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
virtual Common::Error | virtual Common::Error Engine::loadGameStream(Common::SeekableReadStream *stream); | ||
virtual bool canLoadGameStateCurrently(); | virtual bool canLoadGameStateCurrently(); | ||
Line 224: | Line 224: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Saving games is similar. Engines can override saveGameStream (rather than the now deprecated saveGameState). In this case, it gets passed in a write stream to a save file opened for saving. Additionally, it also gets passed a flag for whether an autosave is being created vs a save done by the user. Some engines may want to show a message or other indication in the UI after a save is done, but which shouldn't be done for regular autosaves. | |||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
virtual Common::Error | virtual Common::Error Engine::saveGameStream(Common::WriteStream *stream, bool isAutosave); | ||
virtual bool canSaveGameStateCurrently(); | virtual bool canSaveGameStateCurrently(); | ||
kSupportsSavingDuringRuntime feature flag | kSupportsSavingDuringRuntime feature flag | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Misc== | ==Misc== |
edits