Changeset 5996 in orxonox.OLD for trunk/src/orxonox.cc
- Timestamp:
- Dec 9, 2005, 12:31:01 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/orxonox.cc
r5982 r5996 57 57 #include "load_param_description.h" 58 58 59 #include "network_manager.h" 60 59 61 #include <string.h> 60 62 … … 79 81 this->argc = 0; 80 82 this->argv = NULL; 83 84 /* this way, there is no network enabled: */ 85 this->serverName = NULL; 86 this->port = -1; 81 87 82 88 this->configFileName = NULL; … … 118 124 119 125 PRINT(3) 120 121 122 123 124 125 126 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 ); 127 133 128 134 Orxonox::singletonRef = NULL; … … 137 143 void Orxonox::restart() 138 144 { 139 // int argc = this->argc;140 // char** argv = this->argv;141 //142 // Orxonox *orx = Orxonox::getInstance();143 //144 // delete orx;145 //146 // orx = Orxonox::getInstance();147 //148 // if((*orx).init(argc, argv) == -1)149 // {150 // PRINTF(1)("! Orxonox initialization failed\n");151 // return;152 // }153 //154 // printf("finished inizialisation\n");155 // orx->start();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(); 156 162 } 157 163 … … 179 185 * initialize Orxonox with command line 180 186 */ 181 int Orxonox::init (int argc, char** argv )187 int Orxonox::init (int argc, char** argv, const char* name, int port) 182 188 { 183 189 this->argc = argc; 184 190 this->argv = argv; 185 // parse command line 186 // config file 191 192 this->serverName = name; 193 this->port = port; 187 194 188 195 // initialize the Config-file 189 196 this->getConfigFile(); 190 197 191 // initialize everything192 SDL_Init(SDL_INIT_TIMER);193 198 // windows must not write into stdout.txt and stderr.txt 194 199 #ifdef __WIN32__ … … 197 202 #endif 198 203 199 if( initResources () == -1) return -1; 200 if( initVideo() == -1) return -1; 201 if( initSound() == -1) return -1; 202 if( initInput() == -1) return -1; 203 if( initNetworking () == -1) return -1; 204 if( initMisc () == -1) return -1; 205 206 return 0; 207 } 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; 218 219 return 0; 220 } 221 208 222 209 223 /** 210 224 * initializes SDL and OpenGL 211 */225 */ 212 226 int Orxonox::initVideo() 213 227 { … … 226 240 return 0; 227 241 } 242 228 243 229 244 /** … … 263 278 PRINT(3)("> Initializing networking\n"); 264 279 265 printf(" ---Not yet implemented-FIXME--\n"); 280 if( this->serverName != NULL) // we are a client 281 NetworkManager::getInstance()->establishConnection(this->serverName, port); 282 else if( this->port > 0) // we are a server 283 NetworkManager::getInstance()->createServer(port); 284 266 285 return 0; 267 286 } … … 282 301 { 283 302 if (!ResourceManager::getInstance()->setDataDir(dataPath) && 284 303 !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) 285 304 { 286 305 PRINTF(1)("Data Could not be located in %s\n", dataPath); … … 301 320 exit(-1); 302 321 } 303 322 //! @todo this is a hack and should be loadable 304 323 char* imageDir = ResourceManager::getInstance()->getFullName("maps"); 305 324 ResourceManager::getInstance()->addImageDir(imageDir); … … 332 351 333 352 this->gameLoader = GameLoader::getInstance(); 334 this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); 353 354 if( this->port != -1 || this->serverName != NULL) 355 this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); /* actualy loadNetworkCampaign*/ 356 else 357 this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); 358 335 359 // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); 336 360 this->gameLoader->init(); … … 375 399 int main(int argc, char** argv) 376 400 { 377 // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.378 401 int i; 379 402 for(i = 1; i < argc; ++i) 403 { 404 if( !strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) 405 return showHelp(argc, argv); 406 else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) 407 showGui = true; 408 else if(!strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) 409 return startNetworkOrxonox(argc, argv); 410 else if(!strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) 411 return startNetworkOrxonox(argc, argv); 412 else if(!strcmp( "--license", argv[i]) || !strcmp("-s", argv[i])) 413 return PRINT(0)(ORXONOX_LICENSE_SHORT); 414 } 415 416 return startOrxonox(argc, argv, NULL, -1); 417 } 418 419 420 421 int showHelp(int argc, char** argv) 422 { 423 PRINT(0)("Orxonox Version %s\n", PACKAGE_VERSION); 424 PRINT(0)(" Starts Orxonox - The most furious 3D Action Game :)\n"); 425 PRINT(0)("\n"); 426 PRINT(0)("Common options:\n"); 427 PRINT(0)(" -g, --gui starts the orxonox with the configuration GUI \n"); 428 PRINT(0)(" -h, --help shows this help\n"); 429 PRINT(0)("\n"); 430 PRINT(0)("Network options:\n"); 431 PRINT(0)(" -s, --server [port] starts Orxonox and listens on the [port] for players\n"); 432 PRINT(0)(" -c, --client [hostname] [port] starts Orxonox as a Client\n"); 433 PRINT(0)(" -c, --client [ip address] [port] starts Orxonox as a Client\n"); 434 PRINT(0)("\n"); 435 PRINT(0)("Other options:\n"); 436 PRINT(0)(" --license prints the licence and exit\n\n"); 437 PRINT(0)("\n"); 438 439 // { 440 // Gui* gui = new Gui(argc, argv); 441 // gui->printHelp(); 442 // delete gui; 443 // } 444 } 445 446 447 448 449 /** 450 * starts orxonox in network mode 451 * @param argc parameters count given to orxonox 452 * @param argv parameters given to orxonox 453 */ 454 int startNetworkOrxonox(int argc, char** argv) 455 { 456 457 int i; 458 for(i = 0; i < argc; ++i ) 459 { 460 if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) 380 461 { 381 if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv); 382 // else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks(); 383 else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true; 384 // else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]); 462 if( argc <= (i+2)) 463 { 464 printf(" Wrong arguments try following notations:\n"); 465 printf(" --client [server ip address] [port number]\n"); 466 printf(" --client [dns name] [port number]\n"); 467 return 0; 468 } 469 470 const char* name = argv[i+1]; 471 int port = atoi(argv[i+2]); 472 printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port); 473 474 startOrxonox(argc, argv, name, port); 385 475 } 386 387 return startOrxonox(argc, argv); 388 } 389 390 391 392 int startHelp(int argc, char** argv) 393 { 394 PRINT(0)("orxonox: starts the orxonox game - rules\n"); 395 PRINT(0)("usage: orxonox [arg [arg...]]\n\n"); 396 PRINT(0)("valid options:\n"); 397 { 398 Gui* gui = new Gui(argc, argv); 399 gui->printHelp(); 400 delete gui; 401 } 402 PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n"); 403 PRINT(0)(" -h|--help:\t\t\tshows this help\n"); 476 else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) 477 { 478 if( argc <= (i+1)) 479 { 480 printf(" Wrong arguments try following notations:\n"); 481 printf(" --server [port number]\n"); 482 return 0; 483 } 484 485 int port = atoi(argv[i+1]); 486 printf("Starting Orxonox as server, listening on port %i\n", port); 487 488 startOrxonox(argc, argv, NULL, port); 489 } 490 } 404 491 } 405 492 … … 411 498 * @param argv parameters given to orxonox 412 499 */ 413 int startOrxonox(int argc, char** argv )500 int startOrxonox(int argc, char** argv, const char* name, int port) 414 501 { 415 502 // checking for existence of the configuration-files, or if the lock file is still used 416 503 if (showGui || (!ResourceManager::isFile("./orxonox.conf") && 417 !ResourceManager::isFile(DEFAULT_CONFIG_FILE))504 !ResourceManager::isFile(DEFAULT_CONFIG_FILE)) 418 505 #if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails 419 506 || ResourceManager::isFile(DEFAULT_LOCK_FILE) 420 507 #endif 421 508 ) 422 423 424 425 426 427 428 429 430 431 432 433 434 509 { 510 if (ResourceManager::isFile(DEFAULT_LOCK_FILE)) 511 ResourceManager::deleteFile(DEFAULT_LOCK_FILE); 512 513 // starting the GUI 514 Gui* gui = new Gui(argc, argv); 515 gui->startGui(); 516 517 if (! gui->startOrxonox) 518 return 0; 519 520 delete gui; 521 } 435 522 436 523 PRINT(0)(">>> Starting Orxonox <<<\n"); … … 440 527 Orxonox *orx = Orxonox::getInstance(); 441 528 442 if( orx->init(argc, argv) == -1)443 444 445 446 447 448 529 if( orx->init(argc, argv, name, port) == -1) 530 { 531 PRINTF(1)("! Orxonox initialization failed\n"); 532 return -1; 533 } 534 535 printf("finished inizialisation\n"); 449 536 orx->start(); 450 537
Note: See TracChangeset
for help on using the changeset viewer.