/*! * Run the code inside the gameloop */ static void runGameLoop(void) { gameLoopStatus = gameLoop(); switch (gameLoopStatus) { case GAMECODE_CONTINUE: case GAMECODE_PLAYVIDEO: break; case GAMECODE_QUITGAME: debug(LOG_MAIN, "GAMECODE_QUITGAME"); stopGameLoop(); startTitleLoop(); // Restart into titleloop break; case GAMECODE_LOADGAME: debug(LOG_MAIN, "GAMECODE_LOADGAME"); stopGameLoop(); initSaveGameLoad(); // Restart and load a savegame break; case GAMECODE_NEWLEVEL: debug(LOG_MAIN, "GAMECODE_NEWLEVEL"); stopGameLoop(); startGameLoop(); // Restart gameloop break; // Never thrown: case GAMECODE_FASTEXIT: case GAMECODE_RESTARTGAME: break; default: debug(LOG_ERROR, "Unknown code returned by gameLoop"); break; } }
/*! * Load a savegame and start into the game loop * Game data should be initialised afterwards, so that startGameLoop is not necessary anymore. */ static bool initSaveGameLoad(void) { // NOTE: always setGameMode correctly before *any* loading routines! SetGameMode(GS_NORMAL); screen_RestartBackDrop(); // load up a save game if (!loadGameInit(saveGameName)) { // FIXME: we really should throw up a error window, but we can't (easily) so I won't. debug(LOG_ERROR, "Trying to load Game %s failed!", saveGameName); debug(LOG_POPUP, "Failed to load a save game! It is either corrupted or a unsupported format.\n\nRestarting main menu."); // FIXME: If we bomb out on a in game load, then we would crash if we don't do the next two calls // Doesn't seem to be a way to tell where we are in game loop to determine if/when we should do the two calls. gameLoopStatus = GAMECODE_FASTEXIT; // clear out all old data stopGameLoop(); startTitleLoop(); // Restart into titleloop SetGameMode(GS_TITLE_SCREEN); return false; } screen_StopBackDrop(); closeLoadingScreen(); // Trap the cursor if cursor snapping is enabled if (war_GetTrapCursor()) { wzGrabMouse(); } if (challengeActive) { addMissionTimerInterface(); } return true; }
/*! * Run the code inside the titleloop */ static void runTitleLoop(void) { switch (titleLoop()) { case TITLECODE_CONTINUE: break; case TITLECODE_QUITGAME: debug(LOG_MAIN, "TITLECODE_QUITGAME"); stopTitleLoop(); { // Create a quit event to halt game loop. SDL_Event quitEvent; quitEvent.type = SDL_QUIT; SDL_PushEvent(&quitEvent); } break; case TITLECODE_SAVEGAMELOAD: { debug(LOG_MAIN, "TITLECODE_SAVEGAMELOAD"); // Restart into gameloop and load a savegame, ONLY on a good savegame load! stopTitleLoop(); if (!initSaveGameLoad()) { // we had a error loading savegame (corrupt?), so go back to title screen? stopGameLoop(); startTitleLoop(); changeTitleMode(TITLE); } break; } case TITLECODE_STARTGAME: debug(LOG_MAIN, "TITLECODE_STARTGAME"); stopTitleLoop(); startGameLoop(); // Restart into gameloop break; case TITLECODE_SHOWINTRO: debug(LOG_MAIN, "TITLECODE_SHOWINTRO"); seq_ClearSeqList(); seq_AddSeqToList("titles.ogg", NULL, NULL, false); seq_AddSeqToList("devastation.ogg", NULL, "devastation.txa", false); seq_StartNextFullScreenVideo(); break; default: debug(LOG_ERROR, "Unknown code returned by titleLoop"); break; } }