[4982] | 1 | /* |
---|
[1850] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | This program is distributed in the hope that it will be useful, |
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | GNU General Public License for more details. |
---|
| 15 | |
---|
| 16 | You should have received a copy of the GNU General Public License |
---|
| 17 | along with this program; if not, write to the Free Software Foundation, |
---|
[4556] | 18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
[1850] | 19 | |
---|
[1855] | 20 | |
---|
| 21 | ### File Specific: |
---|
| 22 | main-programmer: Patrick Boenzli |
---|
[5303] | 23 | co-programmer: Christian Meyer |
---|
[4054] | 24 | co-programmer: Benjamin Grauer: injected ResourceManager/GraphicsEngine/GUI |
---|
[1850] | 25 | */ |
---|
| 26 | |
---|
[5303] | 27 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ORXONOX |
---|
[2190] | 28 | #include "orxonox.h" |
---|
[3610] | 29 | |
---|
[5819] | 30 | #include "globals.h" |
---|
| 31 | |
---|
[7661] | 32 | #include "gui/qt_gui/qt_gui.h" |
---|
[4054] | 33 | |
---|
[7661] | 34 | #include "file.h" |
---|
[5944] | 35 | #include "parser/ini_parser/ini_parser.h" |
---|
[7193] | 36 | #include "util/loading/game_loader.h" |
---|
[7440] | 37 | #include "util/signal_handler.h" |
---|
[4786] | 38 | |
---|
| 39 | //ENGINES |
---|
[3610] | 40 | #include "graphics_engine.h" |
---|
[4504] | 41 | #include "sound_engine.h" |
---|
[7193] | 42 | #include "util/loading/resource_manager.h" |
---|
[4786] | 43 | #include "cd_engine.h" |
---|
[3790] | 44 | #include "text_engine.h" |
---|
[4786] | 45 | #include "event_handler.h" |
---|
| 46 | |
---|
[7193] | 47 | #include "util/loading/factory.h" |
---|
[4980] | 48 | #include "fast_factory.h" |
---|
| 49 | |
---|
[4131] | 50 | #include "benchmark.h" |
---|
[3610] | 51 | |
---|
[4786] | 52 | #include "class_list.h" |
---|
[5641] | 53 | #include "shell_command_class.h" |
---|
[5165] | 54 | #include "shell_command.h" |
---|
[5175] | 55 | #include "shell_buffer.h" |
---|
[4748] | 56 | |
---|
[7193] | 57 | #include "util/loading/load_param_description.h" |
---|
[5226] | 58 | |
---|
[5996] | 59 | #include "network_manager.h" |
---|
| 60 | |
---|
[6695] | 61 | #include "state.h" |
---|
[7256] | 62 | #include "lib/parser/preferences/cmd_line_prefs_reader.h" |
---|
| 63 | #include "lib/parser/preferences/ini_file_prefs_reader.h" |
---|
[2190] | 64 | #include <string.h> |
---|
[4032] | 65 | |
---|
[4885] | 66 | int verbose = 4; |
---|
[2036] | 67 | |
---|
[1803] | 68 | using namespace std; |
---|
| 69 | |
---|
[5207] | 70 | SHELL_COMMAND(restart, Orxonox, restart); |
---|
| 71 | |
---|
[7258] | 72 | REGISTER_ARG_FLAG( l, license, "misc", "showLicenseAndExit", "Prints the license and exit", "1" ); |
---|
| 73 | REGISTER_ARG_FLAG( c, client, "game", "gameType", "Connect to Server (-H)", "multiplayer_client" ); |
---|
| 74 | REGISTER_ARG_FLAG( s, server, "game", "gameType", "Start Orxonox as Game Server", "multiplayer_server" ); |
---|
| 75 | REGISTER_ARG_ARG( H, host, "game", "host", "Host to connect to", "host"); |
---|
| 76 | REGISTER_ARG_ARG( p, port, "game", "port", "Port to use", "port" ); |
---|
| 77 | REGISTER_ARG_FLAG( g, gui, "game", "showGui", "starts the orxonox with the configuration GUI", "1"); |
---|
[7256] | 78 | |
---|
[7258] | 79 | REGISTER_ARG_FLAG( f, fullscreen, "video", "Fullscreen-mode", "start Orxonox in fullscreen mode", "1"); |
---|
| 80 | REGISTER_ARG_FLAG( w, windowed, "video", "Fullscreen-mode", "start Orxonox in windowed mode", "0"); |
---|
| 81 | REGISTER_ARG_ARG( r, resolution, "video", "Resolution", "Sets resolution / window size", "res"); |
---|
| 82 | |
---|
[7261] | 83 | REGISTER_ARG_FLAG( a, audio, "audio", "Disable-Audio", "Enable audio", "0" ); |
---|
| 84 | REGISTER_ARG_FLAG( m, mute , "audio", "Disable-Audio", "Disable audio", "1" ); |
---|
| 85 | REGISTER_ARG_ARG( _, audio_channels, "audio", "Audio-Channels", "Sets # audio channels", "num" ); |
---|
| 86 | REGISTER_ARG_ARG( _, music_volume, "audio", "Music-Volume", "Sets music volume", "vol" ); |
---|
| 87 | REGISTER_ARG_ARG( _, effects_volume, "audio", "Effects-Volume", "Sets effects volume", "vol" ); |
---|
| 88 | |
---|
[7440] | 89 | #ifndef __WIN32__ |
---|
| 90 | REGISTER_ARG_FLAG( _, start_gdb_on_signal, "misc", "start-gdb", "Start gdb on signal", "1"); |
---|
| 91 | REGISTER_ARG_FLAG( _, write_bt_to_file, "misc", "bt-to-file", "Write backtrace to file", "1"); |
---|
| 92 | #endif |
---|
| 93 | |
---|
[2190] | 94 | /** |
---|
[4836] | 95 | * create a new Orxonox |
---|
[4135] | 96 | |
---|
| 97 | In this funcitons only global values are set. The game will not be started here. |
---|
[2190] | 98 | */ |
---|
| 99 | Orxonox::Orxonox () |
---|
[1872] | 100 | { |
---|
[4445] | 101 | this->setClassID(CL_ORXONOX, "Orxonox"); |
---|
[4766] | 102 | this->setName("orxonox-main"); |
---|
[4059] | 103 | |
---|
[4135] | 104 | this->argc = 0; |
---|
| 105 | this->argv = NULL; |
---|
[4782] | 106 | |
---|
[5996] | 107 | /* this way, there is no network enabled: */ |
---|
[7256] | 108 | this->serverName = ""; |
---|
[5996] | 109 | this->port = -1; |
---|
| 110 | |
---|
[7221] | 111 | this->configFileName = ""; |
---|
[1872] | 112 | } |
---|
[1803] | 113 | |
---|
[2190] | 114 | /** |
---|
[4836] | 115 | * remove Orxonox from memory |
---|
[2190] | 116 | */ |
---|
[4556] | 117 | Orxonox::~Orxonox () |
---|
[2190] | 118 | { |
---|
[5285] | 119 | // game-specific |
---|
[4815] | 120 | delete GameLoader::getInstance(); |
---|
[5285] | 121 | |
---|
| 122 | // class-less services/factories |
---|
[5982] | 123 | Factory::deleteFactories(); |
---|
[4980] | 124 | FastFactory::deleteAll(); |
---|
[7374] | 125 | OrxShell::ShellCommandClass::unregisterAllCommands(); |
---|
[5332] | 126 | |
---|
[5226] | 127 | LoadClassDescription::deleteAllDescriptions(); |
---|
| 128 | |
---|
[7427] | 129 | // handlers |
---|
| 130 | delete ResourceManager::getInstance(); // deletes the Resource Manager |
---|
| 131 | |
---|
[5285] | 132 | // engines |
---|
| 133 | delete CDEngine::getInstance(); |
---|
[7460] | 134 | delete OrxSound::SoundEngine::getInstance(); |
---|
[5285] | 135 | delete GraphicsEngine::getInstance(); // deleting the Graphics |
---|
[4817] | 136 | delete EventHandler::getInstance(); |
---|
[5285] | 137 | |
---|
| 138 | // output-buffer |
---|
[7374] | 139 | delete OrxShell::ShellBuffer::getInstance(); |
---|
[5285] | 140 | |
---|
[5225] | 141 | SDL_QuitSubSystem(SDL_INIT_TIMER); |
---|
[7126] | 142 | ClassList::debug(); |
---|
[1850] | 143 | |
---|
[4833] | 144 | PRINT(3) |
---|
[5996] | 145 | ( |
---|
| 146 | "===================================================\n" \ |
---|
| 147 | "Thanks for playing orxonox.\n" \ |
---|
| 148 | "visit: http://www.orxonox.net for new versions.\n" \ |
---|
| 149 | "===================================================\n" \ |
---|
| 150 | ORXONOX_LICENSE_SHORT |
---|
| 151 | ); |
---|
[1872] | 152 | |
---|
[4766] | 153 | Orxonox::singletonRef = NULL; |
---|
[1850] | 154 | } |
---|
| 155 | |
---|
[2190] | 156 | /** |
---|
[4836] | 157 | * this is a singleton class to prevent duplicates |
---|
[4766] | 158 | */ |
---|
| 159 | Orxonox* Orxonox::singletonRef = NULL; |
---|
[4556] | 160 | |
---|
[5207] | 161 | // DANGEROUS |
---|
| 162 | void Orxonox::restart() |
---|
| 163 | { |
---|
[5996] | 164 | // int argc = this->argc; |
---|
| 165 | // char** argv = this->argv; |
---|
| 166 | // |
---|
| 167 | // Orxonox *orx = Orxonox::getInstance(); |
---|
| 168 | // |
---|
| 169 | // delete orx; |
---|
| 170 | // |
---|
| 171 | // orx = Orxonox::getInstance(); |
---|
| 172 | // |
---|
| 173 | // if((*orx).init(argc, argv) == -1) |
---|
| 174 | // { |
---|
| 175 | // PRINTF(1)("! Orxonox initialization failed\n"); |
---|
| 176 | // return; |
---|
| 177 | // } |
---|
| 178 | // |
---|
| 179 | // printf("finished inizialisation\n"); |
---|
| 180 | // orx->start(); |
---|
[5207] | 181 | } |
---|
| 182 | |
---|
[4766] | 183 | /** |
---|
[7221] | 184 | * @brief this finds the config file |
---|
[4766] | 185 | * @returns the new config-fileName |
---|
| 186 | * Since the config file varies from user to user and since one may want to specify different config files |
---|
| 187 | * for certain occasions or platforms this function finds the right config file for every occasion and stores |
---|
| 188 | * it's path and name into configfilename |
---|
[2190] | 189 | */ |
---|
[7221] | 190 | const std::string& Orxonox::getConfigFile () |
---|
[1850] | 191 | { |
---|
[7661] | 192 | File orxConfFile("orxonox.conf"); |
---|
| 193 | if (orxConfFile.isFile()) |
---|
[5424] | 194 | { |
---|
[7221] | 195 | this->configFileName = "orxonox.conf"; |
---|
[5424] | 196 | } |
---|
| 197 | else |
---|
[7661] | 198 | this->configFileName = File(DEFAULT_CONFIG_FILE).name(); |
---|
[7256] | 199 | |
---|
[7677] | 200 | PRINTF(3)("Parsed Config File: '%s'\n", this->configFileName.c_str()); |
---|
[1803] | 201 | } |
---|
| 202 | |
---|
[2190] | 203 | /** |
---|
[4833] | 204 | * initialize Orxonox with command line |
---|
| 205 | */ |
---|
[7256] | 206 | int Orxonox::init (int argc, char** argv, const std::string & name, int port) |
---|
[1803] | 207 | { |
---|
[4135] | 208 | this->argc = argc; |
---|
| 209 | this->argv = argv; |
---|
[4556] | 210 | |
---|
[5996] | 211 | this->serverName = name; |
---|
| 212 | this->port = port; |
---|
| 213 | |
---|
[4766] | 214 | // initialize the Config-file |
---|
[4830] | 215 | this->getConfigFile(); |
---|
[4766] | 216 | |
---|
[5788] | 217 | // windows must not write into stdout.txt and stderr.txt |
---|
[6833] | 218 | /*#ifdef __WIN32__ |
---|
[5788] | 219 | freopen( "CON", "w", stdout ); |
---|
| 220 | freopen( "CON", "w", stderr ); |
---|
[6833] | 221 | #endif*/ |
---|
[5788] | 222 | |
---|
[5996] | 223 | // initialize everything |
---|
[6079] | 224 | SDL_Init(0); |
---|
[5996] | 225 | if( initResources () == -1) |
---|
| 226 | return -1; |
---|
| 227 | if( initVideo() == -1) |
---|
| 228 | return -1; |
---|
| 229 | if( initSound() == -1) |
---|
| 230 | return -1; |
---|
| 231 | if( initInput() == -1) |
---|
| 232 | return -1; |
---|
| 233 | if( initNetworking () == -1) |
---|
| 234 | return -1; |
---|
| 235 | if( initMisc () == -1) |
---|
| 236 | return -1; |
---|
[4556] | 237 | |
---|
[2636] | 238 | return 0; |
---|
[1850] | 239 | } |
---|
[1849] | 240 | |
---|
[5996] | 241 | |
---|
[2190] | 242 | /** |
---|
[4833] | 243 | * initializes SDL and OpenGL |
---|
[5996] | 244 | */ |
---|
[4556] | 245 | int Orxonox::initVideo() |
---|
[2190] | 246 | { |
---|
[3611] | 247 | PRINTF(3)("> Initializing video\n"); |
---|
[4556] | 248 | |
---|
[3610] | 249 | GraphicsEngine::getInstance(); |
---|
[4556] | 250 | |
---|
[7256] | 251 | GraphicsEngine::getInstance()->initFromPreferences(); |
---|
[4766] | 252 | |
---|
[7221] | 253 | std::string iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp"); |
---|
| 254 | if (!iconName.empty()) |
---|
[5225] | 255 | { |
---|
| 256 | GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, iconName); |
---|
| 257 | } |
---|
[2190] | 258 | return 0; |
---|
| 259 | } |
---|
[1850] | 260 | |
---|
[5996] | 261 | |
---|
[2190] | 262 | /** |
---|
[4833] | 263 | * initializes the sound engine |
---|
| 264 | */ |
---|
[4556] | 265 | int Orxonox::initSound() |
---|
[2190] | 266 | { |
---|
[4504] | 267 | PRINT(3)("> Initializing sound\n"); |
---|
[5225] | 268 | // SDL_InitSubSystem(SDL_INIT_AUDIO); |
---|
[7460] | 269 | OrxSound::SoundEngine::getInstance(); |
---|
[4985] | 270 | |
---|
[7460] | 271 | OrxSound::SoundEngine::getInstance()->loadSettings(); |
---|
| 272 | OrxSound::SoundEngine::getInstance()->initAudio(); |
---|
[2636] | 273 | return 0; |
---|
[2190] | 274 | } |
---|
[1900] | 275 | |
---|
[3214] | 276 | |
---|
[2190] | 277 | /** |
---|
[4833] | 278 | * initializes input functions |
---|
| 279 | */ |
---|
[4556] | 280 | int Orxonox::initInput() |
---|
[2190] | 281 | { |
---|
[4766] | 282 | PRINT(3)("> Initializing input\n"); |
---|
| 283 | |
---|
[7661] | 284 | EventHandler::getInstance()-> |
---|
[7256] | 285 | EventHandler::getInstance()->init(); |
---|
[4833] | 286 | EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE); |
---|
[4556] | 287 | |
---|
[2636] | 288 | return 0; |
---|
[1803] | 289 | } |
---|
| 290 | |
---|
[3214] | 291 | |
---|
[2190] | 292 | /** |
---|
[4833] | 293 | * initializes network system |
---|
| 294 | */ |
---|
[4556] | 295 | int Orxonox::initNetworking() |
---|
[1897] | 296 | { |
---|
[4766] | 297 | PRINT(3)("> Initializing networking\n"); |
---|
| 298 | |
---|
[7256] | 299 | if( this->serverName != "") // we are a client |
---|
[6695] | 300 | { |
---|
| 301 | State::setOnline(true); |
---|
[5996] | 302 | NetworkManager::getInstance()->establishConnection(this->serverName, port); |
---|
[6695] | 303 | } |
---|
[6139] | 304 | else if( this->port > 0) { // we are a server |
---|
[6695] | 305 | State::setOnline(true); |
---|
[5996] | 306 | NetworkManager::getInstance()->createServer(port); |
---|
[6139] | 307 | } |
---|
[2636] | 308 | return 0; |
---|
[1897] | 309 | } |
---|
| 310 | |
---|
[7355] | 311 | //#include "util/loading/dynamic_loader.h" |
---|
[3214] | 312 | |
---|
[2190] | 313 | /** |
---|
[4833] | 314 | * initializes and loads resource files |
---|
[4766] | 315 | */ |
---|
[4833] | 316 | int Orxonox::initResources() |
---|
[1858] | 317 | { |
---|
[4766] | 318 | PRINTF(3)("> Initializing resources\n"); |
---|
[4091] | 319 | |
---|
[4766] | 320 | PRINT(3)("initializing ResourceManager\n"); |
---|
| 321 | |
---|
[5488] | 322 | // init the resource manager |
---|
[7221] | 323 | std::string dataPath; |
---|
[7661] | 324 | if ((dataPath = Preferences::getInstance()->getString(CONFIG_SECTION_GENERAL, CONFIG_NAME_DATADIR, ""))!= "") |
---|
[4766] | 325 | { |
---|
[5480] | 326 | if (!ResourceManager::getInstance()->setDataDir(dataPath) && |
---|
[5996] | 327 | !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) |
---|
[4766] | 328 | { |
---|
[7221] | 329 | PRINTF(1)("Data Could not be located in %s\n", dataPath.c_str()); |
---|
[4766] | 330 | } |
---|
| 331 | } |
---|
[4556] | 332 | |
---|
[5480] | 333 | if (!ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) |
---|
[4766] | 334 | { |
---|
[5510] | 335 | PRINTF(1)("The DataDirectory %s could not be verified\n\nh" \ |
---|
| 336 | "!!! Please Change in File %s Section %s Entry %s to a suitable value !!!\n", |
---|
[7221] | 337 | ResourceManager::getInstance()->getDataDir().c_str(), |
---|
| 338 | this->configFileName.c_str(), |
---|
[7661] | 339 | CONFIG_SECTION_GENERAL, |
---|
[5510] | 340 | CONFIG_NAME_DATADIR ); |
---|
[7661] | 341 | OrxGui::Gui* gui = new OrxGui::QtGui(argc, argv); |
---|
[5479] | 342 | gui->startGui(); |
---|
| 343 | delete gui; |
---|
[4766] | 344 | exit(-1); |
---|
| 345 | } |
---|
[5996] | 346 | //! @todo this is a hack and should be loadable |
---|
[7221] | 347 | std::string imageDir = ResourceManager::getInstance()->getFullName("maps"); |
---|
[5216] | 348 | ResourceManager::getInstance()->addImageDir(imageDir); |
---|
[7067] | 349 | imageDir = ResourceManager::getInstance()->getFullName("pictures"); |
---|
| 350 | ResourceManager::getInstance()->addImageDir(imageDir); |
---|
[4009] | 351 | |
---|
[7355] | 352 | // DynamicLoader::loadDyLib("libtest.so"); |
---|
[7167] | 353 | |
---|
[5488] | 354 | // start the collision detection engine |
---|
[4766] | 355 | CDEngine::getInstance(); |
---|
[5074] | 356 | return 0; |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | /** |
---|
| 360 | * initializes miscelaneous features |
---|
| 361 | * @return -1 on failure |
---|
| 362 | */ |
---|
| 363 | int Orxonox::initMisc() |
---|
| 364 | { |
---|
[7374] | 365 | OrxShell::ShellBuffer::getInstance(); |
---|
[4766] | 366 | return 0; |
---|
[1858] | 367 | } |
---|
[1849] | 368 | |
---|
[2190] | 369 | /** |
---|
[4836] | 370 | * starts the orxonox game or menu |
---|
[4833] | 371 | * here is the central orxonox state manager. There are currently two states |
---|
| 372 | * - menu |
---|
| 373 | * - game-play |
---|
| 374 | * both states manage their states themselfs again. |
---|
[2190] | 375 | */ |
---|
[2636] | 376 | void Orxonox::start() |
---|
| 377 | { |
---|
[4556] | 378 | |
---|
[2636] | 379 | this->gameLoader = GameLoader::getInstance(); |
---|
[5996] | 380 | |
---|
[6139] | 381 | if( this->port != -1) |
---|
| 382 | this->gameLoader->loadNetworkCampaign("worlds/DefaultNetworkCampaign.oxc"); |
---|
[5996] | 383 | else |
---|
[6139] | 384 | this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); /* start orxonox in single player mode */ |
---|
[5996] | 385 | |
---|
[4010] | 386 | // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
---|
[2636] | 387 | this->gameLoader->init(); |
---|
| 388 | this->gameLoader->start(); |
---|
| 389 | } |
---|
| 390 | |
---|
[3214] | 391 | |
---|
[2636] | 392 | /** |
---|
[4833] | 393 | * handles sprecial events from localinput |
---|
| 394 | * @param event: an event not handled by the CommandNode |
---|
| 395 | */ |
---|
[4817] | 396 | // void Orxonox::graphicsHandler(SDL_Event* event) |
---|
| 397 | // { |
---|
| 398 | // // Handle special events such as reshape, quit, focus changes |
---|
| 399 | // switch (event->type) |
---|
| 400 | // { |
---|
| 401 | // case SDL_VIDEORESIZE: |
---|
| 402 | // GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
---|
| 403 | // tmpGEngine->resolutionChanged(event->resize); |
---|
| 404 | // break; |
---|
| 405 | // } |
---|
| 406 | // } |
---|
[1875] | 407 | |
---|
[4556] | 408 | |
---|
[4408] | 409 | |
---|
[1803] | 410 | |
---|
[3214] | 411 | |
---|
[4782] | 412 | |
---|
[4059] | 413 | bool showGui = false; |
---|
[3648] | 414 | |
---|
[4766] | 415 | |
---|
| 416 | |
---|
| 417 | /********************************** |
---|
| 418 | *** ORXONOX MAIN STARTING POINT *** |
---|
| 419 | **********************************/ |
---|
[3449] | 420 | /** |
---|
[4833] | 421 | * |
---|
[4836] | 422 | * main function |
---|
[4833] | 423 | * |
---|
| 424 | * here the journey begins |
---|
[3449] | 425 | */ |
---|
[4556] | 426 | int main(int argc, char** argv) |
---|
| 427 | { |
---|
[7256] | 428 | CmdLinePrefsReader prefs; |
---|
[7374] | 429 | |
---|
[7661] | 430 | IniFilePrefsReader ini(File(DEFAULT_CONFIG_FILE).name()); |
---|
| 431 | Preferences::getInstance()->setUserIni(File(DEFAULT_CONFIG_FILE).name()); |
---|
[7374] | 432 | |
---|
[7256] | 433 | prefs.parse(argc, argv); |
---|
[7374] | 434 | |
---|
[7256] | 435 | if ( Preferences::getInstance()->getString("misc", "showLicenseAndExit", "") == "1" ) |
---|
[5996] | 436 | { |
---|
[7256] | 437 | PRINT(0)(ORXONOX_LICENSE_SHORT); |
---|
| 438 | return 0; |
---|
[5996] | 439 | } |
---|
[7374] | 440 | |
---|
[7440] | 441 | if ( Preferences::getInstance()->getString("misc", "start-gdb", "0") == "1" ) |
---|
| 442 | { |
---|
| 443 | SignalHandler::getInstance()->doCatch( argv[0], GDB_RUN_IN_FOREGROUND ); |
---|
| 444 | } |
---|
| 445 | else if ( Preferences::getInstance()->getString("misc", "bt-to-file", "1") == "1" ) |
---|
| 446 | { SignalHandler::getInstance()->doCatch( argv[0], GDB_RUN_WRITE_TO_FILE ); |
---|
[7460] | 447 | |
---|
[7440] | 448 | } |
---|
[7460] | 449 | |
---|
[7256] | 450 | if( Preferences::getInstance()->getString("game", "showGui", "") == "1" ) |
---|
| 451 | showGui = true; |
---|
| 452 | else if( Preferences::getInstance()->getString( "game", "gameType", "" ) == "multiplayer_server" || |
---|
| 453 | Preferences::getInstance()->getString( "game", "gameType", "" ) == "multiplayer_client" ) |
---|
| 454 | return startNetworkOrxonox(argc, argv); |
---|
[7374] | 455 | |
---|
[7256] | 456 | return startOrxonox(argc, argv, "", -1); |
---|
| 457 | return 0; |
---|
[3648] | 458 | } |
---|
| 459 | |
---|
| 460 | |
---|
| 461 | |
---|
[5996] | 462 | /** |
---|
| 463 | * starts orxonox in network mode |
---|
| 464 | * @param argc parameters count given to orxonox |
---|
| 465 | * @param argv parameters given to orxonox |
---|
| 466 | */ |
---|
| 467 | int startNetworkOrxonox(int argc, char** argv) |
---|
| 468 | { |
---|
| 469 | |
---|
[7256] | 470 | std::string gameType = Preferences::getInstance()->getString( "game", "gameType", "" ); |
---|
[7374] | 471 | |
---|
[7256] | 472 | if ( gameType == "multiplayer_client" ) |
---|
[4132] | 473 | { |
---|
[7256] | 474 | int port = Preferences::getInstance()->getInt( "game", "port", DEFAULT_ORXONOX_PORT ); |
---|
| 475 | std::string host = Preferences::getInstance()->getString( "game", "host", "" ); |
---|
[7374] | 476 | |
---|
[7256] | 477 | if ( host == "" ) |
---|
[5996] | 478 | { |
---|
[7256] | 479 | printf("You need to specify a host to connect to ( -H <host> )\n"); |
---|
| 480 | return 1; |
---|
[5996] | 481 | } |
---|
[7374] | 482 | |
---|
[7256] | 483 | printf("Starting Orxonox as client: connecting to %s, on port %i\n", host.c_str(), port); |
---|
[7374] | 484 | |
---|
[7256] | 485 | startOrxonox(argc, argv, host.c_str(), port); |
---|
[4132] | 486 | } |
---|
[7256] | 487 | else if ( gameType == "multiplayer_server" ) |
---|
| 488 | { |
---|
| 489 | int port = Preferences::getInstance()->getInt( "game", "port", DEFAULT_ORXONOX_PORT ); |
---|
[7374] | 490 | |
---|
[7256] | 491 | printf("Starting Orxonox as server: listening on port %i\n", port); |
---|
[7374] | 492 | |
---|
[7256] | 493 | startOrxonox(argc, argv, "", port); |
---|
| 494 | } |
---|
[3648] | 495 | } |
---|
| 496 | |
---|
[3649] | 497 | |
---|
[4766] | 498 | |
---|
| 499 | /** |
---|
| 500 | * starts orxonox |
---|
| 501 | * @param argc parameters count given to orxonox |
---|
| 502 | * @param argv parameters given to orxonox |
---|
| 503 | */ |
---|
[7256] | 504 | int startOrxonox(int argc, char** argv, const std::string & name, int port) |
---|
[3648] | 505 | { |
---|
[4830] | 506 | // checking for existence of the configuration-files, or if the lock file is still used |
---|
[7661] | 507 | if (showGui || (!File("./orxonox.conf").isFile() && |
---|
| 508 | !File(DEFAULT_CONFIG_FILE).isFile()) |
---|
[5424] | 509 | #if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails |
---|
[5996] | 510 | || ResourceManager::isFile(DEFAULT_LOCK_FILE) |
---|
[4981] | 511 | #endif |
---|
| 512 | ) |
---|
[5996] | 513 | { |
---|
[7661] | 514 | File lockFile(DEFAULT_LOCK_FILE); |
---|
| 515 | if (lockFile.isFile()) |
---|
| 516 | lockFile.remove(); |
---|
[4556] | 517 | |
---|
[5996] | 518 | // starting the GUI |
---|
[7661] | 519 | OrxGui::QtGui gui(argc, argv); |
---|
| 520 | gui.startGui(); |
---|
[4132] | 521 | |
---|
[7661] | 522 | if (gui.getState() & OrxGui::Gui::Quitting) |
---|
[5996] | 523 | return 0; |
---|
[4556] | 524 | |
---|
[5996] | 525 | } |
---|
[4556] | 526 | |
---|
[4032] | 527 | PRINT(0)(">>> Starting Orxonox <<<\n"); |
---|
[4033] | 528 | |
---|
[7661] | 529 | File(DEFAULT_LOCK_FILE).touch(); |
---|
[4033] | 530 | |
---|
[1850] | 531 | Orxonox *orx = Orxonox::getInstance(); |
---|
[4556] | 532 | |
---|
[5996] | 533 | if( orx->init(argc, argv, name, port) == -1) |
---|
| 534 | { |
---|
| 535 | PRINTF(1)("! Orxonox initialization failed\n"); |
---|
| 536 | return -1; |
---|
| 537 | } |
---|
[4556] | 538 | |
---|
[5996] | 539 | printf("finished inizialisation\n"); |
---|
[2636] | 540 | orx->start(); |
---|
[4556] | 541 | |
---|
[3676] | 542 | delete orx; |
---|
[7661] | 543 | File("~/.orxonox/orxonox.lock").remove(); |
---|
[1803] | 544 | } |
---|