// fill buffers with the static screen void initLoadingScreen( bool drawbdrop ) { setupLoadingScreen(); wzShowMouse(false); pie_SetFogStatus(false); // setup the callback.... resSetLoadCallback(loadingScreenCallback); if (drawbdrop) { if (!screen_GetBackDrop()) { pie_LoadBackDrop(SCREEN_RANDOMBDROP); } screen_RestartBackDrop(); } else { screen_StopBackDrop(); } // Start with two cleared buffers as the hacky loading screen code re-uses old buffers to create its effect. pie_ScreenFlip(CLEAR_BLACK); pie_ScreenFlip(CLEAR_BLACK); }
// fill buffers with the static screen void startCreditsScreen(void) { lastChange = gameTime; pie_LoadBackDrop(SCREEN_CREDITS); pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK);//init loading }
// fill buffers with the static screen void startCreditsScreen(void) { SCREENTYPE screen = SCREEN_CREDITS; lastChange = gameTime; // fill buffers pie_LoadBackDrop(screen); pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK);//init loading }
int realmain(int argc, char *argv[]) { // The libcrypto startup stuff... May or may not actually be needed for anything at all. ERR_load_crypto_strings(); // This is needed for descriptive error messages. OpenSSL_add_all_algorithms(); // Don't actually use the EVP functions, so probably not needed. OPENSSL_config(nullptr); // What does this actually do? #ifdef WZ_OS_WIN RAND_screen(); // Uses a screenshot as a random seed, on systems lacking /dev/random. #endif wzMain(argc, argv); int utfargc = argc; const char** utfargv = (const char**)argv; #ifdef WZ_OS_MAC cocoaInit(); #endif debug_init(); debug_register_callback( debug_callback_stderr, NULL, NULL, NULL ); #if defined(WZ_OS_WIN) && defined(DEBUG_INSANE) debug_register_callback( debug_callback_win32debug, NULL, NULL, NULL ); #endif // WZ_OS_WIN && DEBUG_INSANE // ***** // NOTE: Try *NOT* to use debug() output routines without some other method of informing the user. All this output is sent to /dev/nul at this point on some platforms! // ***** if (!getUTF8CmdLine(&utfargc, &utfargv)) { return EXIT_FAILURE; } QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); // make Qt treat all C strings in Warzone as UTF-8 setupExceptionHandler(utfargc, utfargv, version_getFormattedVersionString()); /*** Initialize PhysicsFS ***/ initialize_PhysicsFS(utfargv[0]); /*** Initialize translations ***/ initI18n(); // find early boot info if (!ParseCommandLineEarly(utfargc, utfargv)) { return EXIT_FAILURE; } /* Initialize the write/config directory for PhysicsFS. * This needs to be done __after__ the early commandline parsing, * because the user might tell us to use an alternative configuration * directory. */ initialize_ConfigDir(); /*** Initialize directory structure ***/ make_dir(ScreenDumpPath, "screenshots", NULL); make_dir(SaveGamePath, "savegames", NULL); PHYSFS_mkdir("savegames/campaign"); PHYSFS_mkdir("savegames/skirmish"); make_dir(MultiCustomMapsPath, "maps", NULL); // MUST have this to prevent crashes when getting map PHYSFS_mkdir("music"); PHYSFS_mkdir("logs"); // a place to hold our netplay, mingw crash reports & WZ logs PHYSFS_mkdir("userdata"); // a place to store per-mod data user generated data memset(rulesettag, 0, sizeof(rulesettag)); // tag to add to userdata to find user generated stuff make_dir(MultiPlayersPath, "multiplay", NULL); make_dir(MultiPlayersPath, "multiplay", "players"); if (!customDebugfile) { // there was no custom debug file specified (--debug-file=blah) // so we use our write directory to store our logs. time_t aclock; struct tm *newtime; char buf[PATH_MAX]; time( &aclock ); // Get time in seconds newtime = localtime( &aclock ); // Convert time to struct // Note: We are using fopen(), and not physfs routines to open the file // log name is logs/(or \)WZlog-MMDD_HHMMSS.txt snprintf(buf, sizeof(buf), "%slogs%sWZlog-%02d%02d_%02d%02d%02d.txt", PHYSFS_getWriteDir(), PHYSFS_getDirSeparator(), newtime->tm_mon + 1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec ); debug_register_callback( debug_callback_file, debug_callback_file_init, debug_callback_file_exit, buf ); // FIXME: Change this to LOG_WZ on next release debug(LOG_INFO, "Using %s debug file", buf); } // NOTE: it is now safe to use debug() calls to make sure output gets captured. check_Physfs(); debug(LOG_WZ, "Warzone 2100 - %s", version_getFormattedVersionString()); debug(LOG_WZ, "Using language: %s", getLanguage()); debug(LOG_WZ, "Backend: %s", BACKEND); debug(LOG_MEMORY, "sizeof: SIMPLE_OBJECT=%ld, BASE_OBJECT=%ld, DROID=%ld, STRUCTURE=%ld, FEATURE=%ld, PROJECTILE=%ld", (long)sizeof(SIMPLE_OBJECT), (long)sizeof(BASE_OBJECT), (long)sizeof(DROID), (long)sizeof(STRUCTURE), (long)sizeof(FEATURE), (long)sizeof(PROJECTILE)); /* Put in the writedir root */ sstrcpy(KeyMapPath, "keymap.map"); // initialise all the command line states war_SetDefaultStates(); debug(LOG_MAIN, "initializing"); PhysicsEngineHandler engine; // register abstract physfs filesystem loadConfig(); // parse the command line if (!ParseCommandLine(utfargc, utfargv)) { return EXIT_FAILURE; } // Save new (commandline) settings saveConfig(); // Find out where to find the data scanDataDirs(); // Now we check the mods to see if they exist or not (specified on the command line) // They are all capped at 100 mods max(see clparse.c) // FIX ME: I know this is a bit hackish, but better than nothing for now? { char *modname; char modtocheck[256]; int i = 0; int result = 0; // check global mods for(i=0; i < 100; i++) { modname = global_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/global/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The (global) mod (%s) you have specified doesn't exist!", modname); } else { info("(global) mod (%s) is enabled", modname); } } // check campaign mods for(i=0; i < 100; i++) { modname = campaign_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/campaign/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The mod_ca (%s) you have specified doesn't exist!", modname); } else { info("mod_ca (%s) is enabled", modname); } } // check multiplay mods for(i=0; i < 100; i++) { modname = multiplay_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/multiplay/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The mod_mp (%s) you have specified doesn't exist!", modname); } else { info("mod_mp (%s) is enabled", modname); } } } if (!wzMain2(war_getFSAA(), war_getFullscreen(), war_GetVsync())) { return EXIT_FAILURE; } int w = pie_GetVideoBufferWidth(); int h = pie_GetVideoBufferHeight(); char buf[256]; ssprintf(buf, "Video Mode %d x %d (%s)", w, h, war_getFullscreen() ? "fullscreen" : "window"); addDumpInfo(buf); debug(LOG_MAIN, "Final initialization"); if (!frameInitialise()) { return EXIT_FAILURE; } if (!screenInitialise()) { return EXIT_FAILURE; } if (!pie_LoadShaders()) { return EXIT_FAILURE; } war_SetWidth(pie_GetVideoBufferWidth()); war_SetHeight(pie_GetVideoBufferHeight()); pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK); pal_Init(); pie_LoadBackDrop(SCREEN_RANDOMBDROP); pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK); if (!systemInitialise()) { return EXIT_FAILURE; } //set all the pause states to false setAllPauseStates(false); // Copy this info to be used by the crash handler for the dump file ssprintf(buf,"Using Backend: %s", BACKEND); addDumpInfo(buf); ssprintf(buf,"Using language: %s", getLanguageName()); addDumpInfo(buf); // Do the game mode specific initialisation. switch(GetGameMode()) { case GS_TITLE_SCREEN: startTitleLoop(); break; case GS_SAVEGAMELOAD: initSaveGameLoad(); break; case GS_NORMAL: startGameLoop(); break; default: debug(LOG_ERROR, "Weirdy game status, I'm afraid!!"); break; } #if defined(WZ_CC_MSVC) && defined(DEBUG) debug_MEMSTATS(); #endif debug(LOG_MAIN, "Entering main loop"); wzMain3(); saveConfig(); systemShutdown(); #ifdef WZ_OS_WIN // clean up the memory allocated for the command line conversion for (int i=0; i<argc; i++) { const char*** const utfargvF = &utfargv; free((void *)(*utfargvF)[i]); } free(utfargv); #endif wzShutdown(); debug(LOG_MAIN, "Completed shutting down Warzone 2100"); return EXIT_SUCCESS; }
static GAMECODE renderLoop() { if (bMultiPlayer && !NetPlay.isHostAlive && NetPlay.bComms && !NetPlay.isHost) { intAddInGamePopup(); } int clearMode = 0; if(getDrawShadows()) { clearMode |= CLEAR_SHADOW; } if (loopMissionState == LMS_SAVECONTINUE) { pie_SetFogStatus(false); clearMode = CLEAR_BLACK; } pie_ScreenFlip(clearMode);//gameloopflip HandleClosingWindows(); // Needs to be done outside the pause case. audio_Update(); wzShowMouse(true); INT_RETVAL intRetVal = INT_NONE; if (!paused) { /* Run the in game interface and see if it grabbed any mouse clicks */ if (!rotActive && getWidgetsStatus() && dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING) { intRetVal = intRunWidgets(); } //don't process the object lists if paused or about to quit to the front end if (!gameUpdatePaused() && intRetVal != INT_QUIT) { if( dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING && ( intRetVal == INT_INTERCEPT || ( radarOnScreen && CoordInRadar(mouseX(), mouseY()) && getHQExists(selectedPlayer) ) ) ) { // Using software cursors (when on) for these menus due to a bug in SDL's SDL_ShowCursor() wzSetCursor(CURSOR_DEFAULT); intRetVal = INT_INTERCEPT; } #ifdef DEBUG // check all flag positions for duplicate delivery points checkFactoryFlags(); #endif //handles callbacks for positioning of DP's process3DBuilding(); //ajl. get the incoming netgame messages and process them. // FIXME Previous comment is deprecated. multiPlayerLoop does some other weird stuff, but not that anymore. if (bMultiPlayer) { multiPlayerLoop(); } for (unsigned i = 0; i < MAX_PLAYERS; i++) { for (DROID *psCurr = apsDroidLists[i]; psCurr; psCurr = psCurr->psNext) { // Don't copy the next pointer - if droids somehow get destroyed in the graphics rendering loop, who cares if we crash. calcDroidIllumination(psCurr); } } /* update animations */ animObj_Update(); } if (!consolePaused()) { /* Process all the console messages */ updateConsoleMessages(); } if (!scrollPaused() && !getWarCamStatus() && dragBox3D.status != DRAG_DRAGGING && intMode != INT_INGAMEOP ) { scroll(); } } else // paused { // Using software cursors (when on) for these menus due to a bug in SDL's SDL_ShowCursor() wzSetCursor(CURSOR_DEFAULT); if(dragBox3D.status != DRAG_DRAGGING) { scroll(); } if(InGameOpUp || isInGamePopupUp) // ingame options menu up, run it! { unsigned widgval = widgRunScreen(psWScreen); intProcessInGameOptions(widgval); if(widgval == INTINGAMEOP_QUIT_CONFIRM || widgval == INTINGAMEOP_POPUP_QUIT) { if(gamePaused()) { kf_TogglePauseMode(); } intRetVal = INT_QUIT; } } if(bLoadSaveUp && runLoadSave(true) && strlen(sRequestResult)) { debug( LOG_NEVER, "Returned %s", sRequestResult ); if(bRequestLoad) { loopMissionState = LMS_LOADGAME; NET_InitPlayers(); // otherwise alliances were not cleared sstrcpy(saveGameName, sRequestResult); } else { char msgbuffer[256]= {'\0'}; if (saveInMissionRes()) { if (saveGame(sRequestResult, GTYPE_SAVE_START)) { sstrcpy(msgbuffer, _("GAME SAVED: ")); sstrcat(msgbuffer, sRequestResult); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); } else { ASSERT( false,"Mission Results: saveGame Failed" ); sstrcpy(msgbuffer, _("Could not save game!")); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); deleteSaveGame(sRequestResult); } } else if (bMultiPlayer || saveMidMission()) { if (saveGame(sRequestResult, GTYPE_SAVE_MIDMISSION))//mid mission from [esc] menu { sstrcpy(msgbuffer, _("GAME SAVED: ")); sstrcat(msgbuffer, sRequestResult); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); } else { ASSERT(!"saveGame(sRequestResult, GTYPE_SAVE_MIDMISSION) failed", "Mid Mission: saveGame Failed" ); sstrcpy(msgbuffer, _("Could not save game!")); addConsoleMessage( msgbuffer, LEFT_JUSTIFY, NOTIFY_MESSAGE); deleteSaveGame(sRequestResult); } } else { ASSERT( false, "Attempt to save game with incorrect load/save mode" ); } } } } /* Check for quit */ bool quitting = false; if (intRetVal == INT_QUIT) { if (!loop_GetVideoStatus()) { //quitting from the game to the front end //so get a new backdrop quitting = true; pie_LoadBackDrop(SCREEN_RANDOMBDROP); } } if (!loop_GetVideoStatus() && !quitting) { if (!gameUpdatePaused()) { if (dragBox3D.status != DRAG_DRAGGING && wallDrag.status != DRAG_DRAGGING) { ProcessRadarInput(); } processInput(); //no key clicks or in Intelligence Screen if (intRetVal == INT_NONE && !InGameOpUp && !isInGamePopupUp) { processMouseClickInput(); } displayWorld(); } /* Display the in game interface */ pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON); pie_SetFogStatus(false); if(bMultiPlayer && bDisplayMultiJoiningStatus) { intDisplayMultiJoiningStatus(bDisplayMultiJoiningStatus); setWidgetsStatus(false); } if(getWidgetsStatus()) { intDisplayWidgets(); } pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON); pie_SetFogStatus(true); } pie_GetResetCounts(&loopPieCount, &loopPolyCount, &loopStateChanges); if ((fogStatus & FOG_BACKGROUND) && (loopMissionState == LMS_SAVECONTINUE)) { pie_SetFogStatus(false); } if (!quitting) { /* Check for toggling display mode */ if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) && keyPressed(KEY_RETURN)) { screenToggleMode(); } } // deal with the mission state switch (loopMissionState) { case LMS_CLEAROBJECTS: missionDestroyObjects(); setScriptPause(true); loopMissionState = LMS_SETUPMISSION; break; case LMS_NORMAL: // default break; case LMS_SETUPMISSION: setScriptPause(false); if (!setUpMission(nextMissionType)) { return GAMECODE_QUITGAME; } break; case LMS_SAVECONTINUE: // just wait for this to be changed when the new mission starts break; case LMS_NEWLEVEL: //nextMissionType = MISSION_NONE; nextMissionType = LDS_NONE; return GAMECODE_NEWLEVEL; break; case LMS_LOADGAME: return GAMECODE_LOADGAME; break; default: ASSERT( false, "unknown loopMissionState" ); break; } if (quitting) { pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK);//gameloopflip /* Check for toggling display mode */ if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) && keyPressed(KEY_RETURN)) { screenToggleMode(); } return GAMECODE_QUITGAME; } else if (loop_GetVideoStatus()) { audio_StopAll(); return GAMECODE_PLAYVIDEO; } return GAMECODE_CONTINUE; }
int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // pointer to command line int nShowCmd) // show state of window { FRAME_STATUS frameRet; BOOL quit = FALSE; BOOL Restart = FALSE; BOOL paused = FALSE;//, firstTime = TRUE; BOOL bGlide = FALSE; BOOL bVidMem = FALSE; SDWORD dispBitDepth = DISP_BITDEPTH; SDWORD introVideoControl = 3; GAMECODE loopStatus; iColour* psPaletteBuffer; SDWORD pSize; (void)nShowCmd; // (void)lpCmdLine; (void)hPrevInstance; // initialise all the command line states clStartWindowed = FALSE; clIntroVideo = FALSE; // save debugging info to disk DBOUTPUTFILE("debug.txt"); if (!pie_CheckForDX6()) { DBERROR(("Unable to create DirectX 6 interface.\nPlease ensure DirectX 6 or later is installed.")); return -1; } war_SetDefaultStates(); war_SetRendMode(REND_MODE_HAL); if (InitGlideDLL()) // In ivis02/3dfxdyn.c - returns FALSE if no glide2x.dll is not found { bGlideFound = TRUE; war_SetRendMode(REND_MODE_GLIDE);//default to glide this will be over writen by Registry or Command line if found } init://jump here from the end if re_initialising // initialise memory stuff, moved out of frameinit by ajl. if (!memInitialise()) { return FALSE; } if (!blkInitialise()) { return FALSE; } loadRenderMode();//get the registry entry for clRendMode bDisableLobby = FALSE; // parse the command line // if (bDisableLobby || !NetPlay.bLobbyLaunched) // { if(!reInit) { if(!ParseCommandLine(lpCmdLine,bGlideFound)) { return -1; } } // } // find out if the lobby stuff has been disabled // bDisableLobby = checkDisableLobby(); if (!bDisableLobby && !lobbyInitialise()) // ajl. Init net stuff. Lobby can modify startup conditions like commandline. { return -1; } reInit = FALSE;//just so we dont restart again #ifdef USE_FILE_PATH _chdir(FILE_PATH); #endif //always start windowed toggle to fullscreen later if (war_GetRendMode() == REND_MODE_HAL) { bGlide = FALSE; bVidMem = TRUE; dispBitDepth = DISP_HARDBITDEPTH; } else if (war_GetRendMode() == REND_MODE_REF) { bGlide = FALSE; bVidMem = TRUE; dispBitDepth = DISP_HARDBITDEPTH; } else if (war_GetRendMode() == REND_MODE_RGB) { bGlide = FALSE; bVidMem = FALSE; dispBitDepth = DISP_HARDBITDEPTH; } else if (war_GetRendMode() == REND_MODE_GLIDE) { bGlide = TRUE; bVidMem = FALSE; dispBitDepth = DISP_HARDBITDEPTH; } else { bGlide = FALSE; bVidMem = FALSE; dispBitDepth = DISP_BITDEPTH; } // frameDDEnumerate(); if (!frameInitialise(hInstance, "Warzone 2100", DISP_WIDTH,DISP_HEIGHT,dispBitDepth, !clStartWindowed, bVidMem, bGlide)) { return -1; } if (!wdgLoadAllWDGCatalogs()) { return -1; } pie_SetFogStatus(FALSE); pie_ScreenFlip(CLEAR_BLACK); pie_ScreenFlip(CLEAR_BLACK); if (war_GetRendMode() == REND_MODE_GLIDE) { dbg_SetMessageBoxCallback(fxMBCallback); dbg_SetErrorBoxCallback(fxMBCallback); dbg_SetAssertCallback(fxMBCallback); } if(gameStatus == GS_VIDEO_MODE) { introVideoControl = 0;//play video gameStatus = GS_TITLE_SCREEN; } //load palette psPaletteBuffer = (iColour*)MALLOC(256 * sizeof(iColour)+1); if (psPaletteBuffer == NULL) { DBERROR(("Out of memory")); return -1; } if (!loadFileToBuffer("palette.bin", (UBYTE*)psPaletteBuffer, (256 * sizeof(iColour)+1),(UDWORD*)&pSize)) { DBERROR(("Couldn't load palette data")); return -1; } pal_AddNewPalette(psPaletteBuffer); FREE(psPaletteBuffer); if (war_GetRendMode() == REND_MODE_GLIDE) { pie_LoadBackDrop(SCREEN_RANDOMBDROP,TRUE); } else { pie_LoadBackDrop(SCREEN_RANDOMBDROP,FALSE); } pie_SetFogStatus(FALSE); pie_ScreenFlip(CLEAR_BLACK); quit = FALSE; /* check CDROM drive available */ if ( cdspan_CheckCDAvailable() == FALSE ) { DBERROR( ("Cannot detect CDROM drive\n") ); quit = TRUE; } if (!systemInitialise()) { return -1; } // If windowed mode not requested then toggle to full screen. Doing // it here rather than in the call to frameInitialise fixes a problem // where machines with an NVidia and a 3DFX would kill the 3dfx display. (Definitly a HACK, PD) /* if(!clStartWindowed) { screenToggleMode(); } */ //set all the pause states to false setAllPauseStates(FALSE); while (!quit) { // Do the game mode specific initialisation. switch(gameStatus) { case GS_TITLE_SCREEN: screen_RestartBackDrop(); if (!frontendInitialise("wrf\\frontend.wrf")) { goto exit; } frontendInitialised = TRUE; frontendInitVars(); //if intro required set up the video if (introVideoControl <= 1) { seq_ClearSeqList(); seq_AddSeqToList("eidos-logo.rpl",NULL, NULL, FALSE,0); seq_AddSeqToList("pumpkin.rpl",NULL, NULL, FALSE,0); seq_AddSeqToList("titles.rpl",NULL, NULL, FALSE,0); seq_AddSeqToList("devastation.rpl",NULL,"devastation.txa", FALSE,0); seq_StartNextFullScreenVideo(); introVideoControl = 2; } break; case GS_SAVEGAMELOAD: screen_RestartBackDrop(); gameStatus = GS_NORMAL; // load up a save game if (!loadGameInit(saveGameName,FALSE)) { goto exit; } /*if (!levLoadData(pLevelName, saveGameName)) { return -1; }*/ screen_StopBackDrop(); break; case GS_NORMAL: if (!levLoadData(pLevelName, NULL, 0)) { goto exit; } //after data is loaded check the research stats are valid if (!checkResearchStats()) { DBERROR(("Invalid Research Stats")); goto exit; } //and check the structure stats are valid if (!checkStructureStats()) { DBERROR(("Invalid Structure Stats")); goto exit; } //set a flag for the trigger/event system to indicate initialisation is complete gameInitialised = TRUE; screen_StopBackDrop(); break; case GS_VIDEO_MODE: DBERROR(("Video_mode no longer valid")); if (introVideoControl == 0) { videoInitialised = TRUE; } break; default: DBERROR(("Unknown game status on startup!")); } DBPRINTF(("Entering main loop\n")); Restart = FALSE; //firstTime = TRUE; while (!Restart) { frameRet = frameUpdate(); if (pie_GetRenderEngine() == ENGINE_D3D) { if ( frameRet == FRAME_SETFOCUS ) { D3DTestCooperativeLevel( TRUE ); } else { D3DTestCooperativeLevel( FALSE ); } } switch (frameRet) { case FRAME_KILLFOCUS: paused = TRUE; gameTimeStop(); if (pie_GetRenderEngine() == ENGINE_GLIDE) { if (!gl_Deactivate()) { quit = TRUE; Restart = TRUE; } } mixer_SaveIngameVols(); mixer_RestoreWinVols(); audio_StopAll(); break; case FRAME_SETFOCUS: paused = FALSE; gameTimeStart(); if (!dispModeChange()) { quit = TRUE; Restart = TRUE; } if (pie_GetRenderEngine() == ENGINE_GLIDE) { if (!gl_Reactivate()) { quit = TRUE; Restart = TRUE; } } else if (pie_GetRenderEngine() == ENGINE_D3D) { dtm_RestoreTextures(); } mixer_SaveWinVols(); mixer_RestoreIngameVols(); break; case FRAME_QUIT: quit = TRUE; Restart = TRUE; break; } lastStatus = gameStatus; if ((!paused) && (!quit)) { switch(gameStatus) { case GS_TITLE_SCREEN: pie_SetSwirlyBoxes(TRUE); if (loop_GetVideoStatus()) { videoLoop(); } else { switch(titleLoop()) { case TITLECODE_QUITGAME: DBPRINTF(("TITLECODE_QUITGAME\n")); Restart = TRUE; quit = TRUE; break; // case TITLECODE_ATTRACT: // DBPRINTF(("TITLECODE_ATTRACT\n")); // break; case TITLECODE_SAVEGAMELOAD: DBPRINTF(("TITLECODE_SAVEGAMELOAD\n")); gameStatus = GS_SAVEGAMELOAD; Restart = TRUE; break; case TITLECODE_STARTGAME: DBPRINTF(("TITLECODE_STARTGAME\n")); gameStatus = GS_NORMAL; Restart = TRUE; break; case TITLECODE_SHOWINTRO: DBPRINTF(("TITLECODE_SHOWINTRO\n")); seq_ClearSeqList(); seq_AddSeqToList("eidos-logo.rpl",NULL,NULL, FALSE,0); seq_AddSeqToList("pumpkin.rpl",NULL,NULL, FALSE,0); seq_AddSeqToList("titles.rpl",NULL,NULL, FALSE,0); seq_AddSeqToList("devastation.rpl",NULL,"devastation.txa", FALSE,0); seq_StartNextFullScreenVideo(); introVideoControl = 2;//play the video but dont init the sound system break; case TITLECODE_CONTINUE: break; default: DBERROR(("Unknown code returned by titleLoop")); } } pie_SetSwirlyBoxes(FALSE); break; /* case GS_SAVEGAMELOAD: if (loopNewLevel) { //the start of a campaign/expand mission DBPRINTF(("GAMECODE_NEWLEVEL\n")); loopNewLevel = FALSE; // gameStatus is unchanged, just loading additional data Restart = TRUE; } break; */ case GS_NORMAL: if (loop_GetVideoStatus()) { videoLoop(); } else { loopStatus = gameLoop(); switch(loopStatus) { case GAMECODE_QUITGAME: DBPRINTF(("GAMECODE_QUITGAME\n")); gameStatus = GS_TITLE_SCREEN; Restart = TRUE; /*#ifdef NON_INTERACT quit = TRUE; #endif*/ if(NetPlay.bLobbyLaunched) { // changeTitleMode(QUIT); quit = TRUE; } break; case GAMECODE_FASTEXIT: DBPRINTF(("GAMECODE_FASTEXIT\n")); Restart = TRUE; quit = TRUE; break; case GAMECODE_LOADGAME: DBPRINTF(("GAMECODE_LOADGAME\n")); Restart = TRUE; gameStatus = GS_SAVEGAMELOAD; break; case GAMECODE_PLAYVIDEO: DBPRINTF(("GAMECODE_PLAYVIDEO\n")); //dont schange mode any more gameStatus = GS_VIDEO_MODE; Restart = FALSE; break; case GAMECODE_NEWLEVEL: DBPRINTF(("GAMECODE_NEWLEVEL\n")); // gameStatus is unchanged, just loading additional data Restart = TRUE; break; case GAMECODE_RESTARTGAME: DBPRINTF(("GAMECODE_RESTARTGAME\n")); Restart = TRUE; break; case GAMECODE_CONTINUE: break; default: DBERROR(("Unknown code returned by gameLoop")); } } break; case GS_VIDEO_MODE: DBERROR(("Video_mode no longer valid")); if (loop_GetVideoStatus()) { videoLoop(); } else { if (introVideoControl <= 1) { seq_ClearSeqList(); seq_AddSeqToList("factory.rpl",NULL,NULL, FALSE,0); seq_StartNextFullScreenVideo();//"sequences\\factory.rpl","sequences\\factory.wav"); introVideoControl = 2; } else { DBPRINTF(("VIDEO_QUIT\n")); if (introVideoControl == 2)//finished playing intro video { gameStatus = GS_TITLE_SCREEN; if (videoInitialised) { Restart = TRUE; } introVideoControl = 3; } else { gameStatus = GS_NORMAL; } } } break; default: DBERROR(("Weirdy game status I'm afraid!!")); break; } gameTimeUpdate(); } } // End of !Restart loop. // Do game mode specific shutdown. switch(lastStatus) { case GS_TITLE_SCREEN: if (!frontendShutdown()) { goto exit; } frontendInitialised = FALSE; break; /* case GS_SAVEGAMELOAD: //get the next level to load up gameStatus = GS_NORMAL; break;*/ case GS_NORMAL: if (loopStatus != GAMECODE_NEWLEVEL) { initLoadingScreen(TRUE,FALSE); // returning to f.e. do a loader.render not active pie_EnableFog(FALSE);//dont let the normal loop code set status on fogStatus = 0; if (loopStatus != GAMECODE_LOADGAME) { levReleaseAll(); } } gameInitialised = FALSE; break; case GS_VIDEO_MODE: DBERROR(("Video_mode no longer valid")); if (videoInitialised) { videoInitialised = FALSE; } break; default: DBERROR(("Unknown game status on shutdown!")); break; } } // End of !quit loop. DBPRINTF(("Shuting down application\n")); systemShutdown(); pal_ShutDown(); frameShutDown(); ShutdownGlideDLL(); if (reInit) goto init; PostQuitMessage(0); return 0; exit: DBPRINTF(("Shutting down after fail\n")); systemShutdown(); pal_ShutDown(); frameShutDown(); ShutdownGlideDLL(); PostQuitMessage(1); return 1; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); int utfargc = argc; const char** utfargv = (const char**)argv; #ifdef WZ_OS_MAC cocoaInit(); #endif debug_init(); debug_register_callback( debug_callback_stderr, NULL, NULL, NULL ); #if defined(WZ_OS_WIN) && defined(DEBUG_INSANE) debug_register_callback( debug_callback_win32debug, NULL, NULL, NULL ); #endif // WZ_OS_WIN && DEBUG_INSANE // ***** // NOTE: Try *NOT* to use debug() output routines without some other method of informing the user. All this output is sent to /dev/nul at this point on some platforms! // ***** if (!getUTF8CmdLine(&utfargc, &utfargv)) { return EXIT_FAILURE; } QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); // make Qt treat all C strings in Warzone as UTF-8 setupExceptionHandler(utfargc, utfargv, version_getFormattedVersionString()); /*** Initialize PhysicsFS ***/ initialize_PhysicsFS(utfargv[0]); /*** Initialize translations ***/ initI18n(); // find early boot info if (!ParseCommandLineEarly(utfargc, utfargv)) { return EXIT_FAILURE; } /* Initialize the write/config directory for PhysicsFS. * This needs to be done __after__ the early commandline parsing, * because the user might tell us to use an alternative configuration * directory. */ initialize_ConfigDir(); /*** Initialize directory structure ***/ make_dir(ScreenDumpPath, "screenshots", NULL); make_dir(SaveGamePath, "savegames", NULL); make_dir(MultiCustomMapsPath, "maps", NULL); // MUST have this to prevent crashes when getting map PHYSFS_mkdir("music"); PHYSFS_mkdir("logs"); // a place to hold our netplay, mingw crash reports & WZ logs make_dir(MultiPlayersPath, "multiplay", NULL); make_dir(MultiPlayersPath, "multiplay", "players"); if (!customDebugfile) { // there was no custom debug file specified (--debug-file=blah) // so we use our write directory to store our logs. time_t aclock; struct tm *newtime; char buf[PATH_MAX]; time( &aclock ); // Get time in seconds newtime = localtime( &aclock ); // Convert time to struct // Note: We are using fopen(), and not physfs routines to open the file // log name is logs/(or \)WZlog-MMDD_HHMMSS.txt snprintf(buf, sizeof(buf), "%slogs%sWZlog-%02d%02d_%02d%02d%02d.txt", PHYSFS_getWriteDir(), PHYSFS_getDirSeparator(), newtime->tm_mon, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec ); debug_register_callback( debug_callback_file, debug_callback_file_init, debug_callback_file_exit, buf ); } // NOTE: it is now safe to use debug() calls to make sure output gets captured. check_Physfs(); debug(LOG_WZ, "Warzone 2100 - %s", version_getFormattedVersionString()); debug(LOG_WZ, "Using language: %s", getLanguage()); debug(LOG_MEMORY, "sizeof: SIMPLE_OBJECT=%ld, BASE_OBJECT=%ld, DROID=%ld, STRUCTURE=%ld, FEATURE=%ld, PROJECTILE=%ld", (long)sizeof(SIMPLE_OBJECT), (long)sizeof(BASE_OBJECT), (long)sizeof(DROID), (long)sizeof(STRUCTURE), (long)sizeof(FEATURE), (long)sizeof(PROJECTILE)); /* Put in the writedir root */ sstrcpy(KeyMapPath, "keymap.map"); // initialise all the command line states war_SetDefaultStates(); debug(LOG_MAIN, "initializing"); PhysicsEngineHandler engine; // register abstract physfs filesystem loadConfig(); // parse the command line if (!ParseCommandLine(utfargc, utfargv)) { return EXIT_FAILURE; } // Save new (commandline) settings saveConfig(); // Find out where to find the data scanDataDirs(); // This needs to be done after "scanDataDirs" // for the root cert from cacert. NETinit(true); // Must be run before OpenGL driver is properly initialized due to // strange conflicts - Per if (selfTest) { memset(enabled_debug, 0, sizeof(*enabled_debug) * LOG_LAST); fprintf(stdout, "Carrying out self-test:\n"); playListTest(); audioTest(); soundTest(); } // Now we check the mods to see if they exist or not (specified on the command line) // They are all capped at 100 mods max(see clparse.c) // FIX ME: I know this is a bit hackish, but better than nothing for now? { char *modname; char modtocheck[256]; int i = 0; int result = 0; // check global mods for(i=0; i < 100; i++) { modname = global_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/global/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The (global) mod (%s) you have specified doesn't exist!", modname); } else { info("(global) mod (%s) is enabled", modname); } } // check campaign mods for(i=0; i < 100; i++) { modname = campaign_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/campaign/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The mod_ca (%s) you have specified doesn't exist!", modname); } else { info("mod_ca (%s) is enabled", modname); } } // check multiplay mods for(i=0; i < 100; i++) { modname = multiplay_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/multiplay/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The mod_mp (%s) you have specified doesn't exist!", modname); } else { info("mod_mp (%s) is enabled", modname); } } } debug(LOG_MAIN, "Qt initialization"); QGL::setPreferredPaintEngine(QPaintEngine::OpenGL); // Workaround for incorrect text rendering on nany platforms. // Setting up OpenGL QGLFormat format; format.setDoubleBuffer(true); format.setAlpha(true); int w = pie_GetVideoBufferWidth(); int h = pie_GetVideoBufferHeight(); if (war_getFSAA()) { format.setSampleBuffers(true); format.setSamples(war_getFSAA()); } WzMainWindow mainwindow(QSize(w, h), format); mainwindow.setMinimumResolution(QSize(800, 600)); if (!mainwindow.context()->isValid()) { QMessageBox::critical(NULL, "Oops!", "Warzone2100 failed to create an OpenGL context. This probably means that your graphics drivers are out of date. Try updating them!"); return EXIT_FAILURE; } screenWidth = w; screenHeight = h; if (war_getFullscreen()) { mainwindow.resize(w,h); mainwindow.showFullScreen(); if(w>mainwindow.width()) { w = mainwindow.width(); } if(h>mainwindow.height()) { h = mainwindow.height(); } pie_SetVideoBufferWidth(w); pie_SetVideoBufferHeight(h); } else { mainwindow.show(); mainwindow.setMinimumSize(w, h); mainwindow.setMaximumSize(w, h); } mainwindow.setSwapInterval(war_GetVsync()); war_SetVsync(mainwindow.swapInterval() > 0); mainwindow.setReadyToPaint(); char buf[256]; ssprintf(buf, "Video Mode %d x %d (%s)", w, h, war_getFullscreen() ? "fullscreen" : "window"); addDumpInfo(buf); debug(LOG_MAIN, "Final initialization"); if (!frameInitialise()) { return EXIT_FAILURE; } war_SetWidth(pie_GetVideoBufferWidth()); war_SetHeight(pie_GetVideoBufferHeight()); pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK); pal_Init(); pie_LoadBackDrop(SCREEN_RANDOMBDROP); pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK); if (!systemInitialise()) { return EXIT_FAILURE; } //set all the pause states to false setAllPauseStates(false); /* Runtime unit testing */ if (selfTest) { parseTest(); levTest(); mapTest(); fprintf(stdout, "All tests PASSED!\n"); exit(0); } // Copy this info to be used by the crash handler for the dump file ssprintf(buf,"Using language: %s", getLanguageName()); addDumpInfo(buf); // Do the game mode specific initialisation. switch(GetGameMode()) { case GS_TITLE_SCREEN: startTitleLoop(); break; case GS_SAVEGAMELOAD: initSaveGameLoad(); break; case GS_NORMAL: startGameLoop(); break; default: debug(LOG_ERROR, "Weirdy game status, I'm afraid!!"); break; } #if defined(WZ_CC_MSVC) && defined(DEBUG) debug_MEMSTATS(); #endif debug(LOG_MAIN, "Entering main loop"); app.exec(); saveConfig(); systemShutdown(); debug(LOG_MAIN, "Completed shutting down Warzone 2100"); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int utfargc = argc; const char** utfargv = (const char**)argv; #ifdef WZ_OS_MAC cocoaInit(); #endif debug_init(); debug_register_callback( debug_callback_stderr, NULL, NULL, NULL ); #if defined(WZ_OS_WIN) && defined(DEBUG_INSANE) debug_register_callback( debug_callback_win32debug, NULL, NULL, NULL ); #endif // WZ_OS_WIN && DEBUG_INSANE if (!getUTF8CmdLine(&utfargc, &utfargv)) { return -1; } setupExceptionHandler(utfargc, utfargv); /*** Initialize PhysicsFS ***/ initialize_PhysicsFS(utfargv[0]); /*** Initialize translations ***/ initI18n(); // find early boot info if ( !ParseCommandLineEarly(utfargc, utfargv) ) { return -1; } debug(LOG_WZ, "Using language: %s", getLanguage()); debug(LOG_MEMORY, "sizeof: SIMPLE_OBJECT=%ld, BASE_OBJECT=%ld, DROID=%ld, STRUCTURE=%ld, FEATURE=%ld, PROJECTILE=%ld", (long)sizeof(SIMPLE_OBJECT), (long)sizeof(BASE_OBJECT), (long)sizeof(DROID), (long)sizeof(STRUCTURE), (long)sizeof(FEATURE), (long)sizeof(PROJECTILE)); /* Initialize the write/config directory for PhysicsFS. * This needs to be done __after__ the early commandline parsing, * because the user might tell us to use an alternative configuration * directory. */ initialize_ConfigDir(); /*** Initialize directory structure ***/ make_dir(ScreenDumpPath, "screenshots", NULL); make_dir(SaveGamePath, "savegame", NULL); make_dir(MultiCustomMapsPath, "maps", NULL); // MUST have this to prevent crashes when getting map PHYSFS_mkdir("music"); PHYSFS_mkdir("logs"); // a place to hold our netplay, mingw crash reports & WZ logs make_dir(MultiPlayersPath, "multiplay", NULL); make_dir(MultiPlayersPath, "multiplay", "players"); if (!customDebugfile) { // there was no custom debug file specified (--debug-file=blah) // so we use our write directory to store our logs. time_t aclock; struct tm *newtime; char buf[PATH_MAX]; time( &aclock ); // Get time in seconds newtime = localtime( &aclock ); // Convert time to struct // Note: We are using fopen(), and not physfs routines to open the file // log name is logs/(or \)WZlog-MMDD_HHMMSS.txt snprintf(buf, sizeof(buf), "%slogs%sWZlog-%02d%02d_%02d%02d%02d.txt", PHYSFS_getWriteDir(), PHYSFS_getDirSeparator(), newtime->tm_mon, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec ); debug_register_callback( debug_callback_file, debug_callback_file_init, debug_callback_file_exit, buf ); } debug(LOG_WZ, "Warzone 2100 - %s", version_getFormattedVersionString()); /* Put these files in the writedir root */ setRegistryFilePath("config"); sstrcpy(KeyMapPath, "keymap.map"); // initialise all the command line states war_SetDefaultStates(); debug(LOG_MAIN, "initializing"); loadConfig(); NETinit(true); // parse the command line if (!ParseCommandLine(utfargc, utfargv)) { return -1; } // Save new (commandline) settings saveConfig(); // Find out where to find the data scanDataDirs(); // Must be run before OpenGL driver is properly initialized due to // strange conflicts - Per if (selfTest) { memset(enabled_debug, 0, sizeof(*enabled_debug) * LOG_LAST); fprintf(stdout, "Carrying out self-test:\n"); playListTest(); audioTest(); soundTest(); } // Now we check the mods to see if they exsist or not (specified on the command line) // They are all capped at 100 mods max(see clparse.c) // FIX ME: I know this is a bit hackish, but better than nothing for now? { char *modname; char modtocheck[256]; int i = 0; int result = 0; // check global mods for(i=0; i < 100; i++) { modname = global_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/global/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The (global) mod (%s) you have specified doesn't exist!", modname); } else { info("(global) mod (%s) is enabled", modname); } } // check campaign mods for(i=0; i < 100; i++) { modname = campaign_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/campaign/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The mod_ca (%s) you have specified doesn't exist!", modname); } else { info("mod_ca (%s) is enabled", modname); } } // check multiplay mods for(i=0; i < 100; i++) { modname = multiplay_mods[i]; if (modname == NULL) { break; } ssprintf(modtocheck, "mods/multiplay/%s", modname); result = PHYSFS_exists(modtocheck); result |= PHYSFS_isDirectory(modtocheck); if (!result) { debug(LOG_ERROR, "The mod_mp (%s) you have specified doesn't exist!", modname); } else { info("mod_mp (%s) is enabled", modname); } } } if (!frameInitialise( "Warzone 2100", pie_GetVideoBufferWidth(), pie_GetVideoBufferHeight(), pie_GetVideoBufferDepth(), war_getFSAA(), war_getFullscreen(), war_GetVsync())) { return -1; } war_SetWidth(pie_GetVideoBufferWidth()); war_SetHeight(pie_GetVideoBufferHeight()); pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK); pal_Init(); pie_LoadBackDrop(SCREEN_RANDOMBDROP); pie_SetFogStatus(false); pie_ScreenFlip(CLEAR_BLACK); if (!systemInitialise()) { return -1; } //set all the pause states to false setAllPauseStates(false); /* Runtime unit testing */ if (selfTest) { tagTest(); parseTest(); levTest(); mapTest(); fprintf(stdout, "All tests PASSED!\n"); exit(0); } { // Copy this info to be used by the crash handler for the dump file char buf[256]; ssprintf(buf,"Using language: %s", getLanguageName()); addDumpInfo(buf); } // Do the game mode specific initialisation. switch(GetGameMode()) { case GS_TITLE_SCREEN: startTitleLoop(); break; case GS_SAVEGAMELOAD: initSaveGameLoad(); break; case GS_NORMAL: startGameLoop(); break; default: debug(LOG_ERROR, "Weirdy game status, I'm afraid!!"); break; } debug(LOG_MAIN, "Entering main loop"); // Enter the mainloop mainLoop(); debug(LOG_MAIN, "Shutting down Warzone 2100"); #if defined(WZ_CC_MSVC) && defined(DEBUG) debug_MEMSTATS(); #endif atexit(systemShutdown); return EXIT_SUCCESS; }