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