Changeset 5829 in orxonox.OLD for branches/network/src/orxonox.cc
- Timestamp:
- Nov 30, 2005, 9:43:05 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/orxonox.cc
r5822 r5829 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->clientName = 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->clientName = 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 /** … … 262 277 PRINT(3)("> Initializing networking\n"); 263 278 264 printf(" ---Not yet implemented-FIXME--\n"); 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 265 286 return 0; 266 287 } … … 281 302 { 282 303 if (!ResourceManager::getInstance()->setDataDir(dataPath) && 283 304 !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) 284 305 { 285 306 PRINTF(1)("Data Could not be located in %s\n", dataPath); … … 300 321 exit(-1); 301 322 } 302 323 //! @todo this is a hack and should be loadable 303 324 char* imageDir = ResourceManager::getInstance()->getFullName("maps"); 304 325 ResourceManager::getInstance()->addImageDir(imageDir); … … 374 395 int main(int argc, char** argv) 375 396 { 376 // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.377 397 int i; 378 398 for(i = 1; i < argc; ++i) 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 } 411 412 return startOrxonox(argc, argv, NULL, -1); 413 } 414 415 416 417 int showHelp(int argc, char** argv) 418 { 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 ) 455 { 456 if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) 379 457 { 380 if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv); 381 // else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks(); 382 else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true; 383 // else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]); 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); 384 471 } 385 386 return startOrxonox(argc, argv); 387 } 388 389 390 391 int startHelp(int argc, char** argv) 392 { 393 PRINT(0)("orxonox: starts the orxonox game - rules\n"); 394 PRINT(0)("usage: orxonox [arg [arg...]]\n\n"); 395 PRINT(0)("valid options:\n"); 396 { 397 Gui* gui = new Gui(argc, argv); 398 gui->printHelp(); 399 delete gui; 400 } 401 PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n"); 402 PRINT(0)(" -h|--help:\t\t\tshows this help\n"); 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 } 486 } 403 487 } 404 488 … … 410 494 * @param argv parameters given to orxonox 411 495 */ 412 int startOrxonox(int argc, char** argv )496 int startOrxonox(int argc, char** argv, const char* name, int port) 413 497 { 414 498 // checking for existence of the configuration-files, or if the lock file is still used 415 499 if (showGui || (!ResourceManager::isFile("./orxonox.conf") && 416 !ResourceManager::isFile(DEFAULT_CONFIG_FILE))500 !ResourceManager::isFile(DEFAULT_CONFIG_FILE)) 417 501 #if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails 418 502 || ResourceManager::isFile(DEFAULT_LOCK_FILE) 419 503 #endif 420 504 ) 421 422 423 424 425 426 427 428 429 430 431 432 433 505 { 506 if (ResourceManager::isFile(DEFAULT_LOCK_FILE)) 507 ResourceManager::deleteFile(DEFAULT_LOCK_FILE); 508 509 // starting the GUI 510 Gui* gui = new Gui(argc, argv); 511 gui->startGui(); 512 513 if (! gui->startOrxonox) 514 return 0; 515 516 delete gui; 517 } 434 518 435 519 PRINT(0)(">>> Starting Orxonox <<<\n"); … … 439 523 Orxonox *orx = Orxonox::getInstance(); 440 524 441 if( orx->init(argc, argv) == -1)442 443 444 445 446 447 525 if( orx->init(argc, argv, name, port) == -1) 526 { 527 PRINTF(1)("! Orxonox initialization failed\n"); 528 return -1; 529 } 530 531 printf("finished inizialisation\n"); 448 532 orx->start(); 449 533
Note: See TracChangeset
for help on using the changeset viewer.