mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Seed with frame counter instead of SDL_GetTicks
Using SDL_GetTicks() to seed the Gravitron RNG caused many reproducibility issues while syncing https://tasvideos.org/7575S . To fix this, add a frame counter, which is a number that is incremented every frame and never resets, and use it instead. If someone needs to switch back to SDL_GetTicks() for old TASes, then provide the -seed-use-sdl-getticks command-line option for them.
This commit is contained in:
parent
e6a3df6ca6
commit
9def8fd704
4 changed files with 21 additions and 2 deletions
|
@ -274,6 +274,8 @@ void Game::init(void)
|
||||||
|
|
||||||
deathcounts = 0;
|
deathcounts = 0;
|
||||||
gameoverdelay = 0;
|
gameoverdelay = 0;
|
||||||
|
framecounter = 0;
|
||||||
|
seed_use_sdl_getticks = false;
|
||||||
resetgameclock();
|
resetgameclock();
|
||||||
gamesaved = false;
|
gamesaved = false;
|
||||||
gamesavefailed = false;
|
gamesavefailed = false;
|
||||||
|
|
|
@ -257,6 +257,8 @@ public:
|
||||||
int lastsaved;
|
int lastsaved;
|
||||||
int deathcounts;
|
int deathcounts;
|
||||||
|
|
||||||
|
int framecounter;
|
||||||
|
bool seed_use_sdl_getticks;
|
||||||
int frames, seconds, minutes, hours;
|
int frames, seconds, minutes, hours;
|
||||||
bool gamesaved;
|
bool gamesaved;
|
||||||
bool gamesavefailed;
|
bool gamesavefailed;
|
||||||
|
|
|
@ -3094,8 +3094,15 @@ void scriptclass::hardreset(void)
|
||||||
{
|
{
|
||||||
const bool version2_2 = GlitchrunnerMode_less_than_or_equal(Glitchrunner2_2);
|
const bool version2_2 = GlitchrunnerMode_less_than_or_equal(Glitchrunner2_2);
|
||||||
|
|
||||||
/* The RNG is 32-bit. We don't _really_ need 64-bit... */
|
if (game.seed_use_sdl_getticks)
|
||||||
xoshiro_seed((Uint32) SDL_GetTicks64());
|
{
|
||||||
|
/* The RNG is 32-bit. We don't _really_ need 64-bit... */
|
||||||
|
xoshiro_seed((Uint32) SDL_GetTicks64());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
xoshiro_seed(game.framecounter);
|
||||||
|
}
|
||||||
|
|
||||||
//Game:
|
//Game:
|
||||||
game.hascontrol = true;
|
game.hascontrol = true;
|
||||||
|
|
|
@ -368,6 +368,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char* baseDir = NULL;
|
char* baseDir = NULL;
|
||||||
char* assetsPath = NULL;
|
char* assetsPath = NULL;
|
||||||
|
bool seed_use_sdl_getticks = false;
|
||||||
|
|
||||||
vlog_init();
|
vlog_init();
|
||||||
|
|
||||||
|
@ -478,6 +479,10 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
vlog_toggle_error(0);
|
vlog_toggle_error(0);
|
||||||
}
|
}
|
||||||
|
else if (ARG("-seed-use-sdl-getticks"))
|
||||||
|
{
|
||||||
|
seed_use_sdl_getticks = true;
|
||||||
|
}
|
||||||
#undef ARG_INNER
|
#undef ARG_INNER
|
||||||
#undef ARG
|
#undef ARG
|
||||||
else
|
else
|
||||||
|
@ -546,6 +551,7 @@ int main(int argc, char *argv[])
|
||||||
graphics.init();
|
graphics.init();
|
||||||
|
|
||||||
game.init();
|
game.init();
|
||||||
|
game.seed_use_sdl_getticks = seed_use_sdl_getticks;
|
||||||
|
|
||||||
// This loads music too...
|
// This loads music too...
|
||||||
if (!graphics.reloadresources())
|
if (!graphics.reloadresources())
|
||||||
|
@ -838,6 +844,8 @@ static void focused_end(void)
|
||||||
|
|
||||||
static enum LoopCode loop_end(void)
|
static enum LoopCode loop_end(void)
|
||||||
{
|
{
|
||||||
|
++game.framecounter;
|
||||||
|
|
||||||
//We did editorinput, now it's safe to turn this off
|
//We did editorinput, now it's safe to turn this off
|
||||||
key.linealreadyemptykludge = false;
|
key.linealreadyemptykludge = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue