[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 | */ |
---|
| 29 | |
---|
| 30 | /** |
---|
[1021] | 31 | @file |
---|
[2685] | 32 | @brief Entry point of the program. |
---|
[612] | 33 | */ |
---|
| 34 | |
---|
[1293] | 35 | #include "OrxonoxStableHeaders.h" |
---|
[612] | 36 | |
---|
[1293] | 37 | #include <exception> |
---|
[1755] | 38 | #include <cassert> |
---|
[2685] | 39 | #include <fstream> |
---|
[1293] | 40 | |
---|
[2664] | 41 | #include "OrxonoxConfig.h" |
---|
[1891] | 42 | #include "util/Debug.h" |
---|
[2087] | 43 | #include "util/SignalHandler.h" |
---|
[1891] | 44 | #include "core/ConfigFileManager.h" |
---|
[2103] | 45 | #include "core/CommandLine.h" |
---|
[2662] | 46 | #include "core/CommandExecutor.h" |
---|
| 47 | #include "core/Identifier.h" |
---|
| 48 | #include "core/Core.h" |
---|
| 49 | #include "core/Language.h" |
---|
[612] | 50 | |
---|
[1755] | 51 | #include "gamestates/GSRoot.h" |
---|
| 52 | #include "gamestates/GSGraphics.h" |
---|
| 53 | #include "gamestates/GSStandalone.h" |
---|
| 54 | #include "gamestates/GSServer.h" |
---|
| 55 | #include "gamestates/GSClient.h" |
---|
| 56 | #include "gamestates/GSDedicated.h" |
---|
| 57 | #include "gamestates/GSGUI.h" |
---|
| 58 | #include "gamestates/GSIOConsole.h" |
---|
| 59 | |
---|
[2664] | 60 | #ifdef ORXONOX_PLATFORM_APPLE |
---|
[612] | 61 | #include <CoreFoundation/CoreFoundation.h> |
---|
| 62 | |
---|
| 63 | // This function will locate the path to our application on OS X, |
---|
| 64 | // unlike windows you can not rely on the curent working directory |
---|
| 65 | // for locating your configuration files and resources. |
---|
| 66 | std::string macBundlePath() |
---|
| 67 | { |
---|
[1755] | 68 | char path[1024]; |
---|
| 69 | CFBundleRef mainBundle = CFBundleGetMainBundle(); |
---|
| 70 | assert(mainBundle); |
---|
[612] | 71 | |
---|
[1755] | 72 | CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); |
---|
| 73 | assert(mainBundleURL); |
---|
[612] | 74 | |
---|
[1755] | 75 | CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); |
---|
| 76 | assert(cfStringRef); |
---|
[612] | 77 | |
---|
[1755] | 78 | CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); |
---|
[612] | 79 | |
---|
[1755] | 80 | CFRelease(mainBundleURL); |
---|
| 81 | CFRelease(cfStringRef); |
---|
[612] | 82 | |
---|
[1755] | 83 | return std::string(path); |
---|
[612] | 84 | } |
---|
| 85 | #endif |
---|
| 86 | |
---|
| 87 | |
---|
[2103] | 88 | SetCommandLineArgument(settingsFile, "orxonox.ini"); |
---|
[2685] | 89 | SetCommandLineArgument(configFileDirectory, ""); |
---|
[2103] | 90 | |
---|
[1755] | 91 | int main(int argc, char** argv) |
---|
[622] | 92 | { |
---|
[2103] | 93 | using namespace orxonox; |
---|
| 94 | |
---|
[2685] | 95 | // First, determine whether we have an installed or a binary dir run |
---|
| 96 | // The latter occurs when simply running from the build directory |
---|
| 97 | std::ifstream probe; |
---|
| 98 | probe.open("orxonox_dev_build.keep_me"); |
---|
| 99 | if (probe) |
---|
| 100 | { |
---|
| 101 | Core::setDevBuild(); |
---|
| 102 | probe.close(); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | // create a signal handler (only active for linux) |
---|
[2662] | 106 | SignalHandler signalHandler; |
---|
[2685] | 107 | signalHandler.doCatch(argv[0], Core::getLogPath() + "orxonox_crash.log"); |
---|
[1021] | 108 | |
---|
[2103] | 109 | // Parse command line arguments |
---|
| 110 | try |
---|
| 111 | { |
---|
| 112 | CommandLine::parseAll(argc, argv); |
---|
| 113 | } |
---|
| 114 | catch (ArgumentException& ex) |
---|
| 115 | { |
---|
| 116 | COUT(1) << ex.what() << std::endl; |
---|
| 117 | COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | // Create the ConfigFileManager before creating the GameStates in order to have |
---|
[1891] | 121 | // setConfigValues() in the constructor (required). |
---|
[2103] | 122 | ConfigFileManager* configFileManager = new ConfigFileManager(); |
---|
| 123 | configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString()); |
---|
[2662] | 124 | // create the Core settings to configure the output level |
---|
| 125 | Language* language = new Language(); |
---|
| 126 | Core* core = new Core(); |
---|
[1891] | 127 | |
---|
[2662] | 128 | // put GameStates in its own scope so we can destroy the identifiers at the end of main(). |
---|
| 129 | { |
---|
| 130 | // create the gamestates |
---|
| 131 | GSRoot root; |
---|
| 132 | GSGraphics graphics; |
---|
| 133 | GSStandalone standalone; |
---|
| 134 | GSServer server; |
---|
| 135 | GSClient client; |
---|
| 136 | GSDedicated dedicated; |
---|
| 137 | GSGUI gui; |
---|
| 138 | GSIOConsole ioConsole; |
---|
[612] | 139 | |
---|
[2662] | 140 | // make the hierarchy |
---|
| 141 | root.addChild(&graphics); |
---|
| 142 | graphics.addChild(&standalone); |
---|
| 143 | graphics.addChild(&server); |
---|
| 144 | graphics.addChild(&client); |
---|
| 145 | graphics.addChild(&gui); |
---|
| 146 | root.addChild(&ioConsole); |
---|
| 147 | root.addChild(&dedicated); |
---|
[1755] | 148 | |
---|
[2662] | 149 | // Here happens the game |
---|
| 150 | root.start(); |
---|
| 151 | } |
---|
[1755] | 152 | |
---|
[2662] | 153 | // destroy singletons |
---|
| 154 | delete core; |
---|
| 155 | delete language; |
---|
[2103] | 156 | delete configFileManager; |
---|
| 157 | |
---|
[2662] | 158 | // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand) |
---|
| 159 | Identifier::destroyAllIdentifiers(); |
---|
| 160 | // destroy command line arguments |
---|
| 161 | CommandLine::destroyAllArguments(); |
---|
| 162 | // Also delete external console command that don't belong to an Identifier |
---|
| 163 | CommandExecutor::destroyExternalCommands(); |
---|
| 164 | |
---|
[1755] | 165 | return 0; |
---|
[612] | 166 | } |
---|