-
Notifications
You must be signed in to change notification settings - Fork 221
Description
We have a lot of horrible things like Game_Map::Dispose(bool is_load_savegame) and Game_Screen::Reset(bool is_load_savegame).
These easily lead to bugs like #1571. The main problem here is that we load the save game data into Main_Data::game_data first, and then we have all these hacked reset methods to try to not overwrite save data. Since Main_Data::game_data is already in memory, we have to tip-toe around and carefully avoid clobbering it.
Instead we should do all of our resets and teardowns after loading the save file from disk (so that file IO errors can be handled before destroying the world) but before installing it into Main_Data::game_data.
To be more precise, the process should look like this:
- Load save data from file into a local variable
- Destroy (preferred) or Reset all game state
- Install the save data into
Main_Data::game_data - Perform necessary runtime setup i.e.
Game_Map::SetupFromSave()etc..
Refactoring the code in this way we can remove these booleans and have a more well defined start and stop process.
Step (4) here could even be a uniform code path between save data and a new game, as long as new game prepares Main_Data::game_data properly before.
Not only will this ensure we don't clobber anything in the save data, it'll also ensure nothing from the previous game before loading leaks into the next one.