Skip to content

Refactor the load game teardown - restart process #1581

@mateofio

Description

@mateofio

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:

  1. Load save data from file into a local variable
  2. Destroy (preferred) or Reset all game state
  3. Install the save data into Main_Data::game_data
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions