Changeset 2896 for code/trunk/src/orxonox/Main.cc
- Timestamp:
- Apr 6, 2009, 1:59:00 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/gui merged: 2796,2798-2801,2805,2807-2808,2811,2814-2817,2834,2840-2850,2853-2854,2859,2862-2863,2869,2875,2887,2892
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/Main.cc
r2873 r2896 38 38 39 39 #include "OrxonoxStableHeaders.h" 40 #include "OrxonoxConfig.h" 40 41 41 #include <exception> 42 #include <cassert> 42 #include "util/Debug.h" 43 #include "core/Identifier.h" 44 #include "core/Game.h" 43 45 44 #include "OrxonoxConfig.h" 45 #include "util/Debug.h" 46 #include "util/SignalHandler.h" 47 #include "core/ConfigFileManager.h" 48 #include "core/CommandLine.h" 49 #include "core/CommandExecutor.h" 50 #include "core/Identifier.h" 51 #include "core/Core.h" 52 #include "core/Language.h" 53 54 #include "gamestates/GSRoot.h" 55 #include "gamestates/GSGraphics.h" 56 #include "gamestates/GSStandalone.h" 57 #include "gamestates/GSServer.h" 58 #include "gamestates/GSClient.h" 59 #include "gamestates/GSDedicated.h" 60 #include "gamestates/GSGUI.h" 61 #include "gamestates/GSIOConsole.h" 62 63 #ifdef ORXONOX_PLATFORM_APPLE 64 #include <CoreFoundation/CoreFoundation.h> 65 66 // This function will locate the path to our application on OS X, 67 // unlike windows you can not rely on the curent working directory 68 // for locating your configuration files and resources. 69 std::string macBundlePath() 70 { 71 char path[1024]; 72 CFBundleRef mainBundle = CFBundleGetMainBundle(); 73 assert(mainBundle); 74 75 CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); 76 assert(mainBundleURL); 77 78 CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); 79 assert(cfStringRef); 80 81 CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); 82 83 CFRelease(mainBundleURL); 84 CFRelease(cfStringRef); 85 86 return std::string(path); 87 } 88 #endif 89 90 91 SetCommandLineArgument(settingsFile, "orxonox.ini"); 92 SetCommandLineArgument(configFileDirectory, ""); 93 46 /* 47 @brief 48 Main method. Game starts here (except for static initialisations). 49 */ 94 50 int main(int argc, char** argv) 95 51 { 96 using namespace orxonox; 52 { 53 orxonox::Game orxonox(argc, argv); 97 54 98 // Parse command line arguments 99 try 100 { 101 CommandLine::parseAll(argc, argv); 102 } 103 catch (ArgumentException& ex) 104 { 105 COUT(1) << ex.what() << std::endl; 106 COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl; 107 } 55 orxonox.setStateHierarchy( 56 "root" 57 " graphics" 58 " mainMenu" 59 " standalone" 60 " level" 61 " server" 62 " level" 63 " client" 64 " level" 65 " dedicated" 66 " level" 67 " ioConsole" 68 ); 108 69 109 // Do this after parsing the command line to allow customisation 110 Core::postMainInitialisation(); 111 112 // create a signal handler (only active for linux) 113 SignalHandler signalHandler; 114 signalHandler.doCatch(argv[0], Core::getLogPathString() + "orxonox_crash.log"); 115 116 // Create the ConfigFileManager before creating the GameStates in order to have 117 // setConfigValues() in the constructor (required). 118 ConfigFileManager* configFileManager = new ConfigFileManager(); 119 configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString()); 120 // create the Core settings to configure the output level 121 Language* language = new Language(); 122 Core* core = new Core(); 123 124 // put GameStates in its own scope so we can destroy the identifiers at the end of main(). 125 { 126 // create the gamestates 127 GSRoot root; 128 GSGraphics graphics; 129 GSStandalone standalone; 130 GSServer server; 131 GSClient client; 132 GSDedicated dedicated; 133 GSGUI gui; 134 GSIOConsole ioConsole; 135 136 // make the hierarchy 137 root.addChild(&graphics); 138 graphics.addChild(&standalone); 139 graphics.addChild(&server); 140 graphics.addChild(&client); 141 graphics.addChild(&gui); 142 root.addChild(&ioConsole); 143 root.addChild(&dedicated); 144 145 // Here happens the game 146 root.start(); 147 } 148 149 // destroy singletons 150 delete core; 151 delete language; 152 delete configFileManager; 70 orxonox.run(); 71 } // orxonox gets destroyed right here! 153 72 154 73 // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand) 155 Identifier::destroyAllIdentifiers(); 156 // destroy command line arguments 157 CommandLine::destroyAllArguments(); 158 // Also delete external console command that don't belong to an Identifier 159 CommandExecutor::destroyExternalCommands(); 74 // Needs to be done after Game destructor because of ~OrxonoxClass 75 orxonox::Identifier::destroyAllIdentifiers(); 160 76 161 77 return 0;
Note: See TracChangeset
for help on using the changeset viewer.