mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49:43 +01:00
Fix a rare chance that finalstretch displays glitchy cycle (color 7)
It's quite rare, though possible, that during finalstretch you could see a glitchy tileset that looked like this: https://i.imgur.com/V7cYKDW.png This happened because final_mapcol, the variable that controls which color of finalstretch is rendered, could end up being 7. Normally, it's in the range of 1..6, which perfectly correlates with the Warp Zone tilesets in tiles2.png, and the higher the number the farther back in the tileset it goes from the gray Warp Zone tileset. However, if it's 7, then it'll start grabbing tiles from the Ship plus some unused blank tiles, which does not look pretty in the slightest. This happened because it's possible, though exceedingly unlikely, that fRandom(), a function which returns a float between 0..1, could return exactly 1. fRandom() calls rand(), which returns a result between 0 and RAND_MAX, and divides it by RAND_MAX. This value is implementation dependent, but required to be at least 32767, and on most systems is 2147483647. Even taking the value of 32767, that means there's a 0.003% chance that you could get this glitchy tileset when the game cycled the color in finalstretch. But of course, playing the game for long periods of time will eventually increase this chance - cycling the color 1,000 times (around 17 minutes of playing) will result in the chance being 3%. Then as the calculations in the finalstretch color cycling logic calls fRandom(), then multiplies by 6 and adds 1, it was possible for fRandom() to return exactly 1, then have 6 added to it, resulting in final_mapcol being 7. To fix this, just decrement the multiplication by fRandom() to multiply by 5 instead of 6. Now the only possible numbers that calculation can produce would be 1..6.
This commit is contained in:
parent
e47781f92f
commit
b8553107ff
1 changed files with 2 additions and 2 deletions
|
@ -502,7 +502,7 @@ void gamelogic(void)
|
|||
if (map.final_colorframe == 1)
|
||||
{
|
||||
map.final_colorframedelay = 40;
|
||||
int temp = 1+int(fRandom() * 6);
|
||||
int temp = 1+int(fRandom() * 5);
|
||||
if (temp == map.final_mapcol) temp = (temp + 1) % 6;
|
||||
if (temp == 0) temp = 6;
|
||||
map.changefinalcol(temp);
|
||||
|
@ -510,7 +510,7 @@ void gamelogic(void)
|
|||
else if (map.final_colorframe == 2)
|
||||
{
|
||||
map.final_colorframedelay = 15;
|
||||
int temp = 1+int(fRandom() * 6);
|
||||
int temp = 1+int(fRandom() * 5);
|
||||
if (temp == map.final_mapcol) temp = (temp + 1) % 6;
|
||||
if (temp == 0) temp = 6;
|
||||
map.changefinalcol(temp);
|
||||
|
|
Loading…
Reference in a new issue