Zal0 / ZGB

Game Boy / Color engine with lots of features
MIT License
703 stars 51 forks source link

Default SaveGame Values #51

Closed mhughson closed 2 years ago

mhughson commented 2 years ago

Often a save file should not be completely zero'd out by default.

It would be nice if the SRAM API allowed for either passing in a "default" savegame struct to copy in the case of CheckSRAMIntegrity needing to clear out the save. Alternatively, some sort of callback that the game could implement would work too.

mhughson commented 2 years ago

I got around this by adding my own very basic "integrity check" in my games initial state. Maybe that's actually a simpler solution overall.

// savegame.h
typedef struct {
  SAVEGAME_HEADER;

  //Whatever content you want to store in external ram
  unsigned char version;

  // Is the music and sound currently enabled?
  unsigned char music_on;
  unsigned char sfx_on;
...
// in START() of my initial state...

    if (savegame.version == 0)
    {
        savegame.version = 1;
        savegame.music_on = 1;
        savegame.sfx_on = 1;
    }
Zal0 commented 2 years ago

Yes, I was going to suggest that