void startSectionTransition(void) { transitionStartTime = SDL_GetTicks(); prepareScene(); presentScene(); expireTexts(); }
void cleanup(void) { SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Cleaning up ..."); SDL_DestroyRenderer(app.renderer); SDL_DestroyWindow(app.window); destroyLookups(); destroyTextures(); expireTexts(1); destroyFonts(); destroySounds(); destroyGame(); destroyFighterDefs(); destroyCapitalShipDefs(); destroyBulletDefs(); destroyItemDefs(); destroyStarSystems(); destroyBattle(); destroyGalacticMap(); destroyWidgets(); destroyResources(); destroyCredits(); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Done"); TTF_Quit(); SDL_Quit(); }
int main(int argc, char *argv[]) { float td; long then, lastFrameTime, frames; long expireTextTimer; SDL_Event event; memset(&app, 0, sizeof(App)); memset(&dev, 0, sizeof(Dev)); handleLoggingArgs(argc, argv); atexit(cleanup); srand(time(NULL)); init18N(argc, argv); initLookups(); initSDL(); initGameSystem(); createScreenshotFolder(); if (fileExists(getSaveFilePath(SAVE_FILENAME))) { loadGame(); } handleMissionArgs(argc, argv); dev.fps = frames = td = 0; then = SDL_GetTicks(); lastFrameTime = SDL_GetTicks() + 1000; expireTextTimer = SDL_GetTicks() + (1000 * 10); while (1) { td += (SDL_GetTicks() - then); then = SDL_GetTicks(); while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_MOUSEMOTION: doMouseMotion(&event.motion); break; case SDL_MOUSEWHEEL: doMouseWheel(&event.wheel); break; case SDL_MOUSEBUTTONDOWN: doMouseDown(&event.button); break; case SDL_MOUSEBUTTONUP: doMouseUp(&event.button); break; case SDL_KEYDOWN: doKeyDown(&event.key); break; case SDL_KEYUP: doKeyUp(&event.key); break; case SDL_QUIT: exit(0); break; } } if (app.modalDialog.type != MD_NONE) { doModalDialog(); } while (td >= LOGIC_RATE) { /* let the delegate decide during logic() */ app.doTrophyAlerts = 0; app.delegate.logic(); td -= LOGIC_RATE; if (app.doTrophyAlerts) { doTrophyAlerts(); } if (app.resetTimeDelta) { td = 0; then = SDL_GetTicks(); app.resetTimeDelta = 0; } game.stats[STAT_TIME]++; } prepareScene(); app.delegate.draw(); if (app.doTrophyAlerts) { drawTrophyAlert(); } if (app.modalDialog.type != MD_NONE) { drawModalDialog(); } presentScene(); doDevKeys(); frames++; if (SDL_GetTicks() > lastFrameTime) { dev.fps = frames; frames = 0; lastFrameTime = SDL_GetTicks() + 1000; if (dev.takeScreenshots) { saveScreenshot(); } } if (isControl(CONTROL_SCREENSHOT)) { saveScreenshot(); clearControl(CONTROL_SCREENSHOT); } if (SDL_GetTicks() > expireTextTimer) { expireTexts(0); expireTextTimer = SDL_GetTicks() + (1000 * 10); } /* don't save more than once per request, and not in the middle of battle */ if (app.saveGame && battle.status != MS_IN_PROGRESS) { saveGame(); app.saveGame = 0; } /* always zero the mouse motion */ app.mouse.dx = app.mouse.dy = 0; SDL_Delay(1); } return 0; }