PerfectAutosave
Goals
- Safe: it should not be possible to destroy a game by crashing during a save.
- Effective: Lost progress should be bounded.
- Non-cheatable: Adding kill -9 as a move should not change the game.
- Efficient: subjective, of course :)
Note
I (Pete Mack) independently wrote a partial implementation of this, for replaying movies. It starts out with a checkpoint: a save file, screen size, and complete option dump (including macros and keymaps.) Then it logs keystrokes from there. To replay: open the save file, and watch the movie. For a guaranteed autosave, it would be necessary to include an option to restart playing after reading the log. However, any such logging is easily hacked for save-file abuse. (Just hack the source and allow replay to position n-1.) It does log (and flush) every keystroke prior to executing any commands, so a full replay is guaranteed to die.
Note that this was not designed as an autosave feature, so some modification would be necessary.
Implementation
Saving is done by writing a 1000new.sorear file, and atomic-renaming it.
- On systems where the first rename fails, 1000 will be renamed to 1000old, then 1000new to 1000, and 1000old deleted. Possibly less safe?
Between saves, incoming events are appended to the save file.
The interesting bits come at the interaction between them
To always restore at a sane point, only save before prompting for a command
After certain types of mode shift, humans need 0.7s, if we do it then it'll be unnoticable
- After level changes, when 8000 characters are in the journal
- During level changes might be interesting on slow systems
- Don't store level data, generate before replay
When we load, replay all stored characters
- Ignore save&quit commands during replay
- Will require respawn support - if you die and lose power, replaying the journal will kill the character but we want a birth screen
- Note that if Angband segfaults, there is a good chance it will do so again on replay - nice for debugging
- Not so nice for playing, add -flush-journal (which IS cheating misused)
