Changeset 6351 in orxonox.OLD for branches/network
- Timestamp:
- Dec 30, 2005, 1:55:51 PM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/orxonox.cc
r6142 r6351 29 29 30 30 #include "globals.h" 31 #include "class_list.h" 31 32 32 33 #include "gui.h" 33 34 34 #include "world.h"35 35 #include "parser/ini_parser/ini_parser.h" 36 #include "game_loader.h" 37 38 // ENGINES36 37 38 // load the core engines 39 39 #include "graphics_engine.h" 40 40 #include "sound_engine.h" 41 41 #include "resource_manager.h" 42 42 #include "cd_engine.h" 43 #include "text_engine.h"44 43 #include "event_handler.h" 44 #include "network_manager.h" 45 #include "game_loader.h" 46 45 47 46 48 #include "factory.h" 47 49 #include "fast_factory.h" 48 50 49 #include "benchmark.h"50 51 #include "class_list.h" 51 // #include "benchmark.h" 52 53 52 54 #include "shell_command_class.h" 53 55 #include "shell_command.h" 54 56 #include "shell_buffer.h" 55 56 57 #include "load_param_description.h" 57 58 58 #include "network_manager.h"59 59 60 60 #include <string.h> … … 64 64 using namespace std; 65 65 66 SHELL_COMMAND(restart, Orxonox, restart); 66 67 67 68 68 /** … … 138 138 Orxonox* Orxonox::singletonRef = NULL; 139 139 140 // DANGEROUS141 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 }161 140 162 141 /** … … 188 167 this->argv = argv; 189 168 169 190 170 this->serverName = name; 191 171 this->port = port; … … 202 182 // initialize everything 203 183 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) 215 195 return -1; 216 196 … … 222 202 * initializes SDL and OpenGL 223 203 */ 224 int Orxonox::initVideo( )204 int Orxonox::initVideo(int argc, char** argv) 225 205 { 226 206 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 227 212 228 213 GraphicsEngine::getInstance(); … … 236 221 delete[] iconName; 237 222 } 223 224 /* if this orxonox program is a dedicated server - don't draw anything */ 225 if( this->dedicatedServer == 1) 226 { 227 228 } 238 229 return 0; 239 230 } … … 243 234 * initializes the sound engine 244 235 */ 245 int Orxonox::initSound( )236 int Orxonox::initSound(int argc, char** argv) 246 237 { 247 238 PRINT(3)("> Initializing sound\n"); … … 258 249 * initializes input functions 259 250 */ 260 int Orxonox::initInput( )251 int Orxonox::initInput(int argc, char** argv) 261 252 { 262 253 PRINT(3)("> Initializing input\n"); … … 272 263 * initializes network system 273 264 */ 274 int Orxonox::initNetworking( )265 int Orxonox::initNetworking(int argc, char** argv) 275 266 { 276 267 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 277 328 278 329 if( this->serverName != NULL) // we are a client … … 289 340 * initializes and loads resource files 290 341 */ 291 int Orxonox::initResources( )342 int Orxonox::initResources(int argc, char** argv) 292 343 { 293 344 PRINTF(3)("> Initializing resources\n"); … … 333 384 * @return -1 on failure 334 385 */ 335 int Orxonox::initMisc( )386 int Orxonox::initMisc(int argc, char** argv) 336 387 { 337 388 ShellBuffer::getInstance(); … … 405 456 else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) 406 457 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);411 458 else if(!strcmp( "--license", argv[i]) || !strcmp("-s", argv[i])) 412 459 return PRINT(0)(ORXONOX_LICENSE_SHORT); … … 444 491 445 492 446 447 448 /**449 * starts orxonox in network mode450 * @param argc parameters count given to orxonox451 * @param argv parameters given to orxonox452 */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 494 493 /** 495 494 * starts orxonox -
branches/network/src/orxonox.h
r5996 r6351 9 9 #include "base_object.h" 10 10 11 class WorldEntity;12 11 class GameLoader; 13 12 class IniParser; … … 18 17 class Orxonox : public BaseObject { 19 18 19 20 20 public: 21 21 virtual ~Orxonox (); … … 24 24 25 25 int init(int argc, char** argv, const char* name, int port); 26 void start(); 26 27 27 void restart();28 29 void start();30 28 31 29 private: 32 30 Orxonox (); 33 31 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 34 39 void parseIniFile(const char* fileName); 40 const char* getConfigFile (); 35 41 36 int initResources ();37 int initVideo ();38 int initSound ();39 int initInput ();40 int initNetworking ();41 int initMisc ();42 43 const char* getConfigFile ();44 42 45 43 private: … … 54 52 55 53 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 56 55 int port; //!< number of the network port of the server/client if == -1 no network 57 56 }; … … 63 62 int showHelp(int argc, char** argv); 64 63 int showLicense(); 65 int startNetworkOrxonox(int argc, char** argv);66 64 int startOrxonox(int argc, char** argv, const char* clientName, int port); 67 65
Note: See TracChangeset
for help on using the changeset viewer.