[612] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1293] | 3 | * > www.orxonox.net < |
---|
[612] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
---|
[1755] | 24 | * Reto Grieder |
---|
[612] | 25 | * Co-authors: |
---|
| 26 | * ... |
---|
| 27 | * |
---|
| 28 | */ |
---|
[2873] | 29 | |
---|
| 30 | /** |
---|
| 31 | @mainpage Orxonox Documentation |
---|
| 32 | */ |
---|
[612] | 33 | |
---|
| 34 | /** |
---|
[1021] | 35 | @file |
---|
[2710] | 36 | @brief Entry point of the program. |
---|
[612] | 37 | */ |
---|
| 38 | |
---|
[1293] | 39 | #include "OrxonoxStableHeaders.h" |
---|
[612] | 40 | |
---|
[1293] | 41 | #include <exception> |
---|
[1755] | 42 | #include <cassert> |
---|
[1293] | 43 | |
---|
[2710] | 44 | #include "OrxonoxConfig.h" |
---|
[1891] | 45 | #include "util/Debug.h" |
---|
[2087] | 46 | #include "util/SignalHandler.h" |
---|
[1891] | 47 | #include "core/ConfigFileManager.h" |
---|
[2103] | 48 | #include "core/CommandLine.h" |
---|
[2662] | 49 | #include "core/CommandExecutor.h" |
---|
| 50 | #include "core/Identifier.h" |
---|
| 51 | #include "core/Core.h" |
---|
| 52 | #include "core/Language.h" |
---|
[612] | 53 | |
---|
[1755] | 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 | |
---|
[2710] | 63 | #ifdef ORXONOX_PLATFORM_APPLE |
---|
[612] | 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 | { |
---|
[1755] | 71 | char path[1024]; |
---|
| 72 | CFBundleRef mainBundle = CFBundleGetMainBundle(); |
---|
| 73 | assert(mainBundle); |
---|
[612] | 74 | |
---|
[1755] | 75 | CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); |
---|
| 76 | assert(mainBundleURL); |
---|
[612] | 77 | |
---|
[1755] | 78 | CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); |
---|
| 79 | assert(cfStringRef); |
---|
[612] | 80 | |
---|
[1755] | 81 | CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); |
---|
[612] | 82 | |
---|
[1755] | 83 | CFRelease(mainBundleURL); |
---|
| 84 | CFRelease(cfStringRef); |
---|
[612] | 85 | |
---|
[1755] | 86 | return std::string(path); |
---|
[612] | 87 | } |
---|
| 88 | #endif |
---|
| 89 | |
---|
| 90 | |
---|
[2103] | 91 | SetCommandLineArgument(settingsFile, "orxonox.ini"); |
---|
[2710] | 92 | SetCommandLineArgument(configFileDirectory, ""); |
---|
[2103] | 93 | |
---|
[1755] | 94 | int main(int argc, char** argv) |
---|
[622] | 95 | { |
---|
[2103] | 96 | using namespace orxonox; |
---|
| 97 | |
---|
| 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 | } |
---|
| 108 | |
---|
[2710] | 109 | // Do this after parsing the command line to allow customisation |
---|
| 110 | Core::postMainInitialisation(); |
---|
| 111 | |
---|
[2716] | 112 | // create a signal handler (only active for linux) |
---|
| 113 | SignalHandler signalHandler; |
---|
| 114 | signalHandler.doCatch(argv[0], Core::getLogPathString() + "orxonox_crash.log"); |
---|
| 115 | |
---|
[2103] | 116 | // Create the ConfigFileManager before creating the GameStates in order to have |
---|
[1891] | 117 | // setConfigValues() in the constructor (required). |
---|
[2103] | 118 | ConfigFileManager* configFileManager = new ConfigFileManager(); |
---|
| 119 | configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString()); |
---|
[2662] | 120 | // create the Core settings to configure the output level |
---|
| 121 | Language* language = new Language(); |
---|
| 122 | Core* core = new Core(); |
---|
[1891] | 123 | |
---|
[2662] | 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; |
---|
[612] | 135 | |
---|
[2662] | 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); |
---|
[1755] | 144 | |
---|
[2662] | 145 | // Here happens the game |
---|
| 146 | root.start(); |
---|
| 147 | } |
---|
[1755] | 148 | |
---|
[2662] | 149 | // destroy singletons |
---|
| 150 | delete core; |
---|
| 151 | delete language; |
---|
[2103] | 152 | delete configFileManager; |
---|
| 153 | |
---|
[2662] | 154 | // 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(); |
---|
| 160 | |
---|
[1755] | 161 | return 0; |
---|
[612] | 162 | } |
---|