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

Factor timestep calculation out to Game function

This is so we can grab the game's timestep anywhere else in the codebase
without copy-pasting it.
This commit is contained in:
Misa 2021-04-02 11:50:30 -07:00 committed by Ethan Lee
parent f8f6f3b96e
commit f6ea05f521
3 changed files with 32 additions and 30 deletions

View file

@ -6742,3 +6742,33 @@ void Game::copyndmresults(void)
ndmresulthardestroom = hardestroom; ndmresulthardestroom = hardestroom;
SDL_memcpy(ndmresultcrewstats, crewstats, sizeof(ndmresultcrewstats)); SDL_memcpy(ndmresultcrewstats, crewstats, sizeof(ndmresultcrewstats));
} }
static inline int 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;
}
int Game::get_timestep(void)
{
switch (gamestate)
{
case EDITORMODE:
return 24;
case GAMEMODE:
return get_framerate(slowdown);
default:
return 34;
}
}

View file

@ -292,6 +292,7 @@ public:
bool colourblindmode; bool colourblindmode;
bool noflashingmode; bool noflashingmode;
int slowdown; int slowdown;
int get_timestep(void);
bool nodeathmode; bool nodeathmode;
int gameoverdelay; int gameoverdelay;

View file

@ -57,23 +57,6 @@ static volatile Uint32 accumulator = 0;
static volatile Uint32 f_time = 0; static volatile Uint32 f_time = 0;
static volatile Uint32 f_timePrev = 0; static 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;
}
enum FuncType enum FuncType
{ {
Func_null, Func_null,
@ -665,19 +648,7 @@ static void inline deltaloop(void)
const float rawdeltatime = static_cast<float>(time_ - timePrev); const float rawdeltatime = static_cast<float>(time_ - timePrev);
accumulator += rawdeltatime; accumulator += rawdeltatime;
Uint32 timesteplimit; Uint32 timesteplimit = game.get_timestep();
if (game.gamestate == EDITORMODE)
{
timesteplimit = 24;
}
else if (game.gamestate == GAMEMODE)
{
timesteplimit = get_framerate(game.slowdown);
}
else
{
timesteplimit = 34;
}
while (accumulator >= timesteplimit) while (accumulator >= timesteplimit)
{ {