mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
Enumify all fade modes
This removes the magic numbers previously used for controlling the fade mode, which are really not readable at all unless you already know what they mean. 0: FADE_NONE 1: FADE_FULLY_BLACK 2: FADE_START_FADEOUT 3: FADE_FADING_OUT 4: FADE_START_FADEIN 5: FADE_FADING_IN There is also the macro FADEMODE_IS_FADING, which indicates when the intention is to only check if the game is fading right now, which wasn't clearly conveyed previously. I also took the opportunity to clean up the style of any lines I touched. This included rewriting if-else chains into case-switches, turning one-liner if-then statements into proper blocks, fixing up comments, and even commenting the `fademode == FADE_NONE` on the tower spike checks (which, it was previously undocumented why that check was there, but I think I know why it's there). As for type safety, we already get some by transforming the variable types into the enum. Assignment is prohibited without a cast. But, apparently, comparison is perfectly legal and won't even give so much as a warning. To work around this and make absolutely sure I made all existing comparisons now use the enum, I temporarily changed it to be an `enum class`, which is a C++11 feature that makes it so all comparisons are illegal. Unfortunately, it scopes them in a namespace with the same name as a class, so I had to temporarily define macros to make sure my existing code worked. I also had to temporarily up the standard in CMakeLists.txt to get it to compile. But after all that was done, I found the rest of the places where a comparison to an integer was used, and fixed them.
This commit is contained in:
@@ -284,7 +284,7 @@ static int gotomode = 0;
|
||||
static void startmode(const int mode)
|
||||
{
|
||||
gotomode = mode;
|
||||
graphics.fademode = 2; /* fading out */
|
||||
graphics.fademode = FADE_START_FADEOUT;
|
||||
fadetomode = true;
|
||||
fadetomodedelay = 19;
|
||||
}
|
||||
@@ -1880,7 +1880,7 @@ void titleinput(void)
|
||||
if (!game.press_action && !game.press_left && !game.press_right && !key.isDown(27) && !key.isDown(game.controllerButton_esc)) game.jumpheld = false;
|
||||
if (!game.press_map) game.mapheld = false;
|
||||
|
||||
if (!game.jumpheld && graphics.fademode==0)
|
||||
if (!game.jumpheld && graphics.fademode == FADE_NONE)
|
||||
{
|
||||
if (game.press_action || game.press_left || game.press_right || game.press_map || key.isDown(27) || key.isDown(game.controllerButton_esc))
|
||||
{
|
||||
@@ -2074,7 +2074,7 @@ void gameinput(void)
|
||||
game.interactheld = false;
|
||||
}
|
||||
|
||||
if (game.intimetrial && graphics.fademode == 1 && game.quickrestartkludge)
|
||||
if (game.intimetrial && graphics.fademode == FADE_FULLY_BLACK && game.quickrestartkludge)
|
||||
{
|
||||
//restart the time trial
|
||||
game.quickrestartkludge = false;
|
||||
@@ -2367,10 +2367,10 @@ void gameinput(void)
|
||||
game.gamesavefailed = false;
|
||||
game.menupage = 20; // The Map Page
|
||||
}
|
||||
else if (game.intimetrial && graphics.fademode == 0)
|
||||
else if (game.intimetrial && graphics.fademode == FADE_NONE)
|
||||
{
|
||||
//Quick restart of time trial
|
||||
graphics.fademode = 2;
|
||||
graphics.fademode = FADE_START_FADEOUT;
|
||||
game.completestop = true;
|
||||
music.fadeout();
|
||||
game.quickrestartkludge = true;
|
||||
@@ -2431,7 +2431,7 @@ void mapinput(void)
|
||||
game.press_map = false;
|
||||
game.press_interact = false;
|
||||
|
||||
if (version2_2 && graphics.fademode == 1 && graphics.menuoffset == 0)
|
||||
if (version2_2 && graphics.fademode == FADE_FULLY_BLACK && graphics.menuoffset == 0)
|
||||
{
|
||||
// Deliberate re-addition of the glitchy gamestate-based fadeout!
|
||||
|
||||
@@ -2496,7 +2496,7 @@ void mapinput(void)
|
||||
|
||||
if(graphics.menuoffset==0
|
||||
&& ((!version2_2 && !game.fadetomenu && game.fadetomenudelay <= 0 && !game.fadetolab && game.fadetolabdelay <= 0)
|
||||
|| graphics.fademode == 0))
|
||||
|| graphics.fademode == FADE_NONE))
|
||||
{
|
||||
if (key.isDown(KEYBOARD_LEFT) || key.isDown(KEYBOARD_UP) || key.isDown(KEYBOARD_a) || key.isDown(KEYBOARD_w)|| key.controllerWantsLeft(true))
|
||||
{
|
||||
@@ -2672,7 +2672,7 @@ static void mapmenuactionpress(const bool version2_2)
|
||||
//Kill contents of offset render buffer, since we do that for some reason.
|
||||
//This fixes an apparent frame flicker.
|
||||
ClearSurface(graphics.tempBuffer);
|
||||
graphics.fademode = 2;
|
||||
graphics.fademode = FADE_START_FADEOUT;
|
||||
music.fadeout();
|
||||
map.nexttowercolour();
|
||||
if (!version2_2)
|
||||
@@ -2691,7 +2691,7 @@ static void mapmenuactionpress(const bool version2_2)
|
||||
case 21:
|
||||
//quit to menu
|
||||
game.swnmode = false;
|
||||
graphics.fademode = 2;
|
||||
graphics.fademode = FADE_START_FADEOUT;
|
||||
music.fadeout();
|
||||
if (!version2_2)
|
||||
{
|
||||
@@ -2712,7 +2712,7 @@ static void mapmenuactionpress(const bool version2_2)
|
||||
graphics.flipmode = false;
|
||||
game.ingame_titlemode = true;
|
||||
graphics.ingame_fademode = graphics.fademode;
|
||||
graphics.fademode = 0;
|
||||
graphics.fademode = FADE_NONE;
|
||||
|
||||
// Set this before we create the menu
|
||||
game.kludge_ingametemp = game.currentmenuname;
|
||||
@@ -2892,9 +2892,9 @@ void gamecompleteinput(void)
|
||||
game.creditposition -= 6;
|
||||
if (game.creditposition <= -Credits::creditmaxposition)
|
||||
{
|
||||
if(graphics.fademode==0)
|
||||
if (graphics.fademode == FADE_NONE)
|
||||
{
|
||||
graphics.fademode = 2;
|
||||
graphics.fademode = FADE_START_FADEOUT;
|
||||
}
|
||||
game.creditposition = -Credits::creditmaxposition;
|
||||
}
|
||||
@@ -2911,9 +2911,9 @@ void gamecompleteinput(void)
|
||||
if(game.press_map)
|
||||
{
|
||||
//Return to game
|
||||
if(graphics.fademode==0)
|
||||
if(graphics.fademode == FADE_NONE)
|
||||
{
|
||||
graphics.fademode = 2;
|
||||
graphics.fademode = FADE_START_FADEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2936,9 +2936,9 @@ void gamecompleteinput2(void)
|
||||
game.oldcreditposx++;
|
||||
if (game.creditposy >= 30)
|
||||
{
|
||||
if(graphics.fademode==0)
|
||||
if(graphics.fademode == FADE_NONE)
|
||||
{
|
||||
graphics.fademode = 2;
|
||||
graphics.fademode = FADE_START_FADEOUT;
|
||||
music.fadeout();
|
||||
}
|
||||
}
|
||||
@@ -2951,9 +2951,9 @@ void gamecompleteinput2(void)
|
||||
if(game.press_map)
|
||||
{
|
||||
//Return to game
|
||||
if(graphics.fademode==0)
|
||||
if(graphics.fademode == FADE_NONE)
|
||||
{
|
||||
graphics.fademode = 2;
|
||||
graphics.fademode = FADE_START_FADEOUT;
|
||||
music.fadeout();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user