Remove game.gameframerate as duplicate of game.slowdown

game.gameframerate seems to exist for converting the value of
game.slowdown into an actual timestep value, when really the timestep
value should just use game.slowdown directly with a fast lookup table.
Otherwise, there's a bunch of duplicated game.slowdown case-switches
everywhere, which adds up to a large, annoying pile should the values be
changed in the future. But now the duplicate variable has been removed,
and with it, all the copy-pasted case-switches.

Also, the game speed text rendering in Menu::accessibility and
Menu::setslowdown has been factored out to a function and de-duplicated
as well.
This commit is contained in:
Misa 2020-11-12 17:05:18 -08:00 committed by Ethan Lee
parent ee44f81d4c
commit bc9dff8c2a
5 changed files with 42 additions and 69 deletions

View File

@ -171,7 +171,6 @@ void Game::init(void)
colourblindmode = false;
noflashingmode = false;
slowdown = 30;
gameframerate=34;
// 0..5
controllerSensitivity = 2;
@ -4610,25 +4609,6 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s
if (pKey == "slowdown")
{
slowdown = help.Int(pText);
switch(slowdown)
{
case 30:
gameframerate=34;
break;
case 24:
gameframerate=41;
break;
case 18:
gameframerate=55;
break;
case 12:
gameframerate=83;
break;
default:
gameframerate=34;
break;
}
}
if (pKey == "advanced_smoothing")

View File

@ -275,7 +275,6 @@ public:
bool colourblindmode;
bool noflashingmode;
int slowdown;
Uint32 gameframerate;
bool nodeathmode;
int gameoverdelay;

View File

@ -488,7 +488,6 @@ void menuactionpress()
{
case 0:
//back
game.gameframerate=34;
game.slowdown = 30;
game.savestats();
music.playef(11);
@ -497,7 +496,6 @@ void menuactionpress()
map.nexttowercolour();
break;
case 1:
game.gameframerate=41;
game.slowdown = 24;
game.savestats();
music.playef(11);
@ -506,7 +504,6 @@ void menuactionpress()
map.nexttowercolour();
break;
case 2:
game.gameframerate=55;
game.slowdown = 18;
game.savestats();
music.playef(11);
@ -515,7 +512,6 @@ void menuactionpress()
map.nexttowercolour();
break;
case 3:
game.gameframerate=83;
game.slowdown = 12;
game.savestats();
music.playef(11);
@ -630,7 +626,7 @@ void menuactionpress()
else
{
music.playef(2);
game.gameframerate = 34;
game.slowdown = 30;
}
break;
case 5:

View File

@ -25,6 +25,25 @@ int inline FLIP(int ypos)
return ypos;
}
static inline void drawslowdowntext()
{
switch (game.slowdown)
{
case 30:
graphics.Print( -1, 105, "Game speed is normal.", tr/2, tg/2, tb/2, true);
break;
case 24:
graphics.Print( -1, 105, "Game speed is at 80%", tr, tg, tb, true);
break;
case 18:
graphics.Print( -1, 105, "Game speed is at 60%", tr, tg, tb, true);
break;
case 12:
graphics.Print( -1, 105, "Game speed is at 40%", tr, tg, tb, true);
break;
}
}
void menurender()
{
int temp = 50;
@ -369,21 +388,7 @@ void menurender()
case Menu::setslowdown:
graphics.bigprint( -1, 40, "Game Speed", tr, tg, tb, true);
graphics.Print( -1, 75, "Select a new game speed below.", tr, tg, tb, true);
switch (game.gameframerate)
{
case 34:
graphics.Print( -1, 105, "Game speed is normal.", tr/2, tg/2, tb/2, true);
break;
case 41:
graphics.Print( -1, 105, "Game speed is at 80%", tr, tg, tb, true);
break;
case 55:
graphics.Print( -1, 105, "Game speed is at 60%", tr, tg, tb, true);
break;
case 83:
graphics.Print( -1, 105, "Game speed is at 40%", tr, tg, tb, true);
break;
}
drawslowdowntext();
break;
case Menu::newgamewarning:
graphics.Print( -1, 100, "Are you sure? This will", tr, tg, tb, true);
@ -556,23 +561,7 @@ void menurender()
graphics.bigprint( -1, 40, "Game Speed", tr, tg, tb, true);
graphics.Print( -1, 75, "May be useful for disabled gamers", tr, tg, tb, true);
graphics.Print( -1, 85, "using one switch devices.", tr, tg, tb, true);
if (game.gameframerate==34)
{
graphics.Print( -1, 105, "Game speed is normal.", tr/2, tg/2, tb/2, true);
}
else if (game.gameframerate==41)
{
graphics.Print( -1, 105, "Game speed is at 80%", tr, tg, tb, true);
}
else if (game.gameframerate==55)
{
graphics.Print( -1, 105, "Game speed is at 60%", tr, tg, tb, true);
}
else if (game.gameframerate==83)
{
graphics.Print( -1, 105, "Game speed is at 40%", tr, tg, tb, true);
}
break;
drawslowdowntext();
}
break;
case Menu::playint1:
@ -588,7 +577,7 @@ void menurender()
graphics.Print( -1, 65, "Replay any level in the game in", tr, tg, tb, true);
graphics.Print( -1, 75, "a competitive time trial mode.", tr, tg, tb, true);
if (game.gameframerate > 34 || map.invincibility)
if (game.slowdown < 30 || map.invincibility)
{
graphics.Print( -1, 105, "Time Trials are not available", tr, tg, tb, true);
graphics.Print( -1, 115, "with slowdown or invincibility.", tr, tg, tb, true);
@ -609,7 +598,7 @@ void menurender()
graphics.Print( -1, 65, "Play the entire game", tr, tg, tb, true);
graphics.Print( -1, 75, "without dying once.", tr, tg, tb, true);
if (game.gameframerate > 34 || map.invincibility)
if (game.slowdown < 30 || map.invincibility)
{
graphics.Print( -1, 105, "No Death Mode is not available", tr, tg, tb, true);
graphics.Print( -1, 115, "with slowdown or invincibility.", tr, tg, tb, true);

View File

@ -55,6 +55,23 @@ volatile Uint32 accumulator = 0;
volatile Uint32 f_time = 0;
volatile Uint32 f_timePrev = 0;
static inline Uint32 get_framerate(const int slowdown)
{
switch (slowdown)
{
case 30:
return 34;
case 24:
return 41;
case 18:
return 55;
case 12:
return 83;
}
return 34;
}
void inline deltaloop();
void inline fixedloop();
@ -278,14 +295,6 @@ int main(int argc, char *argv[])
game.gamestate = TITLEMODE;
if (game.slowdown == 0) game.slowdown = 30;
switch(game.slowdown){
case 30: game.gameframerate=34; break;
case 24: game.gameframerate=41; break;
case 18: game.gameframerate=55; break;
case 12: game.gameframerate=83; break;
default: game.gameframerate=34; break;
}
//Check to see if you've already unlocked some achievements here from before the update
if (game.swnbestrank > 0){
if(game.swnbestrank >= 1) game.unlockAchievement("vvvvvvsupgrav5");
@ -413,7 +422,7 @@ void inline deltaloop()
}
else if (game.gamestate == GAMEMODE)
{
timesteplimit = game.gameframerate;
timesteplimit = get_framerate(game.slowdown);
}
else
{