Concurent autosave
Posted: Tue Jan 02, 2018 8:47 am
Sometimes when I play Factorio the auto save dialog appears and all action freezes for several seconds
- I understand that this is the designed behavior
- I am still greatly irritated by it
- I think that it is possible to avoid stopping-the-world when autosaving
He's how concurrent autosave could be implemented:
In this post it is stated that a Factorio client can emulate a map at any moment given the original map and a stream of users' inputs.
So I propose using this mechanics to emulate a game in a parallel thread and save it instead of freezing the original game.
Step-by-step:
- introduce a buffer for user input [*]
-- it should work the same as sending user actions to a server, but storring them locally
- on autosave record 2 things:
-- a reference to a previous autosave state of the game [**]
-- a time stamp of the moment at which you want to autosave [***]
- this information together with the user input buffer (*) allows to completely restore the state of the game!
- to pack the saved state of the game in its current format, do:
-- start a separate thread with a Factorio engine
-- init it with the previous autosave (**)
-- send to it the buffered user input (*) that happened from the time of the previous autosave (**) to the time of this autosave (***)
-- save this parallel game with the standard procedure as you do now
Note:
- the original game is never stopped since all actions in the main thread take nano-seconds and several bytes of memory
- the parallel game can be run very quickly to shorten the saving procedure or very slowly to ease the load on the cpu
What do you think?
- I understand that this is the designed behavior
- I am still greatly irritated by it
- I think that it is possible to avoid stopping-the-world when autosaving
He's how concurrent autosave could be implemented:
In this post it is stated that a Factorio client can emulate a map at any moment given the original map and a stream of users' inputs.
So I propose using this mechanics to emulate a game in a parallel thread and save it instead of freezing the original game.
Step-by-step:
- introduce a buffer for user input [*]
-- it should work the same as sending user actions to a server, but storring them locally
- on autosave record 2 things:
-- a reference to a previous autosave state of the game [**]
-- a time stamp of the moment at which you want to autosave [***]
- this information together with the user input buffer (*) allows to completely restore the state of the game!
- to pack the saved state of the game in its current format, do:
-- start a separate thread with a Factorio engine
-- init it with the previous autosave (**)
-- send to it the buffered user input (*) that happened from the time of the previous autosave (**) to the time of this autosave (***)
-- save this parallel game with the standard procedure as you do now
Note:
- the original game is never stopped since all actions in the main thread take nano-seconds and several bytes of memory
- the parallel game can be run very quickly to shorten the saving procedure or very slowly to ease the load on the cpu
What do you think?