Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Dec 9, 2005, 12:31:01 PM (20 years ago)
Author:
patrick
Message:

orxonox/trunk: merged network branche into trunk with command svn merge -r 5824:HEAD

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/orxonox.cc

    r5982 r5996  
    5757#include "load_param_description.h"
    5858
     59#include "network_manager.h"
     60
    5961#include <string.h>
    6062
     
    7981  this->argc = 0;
    8082  this->argv = NULL;
     83
     84  /* this way, there is no network enabled: */
     85  this->serverName = NULL;
     86  this->port = -1;
    8187
    8288  this->configFileName = NULL;
     
    118124
    119125  PRINT(3)
    120       (
    121       "===================================================\n" \
    122       "Thanks for playing orxonox.\n" \
    123       "visit: http://www.orxonox.net for new versions.\n" \
    124       "===================================================\n" \
    125       ORXONOX_LICENSE_SHORT
    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  );
    127133
    128134  Orxonox::singletonRef = NULL;
     
    137143void Orxonox::restart()
    138144{
    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();
    156162}
    157163
     
    179185 * initialize Orxonox with command line
    180186 */
    181 int Orxonox::init (int argc, char** argv)
     187int Orxonox::init (int argc, char** argv, const char* name, int port)
    182188{
    183189  this->argc = argc;
    184190  this->argv = argv;
    185   // parse command line
    186   // config file
     191
     192  this->serverName = name;
     193  this->port = port;
    187194
    188195  // initialize the Config-file
    189196  this->getConfigFile();
    190197
    191   // initialize everything
    192   SDL_Init(SDL_INIT_TIMER);
    193198  // windows must not write into stdout.txt and stderr.txt
    194199#ifdef __WIN32__
     
    197202#endif
    198203
    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
    208222
    209223/**
    210224 * initializes SDL and OpenGL
    211 */
     225 */
    212226int Orxonox::initVideo()
    213227{
     
    226240  return 0;
    227241}
     242
    228243
    229244/**
     
    263278  PRINT(3)("> Initializing networking\n");
    264279
    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
    266285  return 0;
    267286}
     
    282301  {
    283302    if (!ResourceManager::getInstance()->setDataDir(dataPath) &&
    284          !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
     303        !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
    285304    {
    286305      PRINTF(1)("Data Could not be located in %s\n", dataPath);
     
    301320    exit(-1);
    302321  }
    303    //! @todo this is a hack and should be loadable
     322  //! @todo this is a hack and should be loadable
    304323  char* imageDir = ResourceManager::getInstance()->getFullName("maps");
    305324  ResourceManager::getInstance()->addImageDir(imageDir);
     
    332351
    333352  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
    335359  //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
    336360  this->gameLoader->init();
     
    375399int main(int argc, char** argv)
    376400{
    377   // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
    378401  int i;
    379402  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
     421int 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 */
     454int 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]))
    380461    {
    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);
    385475    }
    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  }
    404491}
    405492
     
    411498 * @param argv parameters given to orxonox
    412499 */
    413 int startOrxonox(int argc, char** argv)
     500int startOrxonox(int argc, char** argv, const char* name, int port)
    414501{
    415502  // checking for existence of the configuration-files, or if the lock file is still used
    416503  if (showGui || (!ResourceManager::isFile("./orxonox.conf") &&
    417       !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
     504                  !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
    418505#if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails
    419        || ResourceManager::isFile(DEFAULT_LOCK_FILE)
     506      || ResourceManager::isFile(DEFAULT_LOCK_FILE)
    420507#endif
    421508     )
    422     {
    423       if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
    424         ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
    425 
    426       // starting the GUI
    427       Gui* gui = new Gui(argc, argv);
    428       gui->startGui();
    429 
    430       if (! gui->startOrxonox)
    431         return 0;
    432 
    433       delete gui;
    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  }
    435522
    436523  PRINT(0)(">>> Starting Orxonox <<<\n");
     
    440527  Orxonox *orx = Orxonox::getInstance();
    441528
    442   if(orx->init(argc, argv) == -1)
    443     {
    444       PRINTF(1)("! Orxonox initialization failed\n");
    445       return -1;
    446     }
    447 
    448     printf("finished inizialisation\n");
     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");
    449536  orx->start();
    450537
Note: See TracChangeset for help on using the changeset viewer.