1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 10:09:43 +01:00

Unindent gameloop()

You know the drill, diffs are too impatient to properly illustrate an
indentation change without adding a bunch of noise.
This commit is contained in:
Misa 2020-06-14 11:49:23 -07:00 committed by Ethan Lee
parent a8d2994223
commit e294b92785

View file

@ -339,305 +339,305 @@ int main(int argc, char *argv[])
void gameloop() void gameloop()
{ {
while ((game.over30mode || f_accumulator >= 34) && !key.quitProgram) while ((game.over30mode || f_accumulator >= 34) && !key.quitProgram)
{
if (game.over30mode)
{ {
if (game.over30mode) f_accumulator = 0;
}
else
{
f_accumulator = fmodf(f_accumulator, 34);
}
timePrev = time_;
time_ = SDL_GetTicks();
game.infocus = key.isActive;
// Update network per frame.
NETWORK_update();
//timestep limit to 30
const float rawdeltatime = static_cast<float>(time_ - timePrev);
accumulator += rawdeltatime;
Uint32 timesteplimit;
if (game.gamestate == EDITORMODE)
{
timesteplimit = 24;
}
else if (game.gamestate == GAMEMODE || game.gamestate == MAPMODE || game.gamestate == TELEPORTERMODE)
{
timesteplimit = game.gameframerate;
}
else
{
timesteplimit = 34;
}
while (accumulator >= timesteplimit)
{
accumulator = fmodf(accumulator, timesteplimit);
key.Poll();
if(key.toggleFullscreen)
{ {
f_accumulator = 0; if(!gameScreen.isWindowed)
}
else
{
f_accumulator = fmodf(f_accumulator, 34);
}
timePrev = time_;
time_ = SDL_GetTicks();
game.infocus = key.isActive;
// Update network per frame.
NETWORK_update();
//timestep limit to 30
const float rawdeltatime = static_cast<float>(time_ - timePrev);
accumulator += rawdeltatime;
Uint32 timesteplimit;
if (game.gamestate == EDITORMODE)
{
timesteplimit = 24;
}
else if (game.gamestate == GAMEMODE || game.gamestate == MAPMODE || game.gamestate == TELEPORTERMODE)
{
timesteplimit = game.gameframerate;
}
else
{
timesteplimit = 34;
}
while (accumulator >= timesteplimit)
{
accumulator = fmodf(accumulator, timesteplimit);
key.Poll();
if(key.toggleFullscreen)
{ {
if(!gameScreen.isWindowed) SDL_ShowCursor(SDL_DISABLE);
{ SDL_ShowCursor(SDL_ENABLE);
SDL_ShowCursor(SDL_DISABLE);
SDL_ShowCursor(SDL_ENABLE);
}
else
{
SDL_ShowCursor(SDL_ENABLE);
}
if(game.gamestate == EDITORMODE)
{
SDL_ShowCursor(SDL_ENABLE);
}
gameScreen.toggleFullScreen();
game.fullscreen = !game.fullscreen;
key.toggleFullscreen = false;
key.keymap.clear(); //we lost the input due to a new window.
game.press_left = false;
game.press_right = false;
game.press_action = true;
game.press_map = false;
}
if(!game.infocus)
{
Mix_Pause(-1);
Mix_PauseMusic();
if (!game.blackout)
{
FillRect(graphics.backBuffer, 0x00000000);
graphics.bprint(5, 110, "Game paused", 196 - help.glow, 255 - help.glow, 196 - help.glow, true);
graphics.bprint(5, 120, "[click to resume]", 196 - help.glow, 255 - help.glow, 196 - help.glow, true);
graphics.bprint(5, 220, "Press M to mute in game", 164 - help.glow, 196 - help.glow, 164 - help.glow, true);
graphics.bprint(5, 230, "Press N to mute music only", 164 - help.glow, 196 - help.glow, 164 - help.glow, true);
}
graphics.render();
gameScreen.FlipScreen();
//We are minimised, so lets put a bit of a delay to save CPU
SDL_Delay(100);
} }
else else
{ {
Mix_Resume(-1); SDL_ShowCursor(SDL_ENABLE);
Mix_ResumeMusic(); }
game.gametimer++;
graphics.cutscenebarstimer();
switch(game.gamestate)
{ if(game.gamestate == EDITORMODE)
case PRELOADER: {
preloaderlogic(); SDL_ShowCursor(SDL_ENABLE);
break; }
gameScreen.toggleFullScreen();
game.fullscreen = !game.fullscreen;
key.toggleFullscreen = false;
key.keymap.clear(); //we lost the input due to a new window.
game.press_left = false;
game.press_right = false;
game.press_action = true;
game.press_map = false;
}
if(!game.infocus)
{
Mix_Pause(-1);
Mix_PauseMusic();
if (!game.blackout)
{
FillRect(graphics.backBuffer, 0x00000000);
graphics.bprint(5, 110, "Game paused", 196 - help.glow, 255 - help.glow, 196 - help.glow, true);
graphics.bprint(5, 120, "[click to resume]", 196 - help.glow, 255 - help.glow, 196 - help.glow, true);
graphics.bprint(5, 220, "Press M to mute in game", 164 - help.glow, 196 - help.glow, 164 - help.glow, true);
graphics.bprint(5, 230, "Press N to mute music only", 164 - help.glow, 196 - help.glow, 164 - help.glow, true);
}
graphics.render();
gameScreen.FlipScreen();
//We are minimised, so lets put a bit of a delay to save CPU
SDL_Delay(100);
}
else
{
Mix_Resume(-1);
Mix_ResumeMusic();
game.gametimer++;
graphics.cutscenebarstimer();
switch(game.gamestate)
{
case PRELOADER:
preloaderlogic();
break;
#if !defined(NO_CUSTOM_LEVELS) #if !defined(NO_CUSTOM_LEVELS)
case EDITORMODE: case EDITORMODE:
graphics.flipmode = false; graphics.flipmode = false;
//Input //Input
editorinput(); editorinput();
////Logic ////Logic
editorlogic(); editorlogic();
break; break;
#endif #endif
case TITLEMODE: case TITLEMODE:
//Input //Input
titleinput(); titleinput();
////Logic ////Logic
titlelogic(); titlelogic();
break; break;
case GAMEMODE: case GAMEMODE:
if (script.running)
{
script.run();
}
//Update old positions of entities - has to be done BEFORE gameinput!
for (size_t i = 0; i < obj.entities.size(); i++)
{
obj.entities[i].oldxp = obj.entities[i].xp;
obj.entities[i].oldyp = obj.entities[i].yp;
}
gameinput();
gamelogic();
break;
case MAPMODE:
mapinput();
maplogic();
break;
case TELEPORTERMODE:
if(game.useteleporter)
{
teleporterinput();
}
else
{
if (script.running) if (script.running)
{ {
script.run(); script.run();
} }
//Update old positions of entities - has to be done BEFORE gameinput!
for (size_t i = 0; i < obj.entities.size(); i++)
{
obj.entities[i].oldxp = obj.entities[i].xp;
obj.entities[i].oldyp = obj.entities[i].yp;
}
gameinput(); gameinput();
gamelogic();
break;
case MAPMODE:
mapinput();
maplogic();
break;
case TELEPORTERMODE:
if(game.useteleporter)
{
teleporterinput();
}
else
{
if (script.running)
{
script.run();
}
gameinput();
}
maplogic();
break;
case GAMECOMPLETE:
//Input
gamecompleteinput();
//Logic
gamecompletelogic();
break;
case GAMECOMPLETE2:
//Input
gamecompleteinput2();
//Logic
gamecompletelogic2();
break;
case CLICKTOSTART:
break;
default:
break;
} }
maplogic();
break;
case GAMECOMPLETE:
//Input
gamecompleteinput();
//Logic
gamecompletelogic();
break;
case GAMECOMPLETE2:
//Input
gamecompleteinput2();
//Logic
gamecompletelogic2();
break;
case CLICKTOSTART:
break;
default:
break;
} }
//Screen effects timers }
if (game.infocus && game.flashlight > 0)
{
game.flashlight--;
}
if (game.infocus && game.screenshake > 0)
{
game.screenshake--;
graphics.updatescreenshake();
}
if (graphics.screenbuffer->badSignalEffect) //Screen effects timers
{ if (game.infocus && game.flashlight > 0)
UpdateFilter(); {
} game.flashlight--;
}
if (game.infocus && game.screenshake > 0)
{
game.screenshake--;
graphics.updatescreenshake();
}
//We did editorinput, now it's safe to turn this off if (graphics.screenbuffer->badSignalEffect)
key.linealreadyemptykludge = false; {
UpdateFilter();
}
if (game.savemystats) //We did editorinput, now it's safe to turn this off
{ key.linealreadyemptykludge = false;
game.savemystats = false;
game.savestats();
}
//Mute button if (game.savemystats)
{
game.savemystats = false;
game.savestats();
}
//Mute button
#if !defined(NO_CUSTOM_LEVELS) #if !defined(NO_CUSTOM_LEVELS)
bool inEditor = ed.textentry || ed.scripthelppage == 1; bool inEditor = ed.textentry || ed.scripthelppage == 1;
#else #else
bool inEditor = false; bool inEditor = false;
#endif #endif
if (key.isDown(KEYBOARD_m) && game.mutebutton<=0 && !inEditor) if (key.isDown(KEYBOARD_m) && game.mutebutton<=0 && !inEditor)
{ {
game.mutebutton = 8; game.mutebutton = 8;
if (game.muted)
{
game.muted = false;
}
else
{
game.muted = true;
}
}
if(game.mutebutton>0)
{
game.mutebutton--;
}
if (key.isDown(KEYBOARD_n) && game.musicmutebutton <= 0 && !inEditor)
{
game.musicmutebutton = 8;
game.musicmuted = !game.musicmuted;
}
if (game.musicmutebutton > 0)
{
game.musicmutebutton--;
}
if (game.muted) if (game.muted)
{ {
Mix_VolumeMusic(0) ; game.muted = false;
Mix_Volume(-1,0);
} }
else else
{ {
Mix_Volume(-1,MIX_MAX_VOLUME); game.muted = true;
if (game.musicmuted || game.completestop)
{
Mix_VolumeMusic(0);
}
else
{
Mix_VolumeMusic(MIX_MAX_VOLUME);
}
} }
if (key.resetWindow)
{
key.resetWindow = false;
gameScreen.ResizeScreen(-1, -1);
}
music.processmusic();
graphics.processfade();
game.gameclock();
} }
const float alpha = game.over30mode ? static_cast<float>(accumulator) / timesteplimit : 1.0f; if(game.mutebutton>0)
graphics.alpha = alpha;
if (game.infocus)
{ {
switch (game.gamestate) game.mutebutton--;
{
case PRELOADER:
preloaderrender();
break;
case EDITORMODE:
graphics.flipmode = false;
editorrender();
break;
case TITLEMODE:
titlerender();
break;
case GAMEMODE:
gamerender();
break;
case MAPMODE:
maprender();
break;
case TELEPORTERMODE:
teleporterrender();
break;
case GAMECOMPLETE:
gamecompleterender();
break;
case GAMECOMPLETE2:
gamecompleterender2();
break;
case CLICKTOSTART:
help.updateglow();
break;
}
gameScreen.FlipScreen();
} }
if (key.isDown(KEYBOARD_n) && game.musicmutebutton <= 0 && !inEditor)
{
game.musicmutebutton = 8;
game.musicmuted = !game.musicmuted;
}
if (game.musicmutebutton > 0)
{
game.musicmutebutton--;
}
if (game.muted)
{
Mix_VolumeMusic(0) ;
Mix_Volume(-1,0);
}
else
{
Mix_Volume(-1,MIX_MAX_VOLUME);
if (game.musicmuted || game.completestop)
{
Mix_VolumeMusic(0);
}
else
{
Mix_VolumeMusic(MIX_MAX_VOLUME);
}
}
if (key.resetWindow)
{
key.resetWindow = false;
gameScreen.ResizeScreen(-1, -1);
}
music.processmusic();
graphics.processfade();
game.gameclock();
} }
const float alpha = game.over30mode ? static_cast<float>(accumulator) / timesteplimit : 1.0f;
graphics.alpha = alpha;
if (game.infocus)
{
switch (game.gamestate)
{
case PRELOADER:
preloaderrender();
break;
case EDITORMODE:
graphics.flipmode = false;
editorrender();
break;
case TITLEMODE:
titlerender();
break;
case GAMEMODE:
gamerender();
break;
case MAPMODE:
maprender();
break;
case TELEPORTERMODE:
teleporterrender();
break;
case GAMECOMPLETE:
gamecompleterender();
break;
case GAMECOMPLETE2:
gamecompleterender2();
break;
case CLICKTOSTART:
help.updateglow();
break;
}
gameScreen.FlipScreen();
}
}
} }