Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6351 in orxonox.OLD for branches/network/src


Ignore:
Timestamp:
Dec 30, 2005, 1:55:51 PM (19 years ago)
Author:
patrick
Message:

network: the network initialisation is much better, working for dedicated server mode

Location:
branches/network/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/orxonox.cc

    r6142 r6351  
    2929
    3030#include "globals.h"
     31#include "class_list.h"
    3132
    3233#include "gui.h"
    3334
    34 #include "world.h"
    3535#include "parser/ini_parser/ini_parser.h"
    36 #include "game_loader.h"
    37 
    38 //ENGINES
     36
     37
     38// load the core engines
    3939#include "graphics_engine.h"
    4040#include "sound_engine.h"
    4141#include "resource_manager.h"
    4242#include "cd_engine.h"
    43 #include "text_engine.h"
    4443#include "event_handler.h"
     44#include "network_manager.h"
     45#include "game_loader.h"
     46
    4547
    4648#include "factory.h"
    4749#include "fast_factory.h"
    4850
    49 #include "benchmark.h"
    50 
    51 #include "class_list.h"
     51// #include "benchmark.h"
     52
     53
    5254#include "shell_command_class.h"
    5355#include "shell_command.h"
    5456#include "shell_buffer.h"
    55 
    5657#include "load_param_description.h"
    5758
    58 #include "network_manager.h"
    5959
    6060#include <string.h>
     
    6464using namespace std;
    6565
    66 SHELL_COMMAND(restart, Orxonox, restart);
     66
    6767
    6868/**
     
    138138Orxonox* Orxonox::singletonRef = NULL;
    139139
    140 // DANGEROUS
    141 void Orxonox::restart()
    142 {
    143   //   int argc = this->argc;
    144   //   char** argv = this->argv;
    145   //
    146   //   Orxonox *orx = Orxonox::getInstance();
    147   //
    148   //   delete orx;
    149   //
    150   //   orx = Orxonox::getInstance();
    151   //
    152   //   if((*orx).init(argc, argv) == -1)
    153   //   {
    154   //     PRINTF(1)("! Orxonox initialization failed\n");
    155   //     return;
    156   //   }
    157   //
    158   //   printf("finished inizialisation\n");
    159   //   orx->start();
    160 }
    161140
    162141/**
     
    188167  this->argv = argv;
    189168
     169
    190170  this->serverName = name;
    191171  this->port = port;
     
    202182  // initialize everything
    203183  SDL_Init(0);
    204   if( initResources () == -1)
    205     return -1;
    206   if( initVideo() == -1)
    207     return -1;
    208   if( initSound() == -1)
    209     return -1;
    210   if( initInput() == -1)
    211     return -1;
    212   if( initNetworking () == -1)
    213     return -1;
    214   if( initMisc () == -1)
     184  if( initResources (argc, argv) == -1)
     185    return -1;
     186  if( initVideo(argc, argv) == -1)
     187    return -1;
     188  if( initSound(argc, argv) == -1)
     189    return -1;
     190  if( initInput(argc, argv) == -1)
     191    return -1;
     192  if( initNetworking (argc, argv) == -1)
     193    return -1;
     194  if( initMisc (argc, argv) == -1)
    215195    return -1;
    216196
     
    222202 * initializes SDL and OpenGL
    223203 */
    224 int Orxonox::initVideo()
     204int Orxonox::initVideo(int argc, char** argv)
    225205{
    226206  PRINTF(3)("> Initializing video\n");
     207
     208  for( int i = 0; i < argc; i++)
     209    if( !strcmp( "--dedicated-server", argv[i]) || !strcmp("-ds", argv[i]))
     210      this->dedicatedServer = 1;
     211
    227212
    228213  GraphicsEngine::getInstance();
     
    236221    delete[] iconName;
    237222  }
     223
     224  /* if this orxonox program is a dedicated server - don't draw anything */
     225  if( this->dedicatedServer == 1)
     226  {
     227
     228  }
    238229  return 0;
    239230}
     
    243234 * initializes the sound engine
    244235 */
    245 int Orxonox::initSound()
     236int Orxonox::initSound(int argc, char** argv)
    246237{
    247238  PRINT(3)("> Initializing sound\n");
     
    258249 * initializes input functions
    259250 */
    260 int Orxonox::initInput()
     251int Orxonox::initInput(int argc, char** argv)
    261252{
    262253  PRINT(3)("> Initializing input\n");
     
    272263 * initializes network system
    273264 */
    274 int Orxonox::initNetworking()
     265int Orxonox::initNetworking(int argc, char** argv)
    275266{
    276267  PRINT(3)("> Initializing networking\n");
     268
     269  /* command line parsing
     270     parsing following commands:
     271       --client            or  -c
     272       --server            or  -s
     273       --dedicated-server  or  -ds
     274  */
     275  int i;
     276  for( i = 0; i < argc; ++i )
     277  {
     278    if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i]))
     279    {
     280      if( argc <= (i+2))
     281      {
     282        printf(" Wrong arguments try following notations:\n");
     283        printf("   --client [server ip address] [port number]\n");
     284        printf("   --client [dns name] [port number]\n");
     285        return -1;
     286      }
     287
     288      const char* name = argv[i+1];
     289      int port = atoi(argv[i+2]);
     290      printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port);
     291
     292      this->serverName = name;
     293      this->port = port;
     294    }
     295    else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i]))
     296    {
     297      if( argc <= (i+1))
     298      {
     299        printf(" Wrong arguments try following notations:\n");
     300        printf("   --server [port number]\n");
     301        return -1;
     302      }
     303
     304      int port = atoi(argv[i+1]);
     305      printf("Starting Orxonox as server, listening on port %i\n", port);
     306
     307      this->serverName = NULL;
     308      this->port = port;
     309    }
     310    else if( !strcmp( "--dedicated-server", argv[i]) || !strcmp("-ds", argv[i]))
     311    {
     312      if( argc <= (i+1))
     313      {
     314        printf(" Wrong arguments try following notations:\n");
     315        printf("   --dedicated-server [port number]\n");
     316        return -1;
     317      }
     318
     319      int port = atoi(argv[i+1]);
     320      printf("Starting Orxonox as dedicated-server, listening on port %i\n", port);
     321
     322      this->serverName = NULL;
     323      this->port = port;
     324      /*this->dedicatedServer = 1;  - this is already been done in the initVideo(...) function*/
     325    }
     326  }
     327
    277328
    278329  if( this->serverName != NULL) // we are a client
     
    289340 * initializes and loads resource files
    290341 */
    291 int Orxonox::initResources()
     342int Orxonox::initResources(int argc, char** argv)
    292343{
    293344  PRINTF(3)("> Initializing resources\n");
     
    333384 * @return -1 on failure
    334385 */
    335 int Orxonox::initMisc()
     386int Orxonox::initMisc(int argc, char** argv)
    336387{
    337388  ShellBuffer::getInstance();
     
    405456    else if(!strcmp( "--gui", argv[i])      || !strcmp("-g", argv[i]))
    406457      showGui = true;
    407     else if(!strcmp( "--client", argv[i])   || !strcmp("-c", argv[i]))
    408       return startNetworkOrxonox(argc, argv);
    409     else if(!strcmp( "--server", argv[i])   || !strcmp("-s", argv[i]))
    410       return startNetworkOrxonox(argc, argv);
    411458    else if(!strcmp( "--license", argv[i])  || !strcmp("-s", argv[i]))
    412459      return PRINT(0)(ORXONOX_LICENSE_SHORT);
     
    444491
    445492
    446 
    447 
    448 /**
    449  * starts orxonox in network mode
    450  * @param argc parameters count given to orxonox
    451  * @param argv parameters given to orxonox
    452  */
    453 int startNetworkOrxonox(int argc, char** argv)
    454 {
    455 
    456   int i;
    457   for(i = 0; i < argc; ++i )
    458   {
    459     if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i]))
    460     {
    461       if( argc <= (i+2))
    462       {
    463         printf(" Wrong arguments try following notations:\n");
    464         printf("   --client [server ip address] [port number]\n");
    465         printf("   --client [dns name] [port number]\n");
    466         return 0;
    467       }
    468 
    469       const char* name = argv[i+1];
    470       int port = atoi(argv[i+2]);
    471       printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port);
    472 
    473       startOrxonox(argc, argv, name, port);
    474     }
    475     else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i]))
    476     {
    477       if( argc <= (i+1))
    478       {
    479         printf(" Wrong arguments try following notations:\n");
    480         printf("   --server [port number]\n");
    481         return 0;
    482       }
    483 
    484       int port = atoi(argv[i+1]);
    485       printf("Starting Orxonox as server, listening on port %i\n", port);
    486 
    487       startOrxonox(argc, argv, NULL, port);
    488     }
    489   }
    490 }
    491 
    492 
    493 
    494493/**
    495494 * starts orxonox
  • branches/network/src/orxonox.h

    r5996 r6351  
    99#include "base_object.h"
    1010
    11 class WorldEntity;
    1211class GameLoader;
    1312class IniParser;
     
    1817class Orxonox : public BaseObject {
    1918
     19
    2020 public:
    2121  virtual ~Orxonox ();
     
    2424
    2525  int init(int argc, char** argv, const char* name, int port);
     26  void start();
    2627
    27   void restart();
    28 
    29   void start();
    3028
    3129 private:
    3230  Orxonox ();
    3331
     32  int initResources (int argc, char** argv);
     33  int initVideo (int argc, char** argv);
     34  int initSound (int argc, char** argv);
     35  int initInput (int argc, char** argv);
     36  int initNetworking (int argc, char** argv);
     37  int initMisc (int argc, char** argv);
     38
    3439  void parseIniFile(const char* fileName);
     40  const char* getConfigFile ();
    3541
    36   int initResources ();
    37   int initVideo ();
    38   int initSound ();
    39   int initInput ();
    40   int initNetworking ();
    41   int initMisc ();
    42 
    43   const char* getConfigFile ();
    4442
    4543 private:
     
    5452
    5553  const char*       serverName;              //!< Name of the Orxonox client if == NULL -> server
     54  int               dedicatedServer;         //!< is 1 if the server is a dedicated server, 0 else
    5655  int               port;                    //!< number of the network port of the server/client if == -1 no network
    5756};
     
    6362int showHelp(int argc, char** argv);
    6463int showLicense();
    65 int startNetworkOrxonox(int argc, char** argv);
    6664int startOrxonox(int argc, char** argv, const char* clientName, int port);
    6765
Note: See TracChangeset for help on using the changeset viewer.