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

De-duplicate script.running checks

While I was working on #535, I noticed that all the call sites of
script.run() have the exact same code, namely:

    if (script.running)
    {
        script.run();
    }

I figured, why not move the script.running check into the function
itself? That way, we won't have to duplicate the check every single
time, and we don't risk forgetting to add the check and causing a bug
because of that.

The check was already duplicated once since 2.0 (it's used in both
GAMEMODE and TELEPORTERMODE), and with the fix of the two-frame delay in
2.3, it's now duplicated twice, leading to THREE instances of this check
in the code, when there should be only one.
This commit is contained in:
Misa 2020-12-23 20:20:18 -08:00 committed by Ethan Lee
parent cbf3da312f
commit e3aa768034
3 changed files with 9 additions and 10 deletions

View file

@ -2101,9 +2101,6 @@ void mapclass::twoframedelayfix()
game.state = 0;
game.statedelay = 0;
script.load(game.newscript);
if (script.running)
{
script.run();
script.dontrunnextframe = true;
}
script.run();
script.dontrunnextframe = true;
}

View file

@ -79,6 +79,11 @@ void scriptclass::tokenize( const std::string& t )
void scriptclass::run()
{
if (!running)
{
return;
}
// This counter here will stop the function when it gets too high
short execution_counter = 0;
while(running && scriptdelay<=0 && !game.pausescript)

View file

@ -556,7 +556,7 @@ void inline fixedloop()
{
script.dontrunnextframe = false;
}
else if (script.running)
else
{
script.run();
}
@ -586,10 +586,7 @@ void inline fixedloop()
}
else
{
if (script.running)
{
script.run();
}
script.run();
gameinput();
}
maplogic();