/** ** The main program: initialise, parse options and arguments. ** ** @param argc Number of arguments. ** @param argv Vector of arguments. */ int main(int argc, char **argv) { #ifdef REDIRECT_OUTPUT RedirectOutput(); #endif #ifdef USE_BEOS // Parse arguments for BeOS beos_init(argc, argv); #endif // Setup some defaults. #ifndef MAC_BUNDLE StratagusLibPath = "."; #else freopen("/tmp/stdout.txt", "w", stdout); freopen("/tmp/stderr.txt", "w", stderr); // Look for the specified data set inside the application bundle // This should be a subdir of the Resources directory CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); Assert(pathPtr); StratagusLibPath = pathPtr; #endif Parameters ¶meters = Parameters::Instance; parameters.SetDefaultValues(); parameters.LocalPlayerName = GetLocalPlayerNameFromEnv(); if (argc > 0) { parameters.applicationName = argv[0]; } // FIXME: Parse options before or after scripts? ParseCommandLine(argc, argv, parameters); // Init the random number generator. InitSyncRand(); makedir(parameters.GetUserDirectory().c_str(), 0777); // Init Lua and register lua functions! InitLua(); LuaRegisterModules(); // Initialise AI module InitAiModule(); LoadCcl(parameters.luaStartFilename); PrintHeader(); PrintLicense(); // Setup video display InitVideo(); // Setup sound card if (!InitSound()) { InitMusic(); } #ifndef DEBUG // For debug it's better not to have: srand(time(NULL)); // Random counter = random each start #endif // Show title screens. SetDefaultTextColors(FontYellow, FontWhite); LoadFonts(); SetClipping(0, 0, Video.Width - 1, Video.Height - 1); Video.ClearScreen(); ShowTitleScreens(); // Init player data ThisPlayer = NULL; //Don't clear the Players strucure as it would erase the allowed units. // memset(Players, 0, sizeof(Players)); NumPlayers = 0; UnitManager.Init(); // Units memory management PreMenuSetup(); // Load everything needed for menus MenuLoop(); Exit(0); return 0; }
/** ** The main program: initialise, parse options and arguments. ** ** @param argc Number of arguments. ** @param argv Vector of arguments. */ int stratagusMain(int argc, char **argv) { #ifdef USE_BEOS // Parse arguments for BeOS beos_init(argc, argv); #endif #ifdef USE_WIN32 SetUnhandledExceptionFilter(CreateDumpFile); #endif #if defined(USE_WIN32) && ! defined(REDIRECT_OUTPUT) SetupConsole(); #endif // Setup some defaults. #ifndef MAC_BUNDLE StratagusLibPath = "."; #else freopen("/tmp/stdout.txt", "w", stdout); freopen("/tmp/stderr.txt", "w", stderr); // Look for the specified data set inside the application bundle // This should be a subdir of the Resources directory CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); Assert(pathPtr); StratagusLibPath = pathPtr; #endif #ifdef USE_PHYSFS if (PHYSFS_init(argv[0])) { PHYSFS_mount(PHYSFS_DATAFILE, "/", 0); } #endif #ifdef USE_STACKTRACE try { #endif Parameters ¶meters = Parameters::Instance; parameters.SetDefaultValues(); parameters.SetLocalPlayerNameFromEnv(); #ifdef REDIRECT_OUTPUT RedirectOutput(); #endif if (argc > 0) { parameters.applicationName = argv[0]; } // FIXME: Parse options before or after scripts? ParseCommandLine(argc, argv, parameters); // Init the random number generator. InitSyncRand(); makedir(parameters.GetUserDirectory().c_str(), 0777); // Init Lua and register lua functions! InitLua(); LuaRegisterModules(); // Initialise AI module InitAiModule(); LoadCcl(parameters.luaStartFilename, parameters.luaScriptArguments); PrintHeader(); PrintLicense(); // Setup video display InitVideo(); // Setup sound card if (!InitSound()) { InitMusic(); } #ifndef DEBUG // For debug it's better not to have: srand(time(NULL)); // Random counter = random each start #endif // Show title screens. SetDefaultTextColors(FontYellow, FontWhite); LoadFonts(); SetClipping(0, 0, Video.Width - 1, Video.Height - 1); Video.ClearScreen(); ShowTitleScreens(); // Init player data ThisPlayer = NULL; //Don't clear the Players structure as it would erase the allowed units. // memset(Players, 0, sizeof(Players)); NumPlayers = 0; UnitManager.Init(); // Units memory management PreMenuSetup(); // Load everything needed for menus MenuLoop(); Exit(0); #ifdef USE_STACKTRACE } catch (const std::exception &e) { fprintf(stderr, "Stratagus crashed!\n"); //Wyrmgus start // fprintf(stderr, "Please send this call stack to our bug tracker: https://github.com/Wargus/stratagus/issues\n"); fprintf(stderr, "Please send this call stack to our bug tracker: https://github.com/Andrettin/Wyrmgus/issues\n"); //Wyrmgus end fprintf(stderr, "and tell us what caused this bug to occur.\n"); fprintf(stderr, " === exception state traceback === \n"); fprintf(stderr, "%s", e.what()); exit(1); } #endif return 0; }