1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

Refactor Game::savestats() to not use a default argument

In order to be able to fix the bug #556, I'm planning on adding
ScreenSettings* to the settings.vvv write function. However, that
entails adding another argument to Game::savesettings(), which is going
to be really messy given the default argument of Game::savestats().
That, combined with the fact that the code comment at the site of the
implementation of Game::savestats() being wrong (!!!), leads me to
believe that using default function arguments here isn't worth it.

Instead, what I've done is made it so callers are explicit about whether
or not they're calling savestats(), savesettings(), or both at the same
time. If they are calling both at the same time, then they will be using
a new function named savestatsandsettings().

In short, these are the interface changes:
 * bool Game::savestats(bool) has been removed
 * bool Game::savestatsandsettings() has been added
 * void Game::savestats_menu() has been renamed to
   void Game::savestatsandsettings_menu()
 * All previous callers of bool Game::savestats() are now using bool
   Game::savestatsandsettings()
 * The one caller of bool Game::savestats(bool) is now using bool
   Game::savestats()
This commit is contained in:
Misa 2020-12-21 16:03:19 -08:00 committed by Ethan Lee
parent 98effeee58
commit b62908f0f4
6 changed files with 61 additions and 56 deletions

View file

@ -1334,7 +1334,7 @@ void Game::updatestate()
} }
} }
savestats(); savestatsandsettings();
graphics.fademode = 2; graphics.fademode = 2;
music.fadeout(); music.fadeout();
@ -3133,7 +3133,7 @@ void Game::updatestate()
} }
savestats(); savestatsandsettings();
if (nodeathmode) if (nodeathmode)
{ {
unlockAchievement("vvvvvvmaster"); //bloody hell unlockAchievement("vvvvvvmaster"); //bloody hell
@ -4447,7 +4447,7 @@ void Game::unlocknum( int t )
} }
unlock[t] = true; unlock[t] = true;
savestats(); savestatsandsettings();
#endif #endif
} }
@ -4474,7 +4474,7 @@ void Game::loadstats(ScreenSettings* screen_settings)
{ {
// Save unlock.vvv only. Maybe we have a settings.vvv laying around too, // Save unlock.vvv only. Maybe we have a settings.vvv laying around too,
// and we don't want to overwrite that! // and we don't want to overwrite that!
savestats(true); savestats();
printf("No Stats found. Assuming a new player\n"); printf("No Stats found. Assuming a new player\n");
} }
@ -4736,7 +4736,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s
} }
} }
bool Game::savestats(const bool stats_only /*= true*/) bool Game::savestats()
{ {
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc); bool already_exists = FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc);
@ -4812,20 +4812,22 @@ bool Game::savestats(const bool stats_only /*= true*/)
serializesettings(dataNode); serializesettings(dataNode);
bool success = FILESYSTEM_saveTiXml2Document("saves/unlock.vvv", doc); return FILESYSTEM_saveTiXml2Document("saves/unlock.vvv", doc);
if (!stats_only)
{
success &= savesettings();
} }
return success; bool Game::savestatsandsettings()
{
const bool stats_saved = savestats();
const bool settings_saved = savesettings();
return stats_saved && settings_saved; // Not the same as `savestats() && savesettings()`!
} }
void Game::savestats_menu() void Game::savestatsandsettings_menu()
{ {
// Call Game::savestats(), but upon failure, go to the save error screen // Call Game::savestatsandsettings(), but upon failure, go to the save error screen
if (!savestats() && !silence_settings_error) if (!savestatsandsettings() && !silence_settings_error)
{ {
createmenu(Menu::errorsavingsettings); createmenu(Menu::errorsavingsettings);
map.nexttowercolour(); map.nexttowercolour();

View file

@ -133,8 +133,7 @@ public:
void loadstats(ScreenSettings* screen_settings); void loadstats(ScreenSettings* screen_settings);
bool savestats(const bool stats_only = false); bool savestats();
void savestats_menu();
void deletestats(); void deletestats();
@ -146,6 +145,10 @@ public:
bool savesettings(); bool savesettings();
bool savestatsandsettings();
void savestatsandsettings_menu();
void deletesettings(); void deletesettings();
void deletequick(); void deletequick();

View file

@ -390,12 +390,12 @@ void menuactionpress()
game.createmenu(game.currentmenuname, true); game.createmenu(game.currentmenuname, true);
game.currentmenuoption = 0; game.currentmenuoption = 0;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 1: case 1:
music.playef(11); music.playef(11);
graphics.screenbuffer->toggleStretchMode(); graphics.screenbuffer->toggleStretchMode();
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 2: case 2:
// resize to nearest multiple // resize to nearest multiple
@ -403,7 +403,7 @@ void menuactionpress()
{ {
music.playef(11); music.playef(11);
graphics.screenbuffer->ResizeToNearestMultiple(); graphics.screenbuffer->ResizeToNearestMultiple();
game.savestats_menu(); game.savestatsandsettings_menu();
} }
else else
{ {
@ -413,19 +413,19 @@ void menuactionpress()
case 3: case 3:
music.playef(11); music.playef(11);
graphics.screenbuffer->toggleLinearFilter(); graphics.screenbuffer->toggleLinearFilter();
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 4: case 4:
//change smoothing //change smoothing
music.playef(11); music.playef(11);
graphics.screenbuffer->badSignalEffect= !graphics.screenbuffer->badSignalEffect; graphics.screenbuffer->badSignalEffect= !graphics.screenbuffer->badSignalEffect;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 5: case 5:
//toggle 30+ fps //toggle 30+ fps
music.playef(11); music.playef(11);
game.over30mode = !game.over30mode; game.over30mode = !game.over30mode;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 6: case 6:
//toggle vsync //toggle vsync
@ -433,7 +433,7 @@ void menuactionpress()
#ifndef __HAIKU__ // FIXME: Remove after SDL VSync bug is fixed! -flibit #ifndef __HAIKU__ // FIXME: Remove after SDL VSync bug is fixed! -flibit
graphics.screenbuffer->vsync = !graphics.screenbuffer->vsync; graphics.screenbuffer->vsync = !graphics.screenbuffer->vsync;
graphics.screenbuffer->resetRendererWorkaround(); graphics.screenbuffer->resetRendererWorkaround();
game.savestats_menu(); game.savestatsandsettings_menu();
#endif #endif
break; break;
default: default:
@ -480,7 +480,7 @@ void menuactionpress()
music.playef(11); music.playef(11);
game.returnmenu(); game.returnmenu();
map.nexttowercolour(); map.nexttowercolour();
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
} }
break; break;
@ -494,7 +494,7 @@ void menuactionpress()
game.returnmenu(); game.returnmenu();
game.currentmenuoption = 4; game.currentmenuoption = 4;
map.nexttowercolour(); map.nexttowercolour();
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 1: case 1:
game.slowdown = 24; game.slowdown = 24;
@ -502,7 +502,7 @@ void menuactionpress()
game.returnmenu(); game.returnmenu();
game.currentmenuoption = 4; game.currentmenuoption = 4;
map.nexttowercolour(); map.nexttowercolour();
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 2: case 2:
game.slowdown = 18; game.slowdown = 18;
@ -510,7 +510,7 @@ void menuactionpress()
game.returnmenu(); game.returnmenu();
game.currentmenuoption = 4; game.currentmenuoption = 4;
map.nexttowercolour(); map.nexttowercolour();
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 3: case 3:
game.slowdown = 12; game.slowdown = 12;
@ -518,7 +518,7 @@ void menuactionpress()
game.returnmenu(); game.returnmenu();
game.currentmenuoption = 4; game.currentmenuoption = 4;
map.nexttowercolour(); map.nexttowercolour();
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
} }
break; break;
@ -536,31 +536,31 @@ void menuactionpress()
SDL_ShowCursor(SDL_ENABLE); SDL_ShowCursor(SDL_ENABLE);
graphics.showmousecursor = true; graphics.showmousecursor = true;
} }
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 1: case 1:
// toggle unfocus pause // toggle unfocus pause
game.disablepause = !game.disablepause; game.disablepause = !game.disablepause;
game.savestats_menu(); game.savestatsandsettings_menu();
music.playef(11); music.playef(11);
break; break;
case 2: case 2:
// toggle fake load screen // toggle fake load screen
game.skipfakeload = !game.skipfakeload; game.skipfakeload = !game.skipfakeload;
game.savestats_menu(); game.savestatsandsettings_menu();
music.playef(11); music.playef(11);
break; break;
case 3: case 3:
// toggle translucent roomname BG // toggle translucent roomname BG
graphics.translucentroomname = !graphics.translucentroomname; graphics.translucentroomname = !graphics.translucentroomname;
game.savestats_menu(); game.savestatsandsettings_menu();
music.playef(11); music.playef(11);
break; break;
case 4: case 4:
// Glitchrunner mode // Glitchrunner mode
music.playef(11); music.playef(11);
game.glitchrunnermode = !game.glitchrunnermode; game.glitchrunnermode = !game.glitchrunnermode;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 5: case 5:
//back //back
@ -576,7 +576,7 @@ void menuactionpress()
case 0: case 0:
//disable animated backgrounds //disable animated backgrounds
game.colourblindmode = !game.colourblindmode; game.colourblindmode = !game.colourblindmode;
game.savestats_menu(); game.savestatsandsettings_menu();
graphics.towerbg.tdrawback = true; graphics.towerbg.tdrawback = true;
graphics.titlebg.tdrawback = true; graphics.titlebg.tdrawback = true;
music.playef(11); music.playef(11);
@ -584,7 +584,7 @@ void menuactionpress()
case 1: case 1:
//disable screeneffects //disable screeneffects
game.noflashingmode = !game.noflashingmode; game.noflashingmode = !game.noflashingmode;
game.savestats_menu(); game.savestatsandsettings_menu();
if (!game.noflashingmode) if (!game.noflashingmode)
{ {
music.playef(18); music.playef(18);
@ -597,7 +597,7 @@ void menuactionpress()
case 2: case 2:
//disable text outline //disable text outline
graphics.notextoutline = !graphics.notextoutline; graphics.notextoutline = !graphics.notextoutline;
game.savestats_menu(); game.savestatsandsettings_menu();
music.playef(11); music.playef(11);
break; break;
case 3: case 3:
@ -612,7 +612,7 @@ void menuactionpress()
else else
{ {
map.invincibility = !map.invincibility; map.invincibility = !map.invincibility;
game.savestats_menu(); game.savestatsandsettings_menu();
} }
music.playef(11); music.playef(11);
} }
@ -754,7 +754,7 @@ void menuactionpress()
music.usingmmmmmm = !music.usingmmmmmm; music.usingmmmmmm = !music.usingmmmmmm;
music.playef(11); music.playef(11);
music.play(music.currentsong); music.play(music.currentsong);
game.savestats(); game.savestatsandsettings();
} }
offset += mmmmmm_offset; offset += mmmmmm_offset;
@ -784,7 +784,7 @@ void menuactionpress()
music.playef(11); music.playef(11);
game.createmenu(Menu::unlockmenutrials, true); game.createmenu(Menu::unlockmenutrials, true);
game.currentmenuoption = 0; game.currentmenuoption = 0;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 1: //unlock 2 case 1: //unlock 2
game.unlock[10] = true; game.unlock[10] = true;
@ -792,7 +792,7 @@ void menuactionpress()
music.playef(11); music.playef(11);
game.createmenu(Menu::unlockmenutrials, true); game.createmenu(Menu::unlockmenutrials, true);
game.currentmenuoption = 1; game.currentmenuoption = 1;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 2: //unlock 3 case 2: //unlock 3
game.unlock[11] = true; game.unlock[11] = true;
@ -800,7 +800,7 @@ void menuactionpress()
music.playef(11); music.playef(11);
game.createmenu(Menu::unlockmenutrials, true); game.createmenu(Menu::unlockmenutrials, true);
game.currentmenuoption = 2; game.currentmenuoption = 2;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 3: //unlock 4 case 3: //unlock 4
game.unlock[12] = true; game.unlock[12] = true;
@ -808,7 +808,7 @@ void menuactionpress()
music.playef(11); music.playef(11);
game.createmenu(Menu::unlockmenutrials, true); game.createmenu(Menu::unlockmenutrials, true);
game.currentmenuoption = 3; game.currentmenuoption = 3;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 4: //unlock 5 case 4: //unlock 5
game.unlock[13] = true; game.unlock[13] = true;
@ -816,7 +816,7 @@ void menuactionpress()
music.playef(11); music.playef(11);
game.createmenu(Menu::unlockmenutrials, true); game.createmenu(Menu::unlockmenutrials, true);
game.currentmenuoption = 4; game.currentmenuoption = 4;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 5: //unlock 6 case 5: //unlock 6
game.unlock[14] = true; game.unlock[14] = true;
@ -824,7 +824,7 @@ void menuactionpress()
music.playef(11); music.playef(11);
game.createmenu(Menu::unlockmenutrials, true); game.createmenu(Menu::unlockmenutrials, true);
game.currentmenuoption = 5; game.currentmenuoption = 5;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 6: //back case 6: //back
//back //back
@ -852,7 +852,7 @@ void menuactionpress()
game.unlock[7] = true; game.unlock[7] = true;
game.createmenu(Menu::unlockmenu, true); game.createmenu(Menu::unlockmenu, true);
game.currentmenuoption = 1; game.currentmenuoption = 1;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 2: case 2:
//unlock no death mode //unlock no death mode
@ -861,7 +861,7 @@ void menuactionpress()
game.unlocknotify[17] = true; game.unlocknotify[17] = true;
game.createmenu(Menu::unlockmenu, true); game.createmenu(Menu::unlockmenu, true);
game.currentmenuoption = 2; game.currentmenuoption = 2;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 3: case 3:
//unlock flip mode //unlock flip mode
@ -870,7 +870,7 @@ void menuactionpress()
game.unlocknotify[18] = true; game.unlocknotify[18] = true;
game.createmenu(Menu::unlockmenu, true); game.createmenu(Menu::unlockmenu, true);
game.currentmenuoption = 3; game.currentmenuoption = 3;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 4: case 4:
//unlock jukebox //unlock jukebox
@ -878,7 +878,7 @@ void menuactionpress()
game.stat_trinkets = 20; game.stat_trinkets = 20;
game.createmenu(Menu::unlockmenu, true); game.createmenu(Menu::unlockmenu, true);
game.currentmenuoption = 4; game.currentmenuoption = 4;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 5: case 5:
//unlock secret lab //unlock secret lab
@ -887,7 +887,7 @@ void menuactionpress()
game.unlocknotify[8] = true; game.unlocknotify[8] = true;
game.createmenu(Menu::unlockmenu, true); game.createmenu(Menu::unlockmenu, true);
game.currentmenuoption = 5; game.currentmenuoption = 5;
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
default: default:
//back //back
@ -1251,7 +1251,7 @@ void menuactionpress()
{ {
key.sensitivity = 0; key.sensitivity = 0;
} }
game.savestats_menu(); game.savestatsandsettings_menu();
break; break;
case 5: case 5:

View file

@ -432,7 +432,7 @@ void gamelogic()
if (game.swnmessage == 0) if (game.swnmessage == 0)
{ {
music.playef(25); music.playef(25);
game.savestats(); game.savestatsandsettings();
} }
game.swnmessage = 1; game.swnmessage = 1;
} }

View file

@ -3431,7 +3431,7 @@ void scriptclass::startgamemode( int t )
} }
#endif #endif
case 100: case 100:
game.savestats(); game.savestatsandsettings();
SDL_Quit(); SDL_Quit();
exit(0); exit(0);

View file

@ -402,7 +402,7 @@ int main(int argc, char *argv[])
deltaloop(); deltaloop();
} }
game.savestats(); game.savestatsandsettings();
NETWORK_shutdown(); NETWORK_shutdown();
SDL_Quit(); SDL_Quit();
FILESYSTEM_deinit(); FILESYSTEM_deinit();
@ -641,7 +641,7 @@ void inline fixedloop()
if (game.savemystats) if (game.savemystats)
{ {
game.savemystats = false; game.savemystats = false;
game.savestats(); game.savestatsandsettings();
} }
//Mute button //Mute button