Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7256 in orxonox.OLD for trunk/src/orxonox.cc


Ignore:
Timestamp:
Mar 30, 2006, 11:45:31 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the preferences back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/preferences . -r7233:HEAD
no conflicts… nice work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/orxonox.cc

    r7221 r7256  
    5858
    5959#include "state.h"
    60 
     60#include "lib/parser/preferences/cmd_line_prefs_reader.h"
     61#include "lib/parser/preferences/ini_file_prefs_reader.h"
    6162#include <string.h>
    6263
     
    6667
    6768SHELL_COMMAND(restart, Orxonox, restart);
     69
     70REGISTER_ARG_FLAG( l, license, "misc", "showLicenseAndExit", "Prints the licence and exit",    "1" );
     71REGISTER_ARG_FLAG( c, client,  "game", "gameType",           "Connect to Server (-H)",         "multiplayer_client" );
     72REGISTER_ARG_FLAG( s, server,  "game", "gameType",           "Start Orxonox as Game Server",   "multiplayer_server" );
     73REGISTER_ARG_ARG(  H, host,    "game", "host",               "Host to connect to",             "host");
     74REGISTER_ARG_ARG(  p, port,    "game", "port",               "Port to use",                    "port" );
     75REGISTER_ARG_FLAG( g, gui,     "game", "showGui",            "starts the orxonox with the configuration GUI", "1");
    6876
    6977/**
     
    7785  this->setName("orxonox-main");
    7886
    79   this->iniParser = NULL;
    80 
    8187  this->argc = 0;
    8288  this->argv = NULL;
    8389
    8490  /* this way, there is no network enabled: */
    85   this->serverName = NULL;
     91  this->serverName = "";
    8692  this->port = -1;
    8793
     
    114120  // output-buffer
    115121  delete ShellBuffer::getInstance();
    116 
    117   // orxonox class-stuff
    118   delete this->iniParser;
    119122
    120123  SDL_QuitSubSystem(SDL_INIT_TIMER);
     
    175178  else
    176179    this->configFileName = ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE);
    177   this->iniParser = new IniParser(this->configFileName);
     180
    178181  PRINTF(3)("Parsed Config File: '%s'\n", this->configFileName);
    179182}
     
    182185 * initialize Orxonox with command line
    183186 */
    184 int Orxonox::init (int argc, char** argv, const char* name, int port)
     187int Orxonox::init (int argc, char** argv, const std::string & name, int port)
    185188{
    186189  this->argc = argc;
     
    227230  GraphicsEngine::getInstance();
    228231
    229   GraphicsEngine::getInstance()->initFromIniFile(this->iniParser);
     232  GraphicsEngine::getInstance()->initFromPreferences();
    230233
    231234  std::string iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp");
     
    247250  SoundEngine::getInstance();
    248251
    249   SoundEngine::getInstance()->loadSettings(this->iniParser);
     252  SoundEngine::getInstance()->loadSettings();
    250253  SoundEngine::getInstance()->initAudio();
    251254  return 0;
     
    260263  PRINT(3)("> Initializing input\n");
    261264
    262   EventHandler::getInstance()->init(this->iniParser);
     265  EventHandler::getInstance()->init();
    263266  EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE);
    264267
     
    274277  PRINT(3)("> Initializing networking\n");
    275278
    276   if( this->serverName != NULL) // we are a client
     279  if( this->serverName != "") // we are a client
    277280  {
    278281    State::setOnline(true);
     
    299302  // init the resource manager
    300303  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, ""))!= "")
    302305  {
    303306    if (!ResourceManager::getInstance()->setDataDir(dataPath) &&
     
    403406int main(int argc, char** argv)
    404407{
    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}
    450429
    451430
     
    459438{
    460439
    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 == "" )
    465448    {
    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;
    479451    }
    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);
    494464  }
    495465}
     
    502472 * @param argv parameters given to orxonox
    503473 */
    504 int startOrxonox(int argc, char** argv, const char* name, int port)
     474int startOrxonox(int argc, char** argv, const std::string & name, int port)
    505475{
    506476  // 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.