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