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