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:
@@ -1718,7 +1718,7 @@ void editorlogic(void)
|
||||
ed.notedelay--;
|
||||
}
|
||||
|
||||
if (graphics.fademode == 1)
|
||||
if (graphics.fademode == FADE_FULLY_BLACK)
|
||||
{
|
||||
//Return to game
|
||||
graphics.titlebg.colstate = 10;
|
||||
@@ -1896,7 +1896,7 @@ static void editormenuactionpress(void)
|
||||
//Quit without saving
|
||||
music.playef(11);
|
||||
music.fadeout();
|
||||
graphics.fademode = 2;
|
||||
graphics.fademode = FADE_START_FADEOUT;
|
||||
break;
|
||||
case 2:
|
||||
//Go back to editor
|
||||
@@ -1914,7 +1914,7 @@ static void editormenuactionpress(void)
|
||||
void editorinput(void)
|
||||
{
|
||||
extern editorclass ed;
|
||||
if (graphics.fademode == 3 /* fading out */)
|
||||
if (graphics.fademode == FADE_FADING_OUT)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -2346,7 +2346,7 @@ void editorinput(void)
|
||||
|
||||
if (ed.saveandquit)
|
||||
{
|
||||
graphics.fademode = 2; // quit editor
|
||||
graphics.fademode = FADE_START_FADEOUT; /* quit editor */
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user