int realmain(int argc, char *argv[]) { int utfargc = argc; const char **utfargv = (const char **)argv; wzMain(argc, argv); // init Qt integration first // 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 #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; } 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"); 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 (!wzMainScreenSetup(war_getFSAA(), war_getFullscreen(), war_GetVsync())) { return EXIT_FAILURE; } 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)); 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"); wzMainEventLoop(); 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; }
/* Initialise the double buffered display */ bool screenInitialise() { char buf[256]; GLint glMaxTUs; GLenum err; glErrors(); err = glewInit(); if (GLEW_OK != err) { debug(LOG_FATAL, "Error: %s", glewGetErrorString(err)); exit(1); } // Copy this info to be used by the crash handler for the dump file ssprintf(buf, "OpenGL Vendor: %s", glGetString(GL_VENDOR)); addDumpInfo(buf); ssprintf(buf, "OpenGL Renderer: %s", glGetString(GL_RENDERER)); addDumpInfo(buf); ssprintf(buf, "OpenGL Version: %s", glGetString(GL_VERSION)); addDumpInfo(buf); if (GLEW_VERSION_2_0) { ssprintf(buf, "OpenGL GLSL Version : %s", glGetString(GL_SHADING_LANGUAGE_VERSION)); addDumpInfo(buf); } /* Dump general information about OpenGL implementation to the console and the dump file */ ssprintf(buf, "OpenGL Vendor: %s", glGetString(GL_VENDOR)); addDumpInfo(buf); debug(LOG_3D, "%s", buf); ssprintf(buf, "OpenGL Renderer: %s", glGetString(GL_RENDERER)); addDumpInfo(buf); debug(LOG_3D, "%s", buf); ssprintf(buf, "OpenGL Version: %s", glGetString(GL_VERSION)); addDumpInfo(buf); debug(LOG_3D, "%s", buf); ssprintf(buf, "GLEW Version: %s", glewGetString(GLEW_VERSION)); addDumpInfo(buf); debug(LOG_3D, "%s", buf); /* Dump extended information about OpenGL implementation to the console */ debug(LOG_3D, "OpenGL Extensions : %s", glGetString(GL_EXTENSIONS)); // FIXME This is too much for MAX_LEN_LOG_LINE debug(LOG_3D, "Supported OpenGL extensions:"); debug(LOG_3D, " * OpenGL 1.2 %s supported!", GLEW_VERSION_1_2 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 1.3 %s supported!", GLEW_VERSION_1_3 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 1.4 %s supported!", GLEW_VERSION_1_4 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 1.5 %s supported!", GLEW_VERSION_1_5 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 2.0 %s supported!", GLEW_VERSION_2_0 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 2.1 %s supported!", GLEW_VERSION_2_1 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 3.0 %s supported!", GLEW_VERSION_3_0 ? "is" : "is NOT"); debug(LOG_3D, " * Texture compression %s supported.", GLEW_ARB_texture_compression ? "is" : "is NOT"); debug(LOG_3D, " * Two side stencil %s supported.", GLEW_EXT_stencil_two_side ? "is" : "is NOT"); debug(LOG_3D, " * ATI separate stencil is%s supported.", GLEW_ATI_separate_stencil ? "" : " NOT"); debug(LOG_3D, " * Stencil wrap %s supported.", GLEW_EXT_stencil_wrap ? "is" : "is NOT"); debug(LOG_3D, " * Anisotropic filtering %s supported.", GLEW_EXT_texture_filter_anisotropic ? "is" : "is NOT"); debug(LOG_3D, " * Rectangular texture %s supported.", GLEW_ARB_texture_rectangle ? "is" : "is NOT"); debug(LOG_3D, " * FrameBuffer Object (FBO) %s supported.", GLEW_EXT_framebuffer_object ? "is" : "is NOT"); debug(LOG_3D, " * Vertex Buffer Object (VBO) %s supported.", GLEW_ARB_vertex_buffer_object ? "is" : "is NOT"); debug(LOG_3D, " * NPOT %s supported.", GLEW_ARB_texture_non_power_of_two ? "is" : "is NOT"); debug(LOG_3D, " * texture cube_map %s supported.", GLEW_ARB_texture_cube_map ? "is" : "is NOT"); glGetIntegerv(GL_MAX_TEXTURE_UNITS, &glMaxTUs); debug(LOG_3D, " * Total number of Texture Units (TUs) supported is %d.", (int) glMaxTUs); screenWidth = MAX(screenWidth, 640); screenHeight = MAX(screenHeight, 480); /* Dump information about OpenGL 2.0+ implementation to the console and the dump file */ if (GLEW_VERSION_2_0) { GLint glMaxTIUs, glMaxTCs, glMaxTIUAs, glmaxSamples, glmaxSamplesbuf; debug(LOG_3D, " * OpenGL GLSL Version : %s", glGetString(GL_SHADING_LANGUAGE_VERSION)); ssprintf(buf, "OpenGL GLSL Version : %s", glGetString(GL_SHADING_LANGUAGE_VERSION)); addDumpInfo(buf); glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &glMaxTIUs); debug(LOG_3D, " * Total number of Texture Image Units (TIUs) supported is %d.", (int) glMaxTIUs); glGetIntegerv(GL_MAX_TEXTURE_COORDS, &glMaxTCs); debug(LOG_3D, " * Total number of Texture Coords (TCs) supported is %d.", (int) glMaxTCs); glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB,&glMaxTIUAs); debug(LOG_3D, " * Total number of Texture Image Units ARB(TIUAs) supported is %d.", (int) glMaxTIUAs); glGetIntegerv(GL_SAMPLE_BUFFERS, &glmaxSamplesbuf); debug(LOG_3D, " * (current) Max Sample buffer is %d.", (int) glmaxSamplesbuf); glGetIntegerv(GL_SAMPLES, &glmaxSamples); debug(LOG_3D, " * (current) Max Sample level is %d.", (int) glmaxSamples); pie_LoadShaders(); } else { debug(LOG_FATAL, "OpenGL 2.0 is not supported by your system. The game require this. Please upgrade your graphics drivers, if possible."); exit(1); } glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glErrors(); return true; }
/* Initialise the double buffered display */ bool screenInitialise() { GLint glMaxTUs; GLenum err; err = glewInit(); if (GLEW_OK != err) { debug(LOG_FATAL, "Error: %s", glewGetErrorString(err)); exit(1); } /* Dump general information about OpenGL implementation to the console and the dump file */ ssprintf(opengl.vendor, "OpenGL Vendor: %s", glGetString(GL_VENDOR)); addDumpInfo(opengl.vendor); debug(LOG_3D, "%s", opengl.vendor); ssprintf(opengl.renderer, "OpenGL Renderer: %s", glGetString(GL_RENDERER)); addDumpInfo(opengl.renderer); debug(LOG_3D, "%s", opengl.renderer); ssprintf(opengl.version, "OpenGL Version: %s", glGetString(GL_VERSION)); addDumpInfo(opengl.version); debug(LOG_3D, "%s", opengl.version); ssprintf(opengl.GLEWversion, "GLEW Version: %s", glewGetString(GLEW_VERSION)); if (strncmp(opengl.GLEWversion, "1.9.", 4) == 0) // work around known bug with KHR_debug extension support in this release { debug(LOG_WARNING, "Your version of GLEW is old and buggy, please upgrade to at least version 1.10."); khr_debug = false; } else { khr_debug = GLEW_KHR_debug; } addDumpInfo(opengl.GLEWversion); debug(LOG_3D, "%s", opengl.GLEWversion); GLubyte const *extensionsBegin = glGetString(GL_EXTENSIONS); if (extensionsBegin == nullptr) { static GLubyte const emptyString[] = ""; extensionsBegin = emptyString; } GLubyte const *extensionsEnd = extensionsBegin + strlen((char const *)extensionsBegin); std::vector<std::string> glExtensions; for (GLubyte const *i = extensionsBegin; i < extensionsEnd;) { GLubyte const *j = std::find(i, extensionsEnd, ' '); glExtensions.push_back(std::string(i, j)); i = j + 1; } /* Dump extended information about OpenGL implementation to the console */ std::string line; for (unsigned n = 0; n < glExtensions.size(); ++n) { std::string word = " "; word += glExtensions[n]; if (n + 1 != glExtensions.size()) { word += ','; } if (line.size() + word.size() > 160) { debug(LOG_3D, "OpenGL Extensions:%s", line.c_str()); line.clear(); } line += word; } debug(LOG_3D, "OpenGL Extensions:%s", line.c_str()); debug(LOG_3D, "Notable OpenGL features:"); debug(LOG_3D, " * OpenGL 1.2 %s supported!", GLEW_VERSION_1_2 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 1.3 %s supported!", GLEW_VERSION_1_3 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 1.4 %s supported!", GLEW_VERSION_1_4 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 1.5 %s supported!", GLEW_VERSION_1_5 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 2.0 %s supported!", GLEW_VERSION_2_0 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 2.1 %s supported!", GLEW_VERSION_2_1 ? "is" : "is NOT"); debug(LOG_3D, " * OpenGL 3.0 %s supported!", GLEW_VERSION_3_0 ? "is" : "is NOT"); debug(LOG_3D, " * Texture compression %s supported.", GLEW_ARB_texture_compression ? "is" : "is NOT"); debug(LOG_3D, " * Two side stencil %s supported.", GLEW_EXT_stencil_two_side ? "is" : "is NOT"); debug(LOG_3D, " * ATI separate stencil is%s supported.", GLEW_ATI_separate_stencil ? "" : " NOT"); debug(LOG_3D, " * Stencil wrap %s supported.", GLEW_EXT_stencil_wrap ? "is" : "is NOT"); debug(LOG_3D, " * Anisotropic filtering %s supported.", GLEW_EXT_texture_filter_anisotropic ? "is" : "is NOT"); debug(LOG_3D, " * Rectangular texture %s supported.", GLEW_ARB_texture_rectangle ? "is" : "is NOT"); debug(LOG_3D, " * FrameBuffer Object (FBO) %s supported.", GLEW_EXT_framebuffer_object ? "is" : "is NOT"); debug(LOG_3D, " * ARB Vertex Buffer Object (VBO) %s supported.", GLEW_ARB_vertex_buffer_object ? "is" : "is NOT"); debug(LOG_3D, " * NPOT %s supported.", GLEW_ARB_texture_non_power_of_two ? "is" : "is NOT"); debug(LOG_3D, " * texture cube_map %s supported.", GLEW_ARB_texture_cube_map ? "is" : "is NOT"); glGetIntegerv(GL_MAX_TEXTURE_UNITS, &glMaxTUs); debug(LOG_3D, " * Total number of Texture Units (TUs) supported is %d.", (int) glMaxTUs); debug(LOG_3D, " * GL_ARB_timer_query %s supported!", GLEW_ARB_timer_query ? "is" : "is NOT"); debug(LOG_3D, " * KHR_DEBUG support %s detected", khr_debug ? "was" : "was NOT"); if (!GLEW_VERSION_2_0) { debug(LOG_FATAL, "OpenGL 2.0 not supported! Please upgrade your drivers."); return false; } screenWidth = MAX(screenWidth, 640); screenHeight = MAX(screenHeight, 480); std::pair<int, int> glslVersion(0, 0); sscanf((char const *)glGetString(GL_SHADING_LANGUAGE_VERSION), "%d.%d", &glslVersion.first, &glslVersion.second); /* Dump information about OpenGL 2.0+ implementation to the console and the dump file */ GLint glMaxTIUs, glMaxTCs, glMaxTIUAs, glmaxSamples, glmaxSamplesbuf; debug(LOG_3D, " * OpenGL GLSL Version : %s", glGetString(GL_SHADING_LANGUAGE_VERSION)); ssprintf(opengl.GLSLversion, "OpenGL GLSL Version : %s", glGetString(GL_SHADING_LANGUAGE_VERSION)); addDumpInfo(opengl.GLSLversion); glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &glMaxTIUs); debug(LOG_3D, " * Total number of Texture Image Units (TIUs) supported is %d.", (int) glMaxTIUs); glGetIntegerv(GL_MAX_TEXTURE_COORDS, &glMaxTCs); debug(LOG_3D, " * Total number of Texture Coords (TCs) supported is %d.", (int) glMaxTCs); glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &glMaxTIUAs); debug(LOG_3D, " * Total number of Texture Image Units ARB(TIUAs) supported is %d.", (int) glMaxTIUAs); glGetIntegerv(GL_SAMPLE_BUFFERS, &glmaxSamplesbuf); debug(LOG_3D, " * (current) Max Sample buffer is %d.", (int) glmaxSamplesbuf); glGetIntegerv(GL_SAMPLES, &glmaxSamples); debug(LOG_3D, " * (current) Max Sample level is %d.", (int) glmaxSamples); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); pie_Skybox_Init(); // Generate backdrop render backdropGfx = new GFX(GFX_TEXTURE, GL_TRIANGLE_STRIP, 2); if (GLEW_ARB_timer_query) { glGenQueries(PERF_COUNT, perfpos); } if (khr_debug) { glDebugMessageCallback((GLDEBUGPROC)khr_callback, NULL); glEnable(GL_DEBUG_OUTPUT); // Do not want to output notifications. Some drivers spam them too much. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, NULL, GL_FALSE); debug(LOG_3D, "Enabling KHR_debug message callback"); } return true; }
// load up the data for a level bool levLoadData(char const *name, Sha256 const *hash, char *pSaveName, GAME_TYPE saveType) { LEVEL_DATASET *psNewLevel, *psBaseData, *psChangeLevel; bool bCamChangeSaveGame; debug(LOG_WZ, "Loading level %s hash %s (%s, type %d)", name, hash == nullptr ? "builtin" : hash->toString().c_str(), pSaveName, (int)saveType); if (saveType == GTYPE_SAVE_START || saveType == GTYPE_SAVE_MIDMISSION) { if (!levReleaseAll()) { debug(LOG_ERROR, "Failed to unload old data"); return false; } } levelLoadType = saveType; // find the level dataset psNewLevel = levFindDataSet(name, hash); if (psNewLevel == nullptr) { debug(LOG_INFO, "Dataset %s not found - trying to load as WRF", name); return levLoadSingleWRF(name); } debug(LOG_WZ, "** Data set found is %s type %d", psNewLevel->pName, (int)psNewLevel->type); /* Keep a copy of the present level name */ sstrcpy(currentLevelName, name); bCamChangeSaveGame = false; if (pSaveName && saveType == GTYPE_SAVE_START) { if (psNewLevel->psChange != nullptr) { bCamChangeSaveGame = true; debug(LOG_WZ, "** CAMCHANGE FOUND"); } } // select the change dataset if there is one psChangeLevel = nullptr; if (((psNewLevel->psChange != nullptr) && (psCurrLevel != nullptr)) || bCamChangeSaveGame) { //store the level name debug(LOG_WZ, "Found CAMCHANGE dataset"); psChangeLevel = psNewLevel; psNewLevel = psNewLevel->psChange; } // ensure the correct dataset is loaded if (psNewLevel->type == LDS_CAMPAIGN) { debug(LOG_ERROR, "Cannot load a campaign dataset (%s)", psNewLevel->pName); return false; } else { if (psCurrLevel != nullptr) { if ((psCurrLevel->psBaseData != psNewLevel->psBaseData) || (psCurrLevel->type < LDS_NONE && psNewLevel->type >= LDS_NONE) || (psCurrLevel->type >= LDS_NONE && psNewLevel->type < LDS_NONE)) { // there is a dataset loaded but it isn't the correct one debug(LOG_WZ, "Incorrect base dataset loaded (%p != %p, %d - %d)", psCurrLevel->psBaseData, psNewLevel->psBaseData, (int)psCurrLevel->type, (int)psNewLevel->type); if (!levReleaseAll()) // this sets psCurrLevel to NULL { debug(LOG_ERROR, "Failed to release old data"); return false; } } else { debug(LOG_WZ, "Correct base dataset already loaded."); } } // setup the correct dataset to load if necessary if (psCurrLevel == nullptr) { if (psNewLevel->psBaseData != nullptr) { debug(LOG_WZ, "Setting base dataset to load: %s", psNewLevel->psBaseData->pName); } psBaseData = psNewLevel->psBaseData; } else { debug(LOG_WZ, "No base dataset to load"); psBaseData = nullptr; } } if (!rebuildSearchPath(psNewLevel->dataDir, true, psNewLevel->realFileName)) { debug(LOG_ERROR, "Failed to rebuild search path"); return false; } // reset the old mission data if necessary if (psCurrLevel != nullptr) { debug(LOG_WZ, "Reseting old mission data"); if (!levReleaseMissionData()) { debug(LOG_ERROR, "Failed to unload old mission data"); return false; } } // need to free the current map and droids etc for a save game if (psBaseData == nullptr && pSaveName != nullptr) { if (!saveGameReset()) { debug(LOG_ERROR, "Failed to saveGameReset()!"); return false; } } // initialise if necessary if (psNewLevel->type == LDS_COMPLETE || psBaseData != nullptr) { debug(LOG_WZ, "Calling stageOneInitialise!"); if (!stageOneInitialise()) { debug(LOG_ERROR, "Failed stageOneInitialise!"); return false; } } // load up a base dataset if necessary if (psBaseData != nullptr) { debug(LOG_WZ, "Loading base dataset %s", psBaseData->pName); for (int i = 0; i < LEVEL_MAXFILES; i++) { if (psBaseData->apDataFiles[i]) { // load the data debug(LOG_WZ, "Loading [directory: %s] %s ...", PHYSFS_getRealDir(psBaseData->apDataFiles[i]), psBaseData->apDataFiles[i]); if (!resLoad(psBaseData->apDataFiles[i], i)) { debug(LOG_ERROR, "Failed resLoad(%s)!", psBaseData->apDataFiles[i]); return false; } } } } if (psNewLevel->type == LDS_CAMCHANGE) { if (!campaignReset()) { debug(LOG_ERROR, "Failed campaignReset()!"); return false; } } if (psNewLevel->game == -1) //no .gam file to load - BETWEEN missions (for Editor games only) { ASSERT(psNewLevel->type == LDS_BETWEEN, "Only BETWEEN missions do not need a .gam file"); debug(LOG_WZ, "No .gam file for level: BETWEEN mission"); if (pSaveName != nullptr) { if (psBaseData != nullptr) { if (!stageTwoInitialise()) { debug(LOG_ERROR, "Failed stageTwoInitialise()!"); return false; } } //set the mission type before the saveGame data is loaded if (saveType == GTYPE_SAVE_MIDMISSION) { debug(LOG_WZ, "Init mission stuff"); if (!startMissionSave(psNewLevel->type)) { debug(LOG_ERROR, "Failed startMissionSave(%d)!", psNewLevel->type); return false; } debug(LOG_NEVER, "dataSetSaveFlag"); dataSetSaveFlag(); } debug(LOG_NEVER, "Loading savegame: %s", pSaveName); if (!loadGame(pSaveName, false, true, true)) { debug(LOG_ERROR, "Failed loadGame(%s)!", pSaveName); return false; } } if (pSaveName == nullptr || saveType == GTYPE_SAVE_START) { debug(LOG_NEVER, "Start mission - no .gam"); if (!startMission((LEVEL_TYPE)psNewLevel->type, nullptr)) { debug(LOG_ERROR, "Failed startMission(%d)!", psNewLevel->type); return false; } } } //we need to load up the save game data here for a camchange if (bCamChangeSaveGame) { if (pSaveName != nullptr) { if (psBaseData != nullptr) { if (!stageTwoInitialise()) { debug(LOG_ERROR, "Failed stageTwoInitialise() [camchange]!"); return false; } } debug(LOG_NEVER, "loading savegame: %s", pSaveName); if (!loadGame(pSaveName, false, true, true)) { debug(LOG_ERROR, "Failed loadGame(%s)!", pSaveName); return false; } campaignReset(); } } // load the new data debug(LOG_NEVER, "Loading mission dataset: %s", psNewLevel->pName); for (int i = 0; i < LEVEL_MAXFILES; i++) { if (psNewLevel->game == i) { // do some more initialising if necessary if (psNewLevel->type == LDS_COMPLETE || psNewLevel->type >= LDS_MULTI_TYPE_START || (psBaseData != nullptr && !bCamChangeSaveGame)) { if (!stageTwoInitialise()) { debug(LOG_ERROR, "Failed stageTwoInitialise() [newdata]!"); return false; } } // load a savegame if there is one - but not if already done so if (pSaveName != nullptr && !bCamChangeSaveGame) { //set the mission type before the saveGame data is loaded if (saveType == GTYPE_SAVE_MIDMISSION) { debug(LOG_WZ, "Init mission stuff"); if (!startMissionSave(psNewLevel->type)) { debug(LOG_ERROR, "Failed startMissionSave(%d)!", psNewLevel->type); return false; } debug(LOG_NEVER, "dataSetSaveFlag"); dataSetSaveFlag(); } debug(LOG_NEVER, "Loading save game %s", pSaveName); if (!loadGame(pSaveName, false, true, true)) { debug(LOG_ERROR, "Failed loadGame(%s)!", pSaveName); return false; } } if (pSaveName == nullptr || saveType == GTYPE_SAVE_START) { // load the game debug(LOG_WZ, "Loading scenario file %s", psNewLevel->apDataFiles[i]); switch (psNewLevel->type) { case LDS_COMPLETE: case LDS_CAMSTART: debug(LOG_WZ, "LDS_COMPLETE / LDS_CAMSTART"); if (!startMission(LDS_CAMSTART, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_CAMSTART, psNewLevel->apDataFiles[i]); return false; } break; case LDS_BETWEEN: debug(LOG_WZ, "LDS_BETWEEN"); if (!startMission(LDS_BETWEEN, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_BETWEEN, psNewLevel->apDataFiles[i]); return false; } break; case LDS_MKEEP: debug(LOG_WZ, "LDS_MKEEP"); if (!startMission(LDS_MKEEP, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_MKEEP, psNewLevel->apDataFiles[i]); return false; } break; case LDS_CAMCHANGE: debug(LOG_WZ, "LDS_CAMCHANGE"); if (!startMission(LDS_CAMCHANGE, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_CAMCHANGE, psNewLevel->apDataFiles[i]); return false; } break; case LDS_EXPAND: debug(LOG_WZ, "LDS_EXPAND"); if (!startMission(LDS_EXPAND, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_EXPAND, psNewLevel->apDataFiles[i]); return false; } break; case LDS_EXPAND_LIMBO: debug(LOG_WZ, "LDS_LIMBO"); if (!startMission(LDS_EXPAND_LIMBO, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_EXPAND_LIMBO, psNewLevel->apDataFiles[i]); return false; } break; case LDS_MCLEAR: debug(LOG_WZ, "LDS_MCLEAR"); if (!startMission(LDS_MCLEAR, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_MCLEAR, psNewLevel->apDataFiles[i]); return false; } break; case LDS_MKEEP_LIMBO: debug(LOG_WZ, "LDS_MKEEP_LIMBO"); if (!startMission(LDS_MKEEP_LIMBO, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_MKEEP_LIMBO, psNewLevel->apDataFiles[i]); return false; } break; default: ASSERT(psNewLevel->type >= LDS_MULTI_TYPE_START, "Unexpected mission type"); debug(LOG_WZ, "default (MULTIPLAYER)"); if (!startMission(LDS_CAMSTART, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s) (default)!", LDS_CAMSTART, psNewLevel->apDataFiles[i]); return false; } break; } } } else if (psNewLevel->apDataFiles[i]) { // load the data debug(LOG_WZ, "Loading %s", psNewLevel->apDataFiles[i]); if (!resLoad(psNewLevel->apDataFiles[i], i + CURRENT_DATAID)) { debug(LOG_ERROR, "Failed resLoad(%s, %d) (default)!", psNewLevel->apDataFiles[i], i + CURRENT_DATAID); return false; } } } if (bMultiPlayer) { // This calls resLoadFile("SMSG", "multiplay.txt"). Must be before loadMissionExtras, which calls loadSaveMessage, which calls getViewData. loadMultiScripts(); } if (pSaveName != nullptr) { //load MidMission Extras if (!loadMissionExtras(pSaveName, psNewLevel->type)) { debug(LOG_ERROR, "Failed loadMissionExtras(%s, %d)!", pSaveName, psNewLevel->type); return false; } } if (pSaveName != nullptr && saveType == GTYPE_SAVE_MIDMISSION) { //load script stuff // load the event system state here for a save game debug(LOG_SAVE, "Loading script system state"); if (!loadScriptState(pSaveName)) { debug(LOG_ERROR, "Failed loadScriptState(%s)!", pSaveName); return false; } } if (!stageThreeInitialise()) { debug(LOG_ERROR, "Failed stageThreeInitialise()!"); return false; } dataClearSaveFlag(); //this enables us to to start cam2/cam3 without going via a save game and get the extra droids //in from the script-controlled Transporters if (!pSaveName && psNewLevel->type == LDS_CAMSTART) { eventFireCallbackTrigger((TRIGGER_TYPE)CALL_NO_REINFORCEMENTS_LEFT); } //restore the level name for comparisons on next mission load up if (psChangeLevel == nullptr) { psCurrLevel = psNewLevel; } else { psCurrLevel = psChangeLevel; } // Copy this info to be used by the crash handler for the dump file char buf[256]; ssprintf(buf, "Current Level/map is %s", psCurrLevel->pName); addDumpInfo(buf); triggerEvent(TRIGGER_GAME_LOADED); if (autogame_enabled()) { gameTimeSetMod(Rational(500)); if (hostlaunch != 2) // tests will specify the AI manually { jsAutogameSpecific("multiplay/skirmish/semperfi.js", selectedPlayer); } } return true; }
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; }
//* // ======================================================================================================================= // ======================================================================================================================= // bool sound_InitLibrary(void) { int err; const ALfloat listenerVel[3] = { 0.0, 0.0, 0.0 }; const ALfloat listenerOri[6] = { 0.0, 0.0, 1.0, 0.0, 1.0, 0.0 }; char buf[512]; const ALCchar *deviceName; #if 0 // This code is disabled because enumerating devices apparently crashes PulseAudio on Fedora12 /* Get the available devices and print them. * Devices are separated by NUL chars ('\0') and the list of devices is * terminated by two NUL chars. */ deviceName = alcGetString(NULL, ALC_DEVICE_SPECIFIER); while (deviceName != NULL && *deviceName != '\0') { debug(LOG_SOUND, "available OpenAL device(s) are: %s", deviceName); deviceName += strlen(deviceName) + 1; } #endif #ifdef WZ_OS_WIN /* HACK: Select the "software" OpenAL device on Windows because it * provides 256 sound sources (unlike most Creative's default * which provides only 16), causing our lack of source-management * to be significantly less noticeable. */ device = alcOpenDevice("Generic Software"); // If the software device isn't available, fall back to default if (!device) #endif { // Open default device device = alcOpenDevice(nullptr); } if (!device) { debug(LOG_ERROR, "Couldn't open audio device."); return false; } // Print current device name and add it to dump info deviceName = alcGetString(device, ALC_DEVICE_SPECIFIER); debug(LOG_SOUND, "Current audio device: %s", deviceName); ssprintf(buf, "OpenAL Device Name: %s", deviceName); addDumpInfo(buf); context = alcCreateContext(device, nullptr); //NULL was contextAttributes if (!context) { debug(LOG_ERROR, "Couldn't open audio context."); return false; } alcMakeContextCurrent(context); err = sound_GetContextError(device); if (err != ALC_NO_ERROR) { debug(LOG_ERROR, "Couldn't initialize audio context: %s", alcGetString(device, err)); return false; } // Dump Open AL device info (depends on context) // to the crash handler for the dump file and debug log ssprintf(buf, "OpenAL Vendor: %s", alGetString(AL_VENDOR)); addDumpInfo(buf); debug(LOG_SOUND, "%s", buf); ssprintf(buf, "OpenAL Version: %s", alGetString(AL_VERSION)); addDumpInfo(buf); debug(LOG_SOUND, "%s", buf); ssprintf(buf, "OpenAL Renderer: %s", alGetString(AL_RENDERER)); addDumpInfo(buf); debug(LOG_SOUND, "%s", buf); ssprintf(buf, "OpenAL Extensions: %s", alGetString(AL_EXTENSIONS)); addDumpInfo(buf); debug(LOG_SOUND, "%s", buf); openal_initialized = true; // Clear Error Codes alGetError(); alcGetError(device); alListener3f(AL_POSITION, 0.f, 0.f, 0.f); alListenerfv(AL_VELOCITY, listenerVel); alListenerfv(AL_ORIENTATION, listenerOri); alDistanceModel(AL_NONE); sound_GetError(); return true; }