mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-30 01:48:15 +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:
@@ -97,8 +97,8 @@ void Graphics::init(void)
|
||||
SDL_memset(fadebars, 0, sizeof(fadebars));
|
||||
|
||||
setfade(0);
|
||||
fademode = 0;
|
||||
ingame_fademode = 0;
|
||||
fademode = FADE_NONE;
|
||||
ingame_fademode = FADE_NONE;
|
||||
|
||||
// initialize everything else to zero
|
||||
backBuffer = NULL;
|
||||
@@ -1451,68 +1451,67 @@ void Graphics::createtextboxflipme(
|
||||
void Graphics::drawfade(void)
|
||||
{
|
||||
int usethisamount = lerp(oldfadeamount, fadeamount);
|
||||
if ((fademode == 1)||(fademode == 4))
|
||||
switch (fademode)
|
||||
{
|
||||
case FADE_FULLY_BLACK:
|
||||
case FADE_START_FADEIN:
|
||||
ClearSurface(backBuffer);
|
||||
}
|
||||
else if(fademode==3)
|
||||
{
|
||||
break;
|
||||
case FADE_FADING_OUT:
|
||||
for (size_t i = 0; i < SDL_arraysize(fadebars); i++)
|
||||
{
|
||||
FillRect(backBuffer, fadebars[i], i * 16, usethisamount, 16, 0x000000 );
|
||||
}
|
||||
}
|
||||
else if(fademode==5 )
|
||||
{
|
||||
break;
|
||||
case FADE_FADING_IN:
|
||||
for (size_t i = 0; i < SDL_arraysize(fadebars); i++)
|
||||
{
|
||||
FillRect(backBuffer, fadebars[i]-usethisamount, i * 16, 500, 16, 0x000000 );
|
||||
}
|
||||
break;
|
||||
case FADE_NONE:
|
||||
case FADE_START_FADEOUT:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Graphics::processfade(void)
|
||||
{
|
||||
oldfadeamount = fadeamount;
|
||||
if (fademode > 1)
|
||||
switch (fademode)
|
||||
{
|
||||
if (fademode == 2)
|
||||
case FADE_START_FADEOUT:
|
||||
for (size_t i = 0; i < SDL_arraysize(fadebars); i++)
|
||||
{
|
||||
//prepare fade out
|
||||
for (size_t i = 0; i < SDL_arraysize(fadebars); i++)
|
||||
{
|
||||
fadebars[i] = -int(fRandom() * 12) * 8;
|
||||
}
|
||||
setfade(0);
|
||||
fademode = 3;
|
||||
fadebars[i] = -int(fRandom() * 12) * 8;
|
||||
}
|
||||
else if (fademode == 3)
|
||||
setfade(0);
|
||||
fademode = FADE_FADING_OUT;
|
||||
break;
|
||||
case FADE_FADING_OUT:
|
||||
fadeamount += 24;
|
||||
if (fadeamount > 416)
|
||||
{
|
||||
fadeamount += 24;
|
||||
if (fadeamount > 416)
|
||||
{
|
||||
fademode = 1; //faded
|
||||
}
|
||||
fademode = FADE_FULLY_BLACK;
|
||||
}
|
||||
else if (fademode == 4)
|
||||
break;
|
||||
case FADE_START_FADEIN:
|
||||
for (size_t i = 0; i < SDL_arraysize(fadebars); i++)
|
||||
{
|
||||
//prepare fade in
|
||||
for (size_t i = 0; i < SDL_arraysize(fadebars); i++)
|
||||
{
|
||||
fadebars[i] = 320 + int(fRandom() * 12) * 8;
|
||||
}
|
||||
setfade(416);
|
||||
fademode = 5;
|
||||
fadebars[i] = 320 + int(fRandom() * 12) * 8;
|
||||
}
|
||||
else if (fademode == 5)
|
||||
setfade(416);
|
||||
fademode = FADE_FADING_IN;
|
||||
break;
|
||||
case FADE_FADING_IN:
|
||||
fadeamount -= 24;
|
||||
if (fadeamount <= 0)
|
||||
{
|
||||
fadeamount -= 24;
|
||||
if (fadeamount <= 0)
|
||||
{
|
||||
fademode = 0; //normal
|
||||
}
|
||||
fademode = FADE_NONE;
|
||||
}
|
||||
case FADE_NONE:
|
||||
case FADE_FULLY_BLACK:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user