doomhack / GBADoom

A port of prBoom to the Nintendo GBA.
214 stars 27 forks source link

Save settings globally rather than per save file #9

Closed thearst3rd closed 4 years ago

thearst3rd commented 4 years ago

This is a fantastic port!

One thing that I think could be improved is the way the game stores the "global" settings, like the messages toggle, always run toggle, gamma, and sound volumes. I see that @Kippykip made it store alwaysRun and gamma in a game save file, but when you boot up the game, those are only set if you load a game save file.

Last night I programmed a solution that I think works quite well. Unfortunate it was at like 2 am and so the code isn't very nice, but if you guys like the solution then I'll make an actual fork to the repository and rewrite the solution to be nicer :)

Here is what I did - in the SRAM, before the 8 save games, I write a simple settings struct which contains all of the global settings information that I feel is good to retain between booting up the game. These settings are the ones I mentioned earlier: Messages, Always Run, Gamma, Sound Volume, and Music Volume. On game startup, it will read those values. I also removed the alwaysRun and gamma values from the save file since they are no longer necessary in this case. So far in my testing, it works quite well! And saving and loading also still works :)

Since I am not very experiences with GBA programming, I made some other decisions and I'm not sure if they make sense. I'm not sure what the "default" state of SRAM is when you start a game for the first time, so to make sure that it doesn't default to, for example, all zeros (turning off music and sound when you start the game for the first time), I save a magic string to the start of the settings data and then verify that the magic string is correct before reading in the data values. Let me know if this makes sense.

doomhack commented 4 years ago

Hi there,

Yes, I've been meaning to add this. The only suggestion I would make is that the global settings should be stored after the 8 save slots as this preserves save-state compatibility across versions.

doomhack commented 4 years ago

Done!

Always Run, Gamma, Messages and Sounds volumes are stored in save file now.

thearst3rd commented 4 years ago

Wow, that was fast!! Great work! Definitely cleaner than my 2AM code :)