Changeset 7256 in orxonox.OLD for trunk/src/orxonox.cc
- Timestamp:
- Mar 30, 2006, 11:45:31 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/orxonox.cc
r7221 r7256 58 58 59 59 #include "state.h" 60 60 #include "lib/parser/preferences/cmd_line_prefs_reader.h" 61 #include "lib/parser/preferences/ini_file_prefs_reader.h" 61 62 #include <string.h> 62 63 … … 66 67 67 68 SHELL_COMMAND(restart, Orxonox, restart); 69 70 REGISTER_ARG_FLAG( l, license, "misc", "showLicenseAndExit", "Prints the licence and exit", "1" ); 71 REGISTER_ARG_FLAG( c, client, "game", "gameType", "Connect to Server (-H)", "multiplayer_client" ); 72 REGISTER_ARG_FLAG( s, server, "game", "gameType", "Start Orxonox as Game Server", "multiplayer_server" ); 73 REGISTER_ARG_ARG( H, host, "game", "host", "Host to connect to", "host"); 74 REGISTER_ARG_ARG( p, port, "game", "port", "Port to use", "port" ); 75 REGISTER_ARG_FLAG( g, gui, "game", "showGui", "starts the orxonox with the configuration GUI", "1"); 68 76 69 77 /** … … 77 85 this->setName("orxonox-main"); 78 86 79 this->iniParser = NULL;80 81 87 this->argc = 0; 82 88 this->argv = NULL; 83 89 84 90 /* this way, there is no network enabled: */ 85 this->serverName = NULL;91 this->serverName = ""; 86 92 this->port = -1; 87 93 … … 114 120 // output-buffer 115 121 delete ShellBuffer::getInstance(); 116 117 // orxonox class-stuff118 delete this->iniParser;119 122 120 123 SDL_QuitSubSystem(SDL_INIT_TIMER); … … 175 178 else 176 179 this->configFileName = ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE); 177 this->iniParser = new IniParser(this->configFileName); 180 178 181 PRINTF(3)("Parsed Config File: '%s'\n", this->configFileName); 179 182 } … … 182 185 * initialize Orxonox with command line 183 186 */ 184 int Orxonox::init (int argc, char** argv, const char*name, int port)187 int Orxonox::init (int argc, char** argv, const std::string & name, int port) 185 188 { 186 189 this->argc = argc; … … 227 230 GraphicsEngine::getInstance(); 228 231 229 GraphicsEngine::getInstance()->initFrom IniFile(this->iniParser);232 GraphicsEngine::getInstance()->initFromPreferences(); 230 233 231 234 std::string iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp"); … … 247 250 SoundEngine::getInstance(); 248 251 249 SoundEngine::getInstance()->loadSettings( this->iniParser);252 SoundEngine::getInstance()->loadSettings(); 250 253 SoundEngine::getInstance()->initAudio(); 251 254 return 0; … … 260 263 PRINT(3)("> Initializing input\n"); 261 264 262 EventHandler::getInstance()->init( this->iniParser);265 EventHandler::getInstance()->init(); 263 266 EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE); 264 267 … … 274 277 PRINT(3)("> Initializing networking\n"); 275 278 276 if( this->serverName != NULL) // we are a client279 if( this->serverName != "") // we are a client 277 280 { 278 281 State::setOnline(true); … … 299 302 // init the resource manager 300 303 std::string dataPath; 301 if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= "")304 if ((dataPath = Preferences::getInstance()->getString(CONFIG_SECTION_DATA, CONFIG_NAME_DATADIR, ""))!= "") 302 305 { 303 306 if (!ResourceManager::getInstance()->setDataDir(dataPath) && … … 403 406 int main(int argc, char** argv) 404 407 { 405 int i; 406 for(i = 1; i < argc; ++i) 407 { 408 if( !strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) 409 return showHelp(argc, argv); 410 else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) 411 showGui = true; 412 else if(!strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) 413 return startNetworkOrxonox(argc, argv); 414 else if(!strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) 415 return startNetworkOrxonox(argc, argv); 416 else if(!strcmp( "--license", argv[i]) || !strcmp("-l", argv[i])) 417 return PRINT(0)(ORXONOX_LICENSE_SHORT); 418 } 419 420 return startOrxonox(argc, argv, NULL, -1); 421 } 422 423 424 425 int showHelp(int argc, char** argv) 426 { 427 PRINT(0)("Orxonox Version %s\n", PACKAGE_VERSION); 428 PRINT(0)(" Starts Orxonox - The most furious 3D Action Game :)\n"); 429 PRINT(0)("\n"); 430 PRINT(0)("Common options:\n"); 431 PRINT(0)(" -g, --gui starts the orxonox with the configuration GUI \n"); 432 PRINT(0)(" -h, --help shows this help\n"); 433 PRINT(0)("\n"); 434 PRINT(0)("Network options:\n"); 435 PRINT(0)(" -s, --server [port] starts Orxonox and listens on the [port] for players\n"); 436 PRINT(0)(" -c, --client [hostname] [port] starts Orxonox as a Client\n"); 437 PRINT(0)(" -c, --client [ip address] [port] starts Orxonox as a Client\n"); 438 PRINT(0)("\n"); 439 PRINT(0)("Other options:\n"); 440 PRINT(0)(" --license prints the licence and exit\n\n"); 441 PRINT(0)("\n"); 442 443 // { 444 // Gui* gui = new Gui(argc, argv); 445 // gui->printHelp(); 446 // delete gui; 447 // } 448 } 449 408 CmdLinePrefsReader prefs; 409 410 IniFilePrefsReader ini(ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE)); 411 412 prefs.parse(argc, argv); 413 414 if ( Preferences::getInstance()->getString("misc", "showLicenseAndExit", "") == "1" ) 415 { 416 PRINT(0)(ORXONOX_LICENSE_SHORT); 417 return 0; 418 } 419 420 if( Preferences::getInstance()->getString("game", "showGui", "") == "1" ) 421 showGui = true; 422 else if( Preferences::getInstance()->getString( "game", "gameType", "" ) == "multiplayer_server" || 423 Preferences::getInstance()->getString( "game", "gameType", "" ) == "multiplayer_client" ) 424 return startNetworkOrxonox(argc, argv); 425 426 return startOrxonox(argc, argv, "", -1); 427 return 0; 428 } 450 429 451 430 … … 459 438 { 460 439 461 int i; 462 for(i = 0; i < argc; ++i ) 463 { 464 if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) 440 std::string gameType = Preferences::getInstance()->getString( "game", "gameType", "" ); 441 442 if ( gameType == "multiplayer_client" ) 443 { 444 int port = Preferences::getInstance()->getInt( "game", "port", DEFAULT_ORXONOX_PORT ); 445 std::string host = Preferences::getInstance()->getString( "game", "host", "" ); 446 447 if ( host == "" ) 465 448 { 466 if( argc <= (i+2)) 467 { 468 printf(" Wrong arguments try following notations:\n"); 469 printf(" --client [server ip address] [port number]\n"); 470 printf(" --client [dns name] [port number]\n"); 471 return 0; 472 } 473 474 const char* name = argv[i+1]; 475 int port = atoi(argv[i+2]); 476 printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port); 477 478 startOrxonox(argc, argv, name, port); 449 printf("You need to specify a host to connect to ( -H <host> )\n"); 450 return 1; 479 451 } 480 else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) 481 { 482 if( argc <= (i+1)) 483 { 484 printf(" Wrong arguments try following notations:\n"); 485 printf(" --server [port number]\n"); 486 return 0; 487 } 488 489 int port = atoi(argv[i+1]); 490 printf("Starting Orxonox as server, listening on port %i\n", port); 491 492 startOrxonox(argc, argv, NULL, port); 493 } 452 453 printf("Starting Orxonox as client: connecting to %s, on port %i\n", host.c_str(), port); 454 455 startOrxonox(argc, argv, host.c_str(), port); 456 } 457 else if ( gameType == "multiplayer_server" ) 458 { 459 int port = Preferences::getInstance()->getInt( "game", "port", DEFAULT_ORXONOX_PORT ); 460 461 printf("Starting Orxonox as server: listening on port %i\n", port); 462 463 startOrxonox(argc, argv, "", port); 494 464 } 495 465 } … … 502 472 * @param argv parameters given to orxonox 503 473 */ 504 int startOrxonox(int argc, char** argv, const char*name, int port)474 int startOrxonox(int argc, char** argv, const std::string & name, int port) 505 475 { 506 476 // checking for existence of the configuration-files, or if the lock file is still used
Note: See TracChangeset
for help on using the changeset viewer.