Next beta will come with a change to the savefile framework that allows savefiles to be made in the background while continuing to play without borking the savefile ! So to the user the saving process is instantaneous

There is now a SavefilePipe class that should be used to save/load instead of directly using Savefile.
The pipe will run the background thread(coroutine actually) for you.
A default pipe is created by the engine in the "savefile_pipe" global variable. Do not make yours, only one can exist.
You can tell the pipe to save something like that:
This will push the savefile in the pipe. More than one thing can be pushed to save, they will be saved in order sequencially. If too many things are queued the game will pause to wait for the saves to finish to prevent the user from piling tons of things in the pipe.savefile_pipe:push(game.save_name, "game", game)
Obviously I can not do the same for loading, but there is a trick, if the thing to load is still in the saving pipe (like going quickly in and out of a zone) it will just use the still in memory copy making it also intantaneous and still continue to save in the background.
Modules NEED to be converted to this system, luckily it's very easy:
- Change your Game:tick() method to check for savefile_pipe.saving, like that:
Code: Select all
if self.paused and not savefile_pipe.saving then return true end
- Change any instance of savefile saving (probaly just in mod.dialogs.Quit and Game:saveGame() to just one line:
savefile_pipe:push(game.save_name, "game", game)
- Optionnaly (but recommended): add a visual display that the game is still saving in your PlayerDisplay, something like this:
Code: Select all
if savefile_pipe.saving then h = h + self.font_h self.surface:drawColorStringBlended(self.font, "#YELLOW#Saving...", 0, h, 255, 255, 255) h = h + self.font_h end