- Timestamp:
- Nov 30, 2005, 9:43:05 AM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 4 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/defs/globals.h
r5819 r5829 84 84 85 85 #define ORXONOX_LICENSE_SHORT \ 86 "orxonox - the future of 3D-vertical-scrollers\n" \ 87 "\n" \ 88 "Copyright (C) 2004 orx\n" \ 89 "\n" \ 90 "This program is free software; you can redistribute it and/or modify\n" \ 91 "it under the terms of the GNU General Public License as published by\n" \ 92 "the Free Software Foundation; either version 2, or (at your option)\n" \ 93 "any later version.\n" 86 "Orxonox - The Future of 3D-Action-Game\n" \ 87 "\n" \ 88 "Copyright (C) 2004 orx\n" \ 89 "\n" \ 90 "This program is free software; you can redistribute it and/or modify\n" \ 91 "it under the terms of the GNU General Public License as published by\n" \ 92 "the Free Software Foundation; either version 2, or (at your option)\n" \ 93 "any later version.\n" \ 94 "\n" \ 95 "This program is distributed in the hope that it will be useful,\n" \ 96 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \ 97 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \ 98 "GNU General Public License for more details.\n" \ 99 "\n" \ 100 "You should have received a copy of the GNU General Public License\n" \ 101 "along with this program; if not, write to the Free Software Foundation,\n" \ 102 "Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n" 94 103 95 104 -
branches/network/src/lib/network/network_manager.cc
r5822 r5829 35 35 36 36 37 /************************************ 38 What you will see here are the function definitions from the header file (network_manager.h) with doxygen documentation. Here is an example: 39 40 41 In file network_manager.h 42 43 class NetworkManager 44 { 45 int doSomeStuff(float argument, float* pointer); 46 } 47 48 will be implemented in the source file as follows: 49 50 In file network_manager.cc 51 52 / ** 53 * this is the short description for this function: it just does some stuff 54 * @param argument: this is the first argument, stuff... 55 * @param pointer: this is the pointer to nowhereland 56 * return: whatever the function returns: for example an index, number, etc. 57 * / 58 int NetworkManager::doSomeStuff(float argument, float* pointer) 59 { 60 // whaterver you want to do 61 } 62 63 64 if you want to make automake compile your files: you will want to add the file names to the local Makefile.am 65 66 ************************************/ 67 68 37 NetworkManager* NetworkManager::singletonRef = NULL; 69 38 70 39 /** … … 79 48 this->netStreamList = NULL; 80 49 this->syncList = NULL; 50 this->tmpStream = NULL; 81 51 82 52 PRINTF(0)("NetworkManager created\n"); … … 114 84 * creates a connection from one object to a host 115 85 * @param hostName: the name of the destination host 116 * @param synchronizeable: reference to the sync object117 86 */ 118 NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync) 119 {} 87 int NetworkManager::establishConnection(const char* name, unsigned int port) 88 { 89 IPaddress ipAddress; 90 int error = SDLNet_ResolveHost(&ipAddress, name, port); 91 if( error == -1) { 92 printf("\n\nerror on address resolution, program inconsistency\n\n"); 93 return -1; 94 } 95 96 this->tmpStream = new NetworkStream(ipAddress, NET_CLIENT); 97 return 1; 98 } 99 100 101 /** 102 * creates a new NetworkStream of server type 103 * @param port: number of the TCP port 104 */ 105 int NetworkManager::createServer(unsigned int port) 106 { 107 this->tmpStream = new NetworkStream(port, NET_SERVER); 108 SDL_Delay(20); 109 return 1; 110 } 120 111 121 112 … … 127 118 NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync) 128 119 { 129 printf("Establish connection to server %s, on port %u\n", SDLNet_ResolveIP(&address), address.port);130 120 /* creating a new network stream, it will register itself automaticaly to the class list */ 131 NetworkStream* netStream = new NetworkStream(address, sync, NET_CLIENT);121 this->tmpStream = new NetworkStream(address, sync, NET_CLIENT); 132 122 } 123 133 124 134 125 /** … … 140 131 PRINTF(0)("Create a new server socket\n"); 141 132 /* creating a new network stream, it will register itself automaticaly to the class list */ 142 NetworkStream* netStream = new NetworkStream(port, sync, NET_SERVER);133 this->tmpStream = new NetworkStream(port, sync, NET_SERVER); 143 134 } 144 135 … … 153 144 154 145 146 void NetworkManager::connectSynchronizeable(Synchronizeable& sync) 147 { 148 this->tmpStream->connectSynchronizeable(sync); 149 } 150 155 151 156 152 /** … … 161 157 if (this->netStreamList != NULL || (this->netStreamList = ClassList::getList(CL_NETWORK_STREAM)) != NULL) 162 158 { 159 // tIterator<BaseObject>* iterator = this->netStreamList->getIterator(); 160 // NetworkStream* stream = (NetworkStream*)(iterator->firstElement()); 161 // while( stream) 162 // { 163 // if(stream->isActive()) 164 // stream->processData(); 165 // stream = (NetworkStream*)(iterator->nextElement()); 166 // } 167 // delete iterator; 163 168 std::list<BaseObject*>::iterator stream; 164 169 for (stream = this->netStreamList->begin(); stream != this->netStreamList->end(); ++stream) 165 static_cast<NetworkStream*>(*stream)->processData(); 170 if( static_cast<NetworkStream*>(*stream)->isActive()) 171 static_cast<NetworkStream*>(*stream)->processData(); 172 166 173 } 167 174 -
branches/network/src/lib/network/network_manager.h
r5822 r5829 19 19 class NetworkStream; 20 20 class Synchronizeable; 21 template<typename> class tList; 21 template<typename> 22 class tList; 22 23 23 24 /* and here is the class itsself*/ … … 25 26 { 26 27 27 public:28 public: 28 29 29 NetworkManager(); 30 ~NetworkManager(); 30 inline static NetworkManager* getInstance() { if (!NetworkManager::singletonRef) NetworkManager::singletonRef = new NetworkManager(); 31 return NetworkManager::singletonRef; } 32 ~NetworkManager(); 31 33 32 void initialize();33 void shutdown();34 void initialize(); 35 void shutdown(); 34 36 35 NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync); 36 NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync); 37 NetworkStream& createServer(Synchronizeable& sync, unsigned int port); 38 void shutdownConnection(); 37 int establishConnection(const char* name, unsigned int port); 38 int createServer(unsigned int port); 39 39 40 void synchronize(); 40 NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync); 41 NetworkStream& createServer(Synchronizeable& sync, unsigned int port); 42 void shutdownConnection(); 41 43 42 private: 43 std::list<BaseObject*>* netStreamList; // list with refs to all network streams 44 std::list<BaseObject*>* syncList; // list of synchronizeables 44 void connectSynchronizeable(Synchronizeable& sync); 45 46 void synchronize(); 47 48 private: 49 NetworkManager(); 50 51 52 private: 53 std::list<BaseObject*>* netStreamList; // list with refs to all network streams 54 std::list<BaseObject*>* syncList; // list of synchronizeables 55 static NetworkManager* singletonRef; //!< Pointer to the only instance of this Class 56 NetworkStream* tmpStream; //!< FIXME: this is only for testing purposes 45 57 46 58 }; -
branches/network/src/lib/network/network_socket.cc
r5822 r5829 313 313 314 314 while (!tempsocket && !self->terminateThread) 315 { 315 316 tempsocket = SDLNet_TCP_Accept(self->tcpSocket); 317 SDL_Delay(_MSECONDS_SLEEP_LISTEN); 318 } 316 319 317 320 SDL_mutexP(self->socketMutex); -
branches/network/src/lib/network/network_socket.h
r5822 r5829 18 18 //sleep if outgoing buffer is empty 19 19 #define _MSECONDS_SLEEP_EMPTY_BUFFER 10 20 //sleep when waiting for connections 21 #define _MSECONDS_SLEEP_LISTEN 100 20 22 21 23 /* contains memmove and memcpy */ -
branches/network/src/lib/network/network_stream.cc
r5822 r5829 40 40 41 41 NetworkStream::NetworkStream() 42 : DataStream()42 : DataStream() 43 43 { 44 44 this->init(); … … 50 50 } 51 51 52 NetworkStream::NetworkStream(IPaddress& address, NodeType type) 53 { 54 this->init(); 55 this->networkSocket = new NetworkSocket(address); 56 this->networkProtocol = new NetworkProtocol(); 57 this->synchronizeables = NULL; 58 this->connectionMonitor = new ConnectionMonitor(); 59 } 60 61 62 NetworkStream::NetworkStream(unsigned int port, NodeType type) 63 { 64 this->init(); 65 this->networkSocket = new NetworkSocket(); 66 this->networkSocket->listen(port); 67 this->networkProtocol = new NetworkProtocol(); 68 this->synchronizeables = NULL; 69 this->connectionMonitor = new ConnectionMonitor(); 70 } 71 52 72 53 73 NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type) 54 : DataStream()74 : DataStream() 55 75 { 56 76 this->init(); … … 59 79 this->synchronizeables = &sync; 60 80 this->connectionMonitor = new ConnectionMonitor(); 81 this->bActive = true; 61 82 } 62 83 63 84 64 85 NetworkStream::NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type) 65 : DataStream()86 : DataStream() 66 87 { 67 88 this->init(); … … 71 92 this->synchronizeables = &sync; 72 93 this->connectionMonitor = new ConnectionMonitor(); 94 this->bActive = true; 73 95 } 74 96 … … 79 101 this->setClassID(CL_NETWORK_STREAM, "NetworkStream"); 80 102 this->state = NET_REC_HEADER; 103 this->bActive = false; 81 104 } 82 105 … … 85 108 { 86 109 87 networkSocket->disconnectServer();110 networkSocket->disconnectServer(); 88 111 89 if( this->networkSocket)90 delete networkSocket;112 if( this->networkSocket) 113 delete networkSocket; 91 114 92 delete connectionMonitor;93 delete networkProtocol;115 delete connectionMonitor; 116 delete networkProtocol; 94 117 } 118 119 120 void NetworkStream::connectSynchronizeable(Synchronizeable& sync) 121 { 122 this->synchronizeables = &sync; 123 if( this->networkSocket != NULL) 124 this->bActive = true; 125 } 126 95 127 96 128 void NetworkStream::processData() … … 102 134 PRINT(0)("============= DOWNSTREAM:===============\n"); 103 135 /* first of all read the synchronizeable's data: */ 136 //if(this->isServer()) 104 137 dataLength = this->synchronizeables->readBytes((byte*)downBuffer); 105 138 106 /* send the received data to connectionMonitor */ 107 this->connectionMonitor->processPacket((byte*)downBuffer, dataLength); 139 if( dataLength > 0) 140 { 141 /* send the received data to connectionMonitor */ 142 this->connectionMonitor->processPacket((byte*)downBuffer, dataLength); 108 143 109 dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE,110 *(this->synchronizeables), 12/* some random number (no real id)*/);144 dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, 145 *(this->synchronizeables), 12/* some random number (no real id)*/); 111 146 112 /* pass the data to the network socket */ 113 dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength); 114 /* check if there was an error */ 115 if( dataLength == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");} 116 147 /* pass the data to the network socket */ 148 dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength); 149 /* check if there was an error */ 150 if( dataLength == -1) 151 { 152 PRINTF(0)("Error in writing data to the NetworkSocket\n"); 153 } 154 } 117 155 118 156 … … 147 185 this->connectionMonitor->processPacket((byte*)upBuffer, this->packetHeader.length); 148 186 /* now pass the data to the sync object */ 187 //if(!this->isServer()) 149 188 this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length); 150 189 -
branches/network/src/lib/network/network_stream.h
r5822 r5829 28 28 { 29 29 30 public: 31 NetworkStream(); 32 NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type); 33 NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type); 34 ~NetworkStream(); 30 public: 31 NetworkStream(); 32 NetworkStream(IPaddress& address, NodeType type); 33 NetworkStream(unsigned int port, NodeType type); 35 34 36 void init(); 35 NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type); 36 NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type); 37 ~NetworkStream(); 38 void init(); 37 39 38 inline bool isServer() { return (this->type == NET_SERVER)? true:false; } 39 virtual void processData(); 40 void connectSynchronizeable(Synchronizeable& sync); 40 41 41 private: 42 NetworkProtocol* networkProtocol; 43 //NetworkSocket* networkSockets; 44 ConnectionMonitor* connectionMonitor; 45 // tList<Synchronizeable>* synchronizeables; 46 Synchronizeable* synchronizeables; 47 NetworkSocket* networkSocket; 48 int type; 49 int state; 50 Header packetHeader; 42 inline bool isServer() const { return (this->type == NET_SERVER)? true:false; } 43 inline bool isActive() const { return this->bActive; } 44 45 virtual void processData(); 46 47 private: 48 NetworkProtocol* networkProtocol; 49 ConnectionMonitor* connectionMonitor; 50 Synchronizeable* synchronizeables; 51 NetworkSocket* networkSocket; 52 int type; 53 int state; 54 Header packetHeader; 55 bool bActive; 51 56 }; 52 57 #endif /* _NETWORK_STREAM */ 53 -
branches/network/src/lib/network/synchronizeable.cc
r5822 r5829 18 18 #include "netdefs.h" 19 19 20 21 /** 22 * default constructor 23 */ 24 Synchronizeable::Synchronizeable() 25 {} 26 20 27 /** 21 28 * default constructor … … 25 32 this->setName(name); 26 33 } 34 27 35 28 36 /** … … 41 49 * read data from NetworkStream 42 50 */ 43 int Synchronizeable::readBytes(byte* data) const51 int Synchronizeable::readBytes(byte* data) 44 52 {} 45 53 -
branches/network/src/lib/network/synchronizeable.h
r5822 r5829 15 15 16 16 Synchronizeable(const char* name); 17 Synchronizeable(); 17 18 ~Synchronizeable(); 18 19 19 20 virtual void writeBytes(const byte* data, int length); 20 virtual int readBytes(byte* data) const;21 virtual int readBytes(byte* data); 21 22 virtual void writeDebug() const; 22 23 virtual void readDebug() const; -
branches/network/src/orxonox.cc
r5822 r5829 57 57 #include "load_param_description.h" 58 58 59 #include "network_manager.h" 60 59 61 #include <string.h> 60 62 … … 79 81 this->argc = 0; 80 82 this->argv = NULL; 83 84 /* this way, there is no network enabled: */ 85 this->clientName = NULL; 86 this->port = -1; 81 87 82 88 this->configFileName = NULL; … … 118 124 119 125 PRINT(3) 120 121 122 123 124 125 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 ); 127 133 128 134 Orxonox::singletonRef = NULL; … … 137 143 void Orxonox::restart() 138 144 { 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(); 156 162 } 157 163 … … 179 185 * initialize Orxonox with command line 180 186 */ 181 int Orxonox::init (int argc, char** argv )187 int Orxonox::init (int argc, char** argv, const char* name, int port) 182 188 { 183 189 this->argc = argc; 184 190 this->argv = argv; 185 // parse command line 186 // config file 191 192 this->clientName = name; 193 this->port = port; 187 194 188 195 // initialize the Config-file 189 196 this->getConfigFile(); 190 197 191 // initialize everything192 SDL_Init(SDL_INIT_TIMER);193 198 // windows must not write into stdout.txt and stderr.txt 194 199 #ifdef __WIN32__ … … 197 202 #endif 198 203 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 208 222 209 223 /** 210 224 * initializes SDL and OpenGL 211 */225 */ 212 226 int Orxonox::initVideo() 213 227 { … … 226 240 return 0; 227 241 } 242 228 243 229 244 /** … … 262 277 PRINT(3)("> Initializing networking\n"); 263 278 264 printf(" ---Not yet implemented-FIXME--\n"); 279 NetworkManager::getInstance(); 280 281 if( this->clientName != NULL) // we are a client 282 NetworkManager::getInstance()->establishConnection(this->clientName, port); 283 else if( this->port > 0) // we are a server 284 NetworkManager::getInstance()->createServer(port); 285 265 286 return 0; 266 287 } … … 281 302 { 282 303 if (!ResourceManager::getInstance()->setDataDir(dataPath) && 283 304 !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) 284 305 { 285 306 PRINTF(1)("Data Could not be located in %s\n", dataPath); … … 300 321 exit(-1); 301 322 } 302 323 //! @todo this is a hack and should be loadable 303 324 char* imageDir = ResourceManager::getInstance()->getFullName("maps"); 304 325 ResourceManager::getInstance()->addImageDir(imageDir); … … 374 395 int main(int argc, char** argv) 375 396 { 376 // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.377 397 int i; 378 398 for(i = 1; i < argc; ++i) 399 { 400 if( !strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) 401 return showHelp(argc, argv); 402 else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) 403 showGui = true; 404 else if(!strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) 405 return startNetworkOrxonox(argc, argv); 406 else if(!strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) 407 return startNetworkOrxonox(argc, argv); 408 else if(!strcmp( "--license", argv[i]) || !strcmp("-s", argv[i])) 409 return PRINT(0)(ORXONOX_LICENSE_SHORT); 410 } 411 412 return startOrxonox(argc, argv, NULL, -1); 413 } 414 415 416 417 int showHelp(int argc, char** argv) 418 { 419 PRINT(0)("Orxonox Version %s\n", PACKAGE_VERSION); 420 PRINT(0)(" Starts Orxonox - The most furious 3D Action Game :)\n"); 421 PRINT(0)("\n"); 422 PRINT(0)("Common options:\n"); 423 PRINT(0)(" -g, --gui starts the orxonox with the configuration GUI \n"); 424 PRINT(0)(" -h, --help shows this help\n"); 425 PRINT(0)("\n"); 426 PRINT(0)("Network options:\n"); 427 PRINT(0)(" -s, --server [port] starts Orxonox and listens on the [port] for players\n"); 428 PRINT(0)(" -c, --client [hostname] [port] starts Orxonox as a Client\n"); 429 PRINT(0)(" -c, --client [ip address] [port] starts Orxonox as a Client\n"); 430 PRINT(0)("\n"); 431 PRINT(0)("Other options:\n"); 432 PRINT(0)(" --license prints the licence and exit\n\n"); 433 PRINT(0)("\n"); 434 435 // { 436 // Gui* gui = new Gui(argc, argv); 437 // gui->printHelp(); 438 // delete gui; 439 // } 440 } 441 442 443 444 445 /** 446 * starts orxonox in network mode 447 * @param argc parameters count given to orxonox 448 * @param argv parameters given to orxonox 449 */ 450 int startNetworkOrxonox(int argc, char** argv) 451 { 452 453 int i; 454 for(i = 0; i < argc; ++i ) 455 { 456 if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) 379 457 { 380 if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv); 381 // else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks(); 382 else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true; 383 // else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]); 458 if( argc <= (i+2)) 459 { 460 printf(" Wrong arguments try following notations:\n"); 461 printf(" --client [server ip address] [port number]\n"); 462 printf(" --client [dns name] [port number]\n"); 463 return 0; 464 } 465 466 const char* name = argv[i+1]; 467 int port = atoi(argv[i+2]); 468 printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port); 469 470 startOrxonox(argc, argv, name, port); 384 471 } 385 386 return startOrxonox(argc, argv); 387 } 388 389 390 391 int startHelp(int argc, char** argv) 392 { 393 PRINT(0)("orxonox: starts the orxonox game - rules\n"); 394 PRINT(0)("usage: orxonox [arg [arg...]]\n\n"); 395 PRINT(0)("valid options:\n"); 396 { 397 Gui* gui = new Gui(argc, argv); 398 gui->printHelp(); 399 delete gui; 400 } 401 PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n"); 402 PRINT(0)(" -h|--help:\t\t\tshows this help\n"); 472 else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) 473 { 474 if( argc <= (i+1)) 475 { 476 printf(" Wrong arguments try following notations:\n"); 477 printf(" --server [port number]\n"); 478 return 0; 479 } 480 481 int port = atoi(argv[i+1]); 482 printf("Starting Orxonox as server, listening on port %i\n", port); 483 484 startOrxonox(argc, argv, NULL, port); 485 } 486 } 403 487 } 404 488 … … 410 494 * @param argv parameters given to orxonox 411 495 */ 412 int startOrxonox(int argc, char** argv )496 int startOrxonox(int argc, char** argv, const char* name, int port) 413 497 { 414 498 // checking for existence of the configuration-files, or if the lock file is still used 415 499 if (showGui || (!ResourceManager::isFile("./orxonox.conf") && 416 !ResourceManager::isFile(DEFAULT_CONFIG_FILE))500 !ResourceManager::isFile(DEFAULT_CONFIG_FILE)) 417 501 #if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails 418 502 || ResourceManager::isFile(DEFAULT_LOCK_FILE) 419 503 #endif 420 504 ) 421 422 423 424 425 426 427 428 429 430 431 432 433 505 { 506 if (ResourceManager::isFile(DEFAULT_LOCK_FILE)) 507 ResourceManager::deleteFile(DEFAULT_LOCK_FILE); 508 509 // starting the GUI 510 Gui* gui = new Gui(argc, argv); 511 gui->startGui(); 512 513 if (! gui->startOrxonox) 514 return 0; 515 516 delete gui; 517 } 434 518 435 519 PRINT(0)(">>> Starting Orxonox <<<\n"); … … 439 523 Orxonox *orx = Orxonox::getInstance(); 440 524 441 if( orx->init(argc, argv) == -1)442 443 444 445 446 447 525 if( orx->init(argc, argv, name, port) == -1) 526 { 527 PRINTF(1)("! Orxonox initialization failed\n"); 528 return -1; 529 } 530 531 printf("finished inizialisation\n"); 448 532 orx->start(); 449 533 -
branches/network/src/orxonox.h
r5207 r5829 23 23 inline static Orxonox* getInstance() { if (!singletonRef) singletonRef = new Orxonox(); return singletonRef; }; 24 24 25 int init (int argc, char** argv);25 int init(int argc, char** argv, const char* name, int port); 26 26 27 27 void restart(); 28 28 29 29 void start(); 30 31 //void graphicsHandler (SDL_Event* event);32 30 33 31 private: … … 43 41 int initMisc (); 44 42 45 46 43 const char* getConfigFile (); 47 44 … … 55 52 unsigned int argc; //!< Count of Arguments of orxonox 56 53 char** argv; //!< Values of th Arguments of orxonox. 54 55 const char* clientName; //!< Name of the Orxonox client if == NULL -> server 56 int port; //!< number of the network port of the server/client if == -1 no network 57 57 }; 58 58 … … 61 61 // Start-up functions // 62 62 //////////////////////// 63 int startHelp(int argc, char** argv); 64 int startOrxonox(int argc, char** argv); 63 int showHelp(int argc, char** argv); 64 int showLicense(); 65 int startNetworkOrxonox(int argc, char** argv); 66 int startOrxonox(int argc, char** argv, const char* clientName, int port); 65 67 66 68 #endif /* _ORXONOX_H */ -
branches/network/src/story_entities/world.cc
r5819 r5829 73 73 #include "shader.h" 74 74 75 #include "network_manager.h" 76 75 77 SHELL_COMMAND(speed, World, setSpeed); 76 78 SHELL_COMMAND(togglePNodeVisibility, World, togglePNodeVisibility); … … 321 323 localPlayer = (Player*) created; 322 324 CDEngine::getInstance()->setPlayer(localPlayer); 325 NetworkManager::getInstance()->connectSynchronizeable(*(Synchronizeable*)this->localPlayer); 323 326 } 324 327 if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) sky = (SkyBox*) created; … … 827 830 // Get remote input 828 831 // Update synchronizables 832 NetworkManager::getInstance()->synchronize(); 829 833 } 830 834 -
branches/network/src/subprojects/network/Makefile.am
r5822 r5829 15 15 network_SOURCES= network_unit_test.cc \ 16 16 simple_sync.cc \ 17 read_sync.cc \ 18 write_sync.cc \ 17 19 \ 18 20 \ … … 26 28 27 29 noinst_HEADERS = network_unit_test.h \ 28 simple_sync.h 30 simple_sync.h \ 31 read_sync.h \ 32 write_sync.h 29 33 -
branches/network/src/subprojects/network/Makefile.in
r5822 r5829 54 54 PROGRAMS = $(bin_PROGRAMS) 55 55 am_network_OBJECTS = network-network_unit_test.$(OBJEXT) \ 56 network-simple_sync.$(OBJEXT) network-base_object.$(OBJEXT) \ 56 network-simple_sync.$(OBJEXT) network-read_sync.$(OBJEXT) \ 57 network-write_sync.$(OBJEXT) network-base_object.$(OBJEXT) \ 57 58 network-class_list.$(OBJEXT) network-load_param.$(OBJEXT) \ 58 59 network-substring.$(OBJEXT) network-helper_functions.$(OBJEXT) … … 193 194 network_SOURCES = network_unit_test.cc \ 194 195 simple_sync.cc \ 196 read_sync.cc \ 197 write_sync.cc \ 195 198 \ 196 199 \ … … 202 205 203 206 noinst_HEADERS = network_unit_test.h \ 204 simple_sync.h 207 simple_sync.h \ 208 read_sync.h \ 209 write_sync.h 205 210 206 211 all: all-am … … 275 280 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-load_param.Po@am__quote@ 276 281 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-network_unit_test.Po@am__quote@ 282 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-read_sync.Po@am__quote@ 277 283 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-simple_sync.Po@am__quote@ 278 284 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-substring.Po@am__quote@ 285 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network-write_sync.Po@am__quote@ 279 286 280 287 .cc.o: … … 319 326 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 320 327 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o network-simple_sync.obj `if test -f 'simple_sync.cc'; then $(CYGPATH_W) 'simple_sync.cc'; else $(CYGPATH_W) '$(srcdir)/simple_sync.cc'; fi` 328 329 network-read_sync.o: read_sync.cc 330 @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT network-read_sync.o -MD -MP -MF "$(DEPDIR)/network-read_sync.Tpo" -c -o network-read_sync.o `test -f 'read_sync.cc' || echo '$(srcdir)/'`read_sync.cc; \ 331 @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/network-read_sync.Tpo" "$(DEPDIR)/network-read_sync.Po"; else rm -f "$(DEPDIR)/network-read_sync.Tpo"; exit 1; fi 332 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='read_sync.cc' object='network-read_sync.o' libtool=no @AMDEPBACKSLASH@ 333 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 334 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o network-read_sync.o `test -f 'read_sync.cc' || echo '$(srcdir)/'`read_sync.cc 335 336 network-read_sync.obj: read_sync.cc 337 @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT network-read_sync.obj -MD -MP -MF "$(DEPDIR)/network-read_sync.Tpo" -c -o network-read_sync.obj `if test -f 'read_sync.cc'; then $(CYGPATH_W) 'read_sync.cc'; else $(CYGPATH_W) '$(srcdir)/read_sync.cc'; fi`; \ 338 @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/network-read_sync.Tpo" "$(DEPDIR)/network-read_sync.Po"; else rm -f "$(DEPDIR)/network-read_sync.Tpo"; exit 1; fi 339 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='read_sync.cc' object='network-read_sync.obj' libtool=no @AMDEPBACKSLASH@ 340 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 341 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o network-read_sync.obj `if test -f 'read_sync.cc'; then $(CYGPATH_W) 'read_sync.cc'; else $(CYGPATH_W) '$(srcdir)/read_sync.cc'; fi` 342 343 network-write_sync.o: write_sync.cc 344 @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT network-write_sync.o -MD -MP -MF "$(DEPDIR)/network-write_sync.Tpo" -c -o network-write_sync.o `test -f 'write_sync.cc' || echo '$(srcdir)/'`write_sync.cc; \ 345 @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/network-write_sync.Tpo" "$(DEPDIR)/network-write_sync.Po"; else rm -f "$(DEPDIR)/network-write_sync.Tpo"; exit 1; fi 346 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='write_sync.cc' object='network-write_sync.o' libtool=no @AMDEPBACKSLASH@ 347 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 348 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o network-write_sync.o `test -f 'write_sync.cc' || echo '$(srcdir)/'`write_sync.cc 349 350 network-write_sync.obj: write_sync.cc 351 @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT network-write_sync.obj -MD -MP -MF "$(DEPDIR)/network-write_sync.Tpo" -c -o network-write_sync.obj `if test -f 'write_sync.cc'; then $(CYGPATH_W) 'write_sync.cc'; else $(CYGPATH_W) '$(srcdir)/write_sync.cc'; fi`; \ 352 @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/network-write_sync.Tpo" "$(DEPDIR)/network-write_sync.Po"; else rm -f "$(DEPDIR)/network-write_sync.Tpo"; exit 1; fi 353 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='write_sync.cc' object='network-write_sync.obj' libtool=no @AMDEPBACKSLASH@ 354 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 355 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(network_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o network-write_sync.obj `if test -f 'write_sync.cc'; then $(CYGPATH_W) 'write_sync.cc'; else $(CYGPATH_W) '$(srcdir)/write_sync.cc'; fi` 321 356 322 357 network-base_object.o: $(MAINSRCDIR)/lib/lang/base_object.cc -
branches/network/src/subprojects/network/network_unit_test.cc
r5822 r5829 12 12 13 13 #include "simple_sync.h" 14 #include "read_sync.h" 14 15 15 16 int verbose = 4; … … 25 26 printf(" --server [port number] creates a test server\n"); 26 27 printf(" --client [address] [port] connects to a server\n"); 28 printf(" --listen [address] [port] just listens to this connection"); 27 29 printf("\n"); 28 30 } … … 76 78 77 79 #define _N_ELEMENTS 212994 80 78 81 char sendbuf[_N_ELEMENTS+1]; 79 82 char recvbuf[_N_ELEMENTS+1]; … … 131 134 132 135 /* create the network manager */ 133 NetworkManager* nm = new NetworkManager();136 NetworkManager* nm = NetworkManager::getInstance(); 134 137 135 138 /* initialize the network manager */ … … 143 146 int error = SDLNet_ResolveHost(&ip, "127.0.0.1", port); 144 147 //SDLNet_ResolveHost(&ip, "localhost", port); 145 if(error == -1) printf("\n\nerror on address resolution, program inconsistancy\n\n"); 148 if(error == -1) 149 printf("\n\nerror on address resolution, program inconsistancy\n\n"); 146 150 nm->establishConnection(ip, *clientSync); 147 151 /* adding some break for connection setup */ … … 149 153 150 154 /* synchronize the data 1 time (increment for longer tests) */ 151 for( int i = 0; i < 3; i++) { 155 for( int i = 0; i < 3; i++) 156 { 152 157 nm->synchronize(); 153 158 /* simulate the network delay */ … … 177 182 int startServer(int argc, char** argv) 178 183 { 179 if( argc <= 2) { 184 if( argc <= 2) 185 { 180 186 printf(" Wrong arguments try following notations:\n"); 181 187 printf(" --server [port number]\n"); … … 186 192 printf("Starting Server on port %i\n", port); 187 193 188 NetworkManager* netMan = new NetworkManager();194 NetworkManager* netMan = NetworkManager::getInstance(); 189 195 Synchronizeable* ss = new SimpleSync("Server\0"); 190 196 191 //NetworkStream* server = new NetworkStream(port, ss, NET_SERVER);192 197 netMan->createServer(*ss, port); 193 198 SDL_Delay(20); 194 199 195 for(;;) { 200 for(;;) 201 { 196 202 netMan->synchronize(); 197 203 SDL_Delay(500); 198 204 } 205 206 delete netMan; 207 delete ss; 208 209 199 210 return 0; 200 211 } … … 203 214 int startClient(int argc, char** argv) 204 215 { 205 if( argc < 3) { 216 if( argc < 3) 217 { 206 218 printf(" Wrong arguments try following notations:\n"); 207 219 printf(" --client [server ip] [port number]\n"); 208 printf(" -- server[server name] [port number]\n");220 printf(" --client [server name] [port number]\n"); 209 221 return 0; 210 222 } … … 216 228 IPaddress ip; 217 229 int error = SDLNet_ResolveHost(&ip, name, port); 218 //SDLNet_ResolveHost(&ip, "localhost", port);219 if(error == -1)printf("\n\nerror on address resolution, program inconsistancy\n\n");220 221 NetworkManager* netMan = new NetworkManager();230 if(error == -1) 231 printf("\n\nerror on address resolution, program inconsistancy\n\n"); 232 233 NetworkManager* netMan = NetworkManager::getInstance(); 222 234 Synchronizeable* ss = new SimpleSync("Client\0"); 223 235 224 236 netMan->establishConnection(ip, *ss); 225 237 226 for(;;) { 238 for(;;) 239 { 227 240 netMan->synchronize(); 228 241 SDL_Delay(500); 229 242 } 230 243 231 //NetworkStream* client = new NetworkStream(ip, ss, NET_CLIENT); 244 245 delete netMan; 246 delete ss; 247 248 return 0; 249 } 250 251 252 253 int startListen(int argc, char** argv) 254 { 255 if( argc < 3) 256 { 257 printf(" Wrong arguments try following notations:\n"); 258 printf(" --listen [server ip] [port number]\n"); 259 printf(" --listen [server name] [port number]\n"); 260 return 0; 261 } 262 263 char* name = argv[2]; 264 int port = atoi(argv[3]); 265 printf("Connecting to %s, on port %i\n", name, port); 266 267 IPaddress ip; 268 int error = SDLNet_ResolveHost(&ip, name, port); 269 if(error == -1) 270 printf("\n\nerror on address resolution, program inconsistancy\n\n"); 271 272 NetworkManager* netMan = NetworkManager::getInstance(); 273 Synchronizeable* ss = new ReadSync("WriteSync\0"); 274 275 netMan->establishConnection(ip, *ss); 276 277 for(;;) 278 { 279 netMan->synchronize(); 280 SDL_Delay(10); 281 } 232 282 233 283 … … 253 303 { 254 304 //else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true; 255 if (! strcmp( "--sockettest", argv[i]) || !strcmp("-st", argv[i])) return testSocket(argc, argv); 256 else if (! strcmp( "--frameworktest", argv[i]) || !strcmp("-ft", argv[i])) return testFramework(argc, argv); 257 else if (! strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) return startServer(argc, argv); 258 else if (! strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) return startClient(argc, argv); 305 if (! strcmp( "--sockettest", argv[i]) || !strcmp("-st", argv[i])) 306 return testSocket(argc, argv); 307 else if (! strcmp( "--frameworktest", argv[i]) || !strcmp("-ft", argv[i])) 308 return testFramework(argc, argv); 309 else if (! strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) 310 return startServer(argc, argv); 311 else if (! strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) 312 return startClient(argc, argv); 313 else if (! strcmp( "--listen", argv[i]) || !strcmp("-l", argv[i])) 314 return startListen(argc, argv); 259 315 } 260 316 -
branches/network/src/subprojects/network/simple_sync.cc
r5822 r5829 86 86 * read data from Synchronizeable 87 87 */ 88 int SimpleSync::readBytes(byte* data) const88 int SimpleSync::readBytes(byte* data) 89 89 { 90 90 PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength); -
branches/network/src/subprojects/network/simple_sync.h
r5822 r5829 17 17 18 18 virtual void writeBytes(const byte* data, int length); 19 virtual int readBytes(byte* data) const;19 virtual int readBytes(byte* data); 20 20 21 21 -
branches/network/src/world_entities/player.cc
r5767 r5829 39 39 40 40 CREATE_FACTORY(Player, CL_PLAYER); 41 42 43 44 #define UP 0 45 #define DOWN 1 46 #define RIGHT 2 47 #define LEFT 3 48 #define TIME 4 49 41 50 42 51 /** … … 107 116 */ 108 117 delete this->weaponMan; 118 if( this->outData) 119 delete[] this->outData; 120 if( this->inData) 121 delete[] this->inData; 109 122 } 110 123 … … 160 173 // this->weaponMan->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: 161 174 175 this->outBufferLength = 100; 176 this->outLength = 0; 177 this->recLength = 0; 178 this->inBufferLength = 100; 179 this->inLength = 0; 180 this->sentLength = 0; 181 this->outData = new byte[this->outBufferLength]; 182 this->inData = new byte[this->inBufferLength]; 162 183 } 163 184 … … 282 303 //orthDirection = orthDirection.cross (direction); 283 304 305 306 if( this->outLength >= this->outBufferLength) return; 307 308 if( this->bUp || this->bDown || this->bRight || this->bLeft) 309 { 310 this->outData[this->outLength++] = TIME; 311 this->outData[this->outLength++] = (byte)(lround(time * 100.0f)); 312 313 PRINTF(0)("Writing TIME = %i, or %f\n", this->outData[this->outLength-1], time); 314 } 315 284 316 if( this->bUp && this->getRelCoor().x < 20) 317 { 285 318 accel += direction; 319 this->outData[this->outLength++] = UP; 320 } 286 321 if( this->bDown && this->getRelCoor().x > -5) 322 { 287 323 accel -= direction; 288 324 this->outData[this->outLength++] = DOWN; 325 } 289 326 if( this->bLeft && TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2) 290 327 { … … 292 329 rot +=Vector(1,0,0); 293 330 rotVal -= .4; 331 this->outData[this->outLength++] = LEFT; 294 332 } 295 333 if( this->bRight && TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2) … … 298 336 rot += Vector(1,0,0); 299 337 rotVal += .4; 338 this->outData[this->outLength++] = RIGHT; 300 339 } 301 340 if (this->bAscend ) … … 311 350 rotVal -= .4; 312 351 } 352 313 353 314 354 Vector move = accel * time *acceleration; … … 322 362 this->setRelDirSoft(Quaternion(rotVal, rot), 5); 323 363 this->shiftCoor (move); 364 365 324 366 } 325 367 … … 394 436 } 395 437 } 438 439 440 441 442 /** 443 * write data to Synchronizeable 444 */ 445 void Player::writeBytes(const byte* data, int length) 446 { 447 PRINTF(0)("Player: got %i bytes of data\n", length); 448 this->inLength = length; 449 450 /* 451 bytes: | 0 | 1 | 452 CODE DIST 453 454 455 CODE: 456 0 : Up 457 1 : Down 458 2 : Right 459 3 : Left 460 4 : TIME 461 462 DIST: 463 Coordinate diff multiplied by 100 and casted to a byte: byte a = (byte)(x * 100) 464 465 */ 466 467 float time = 0.0f; 468 469 Vector accel(0.0, 0.0, 0.0); 470 Vector direction (1.0, 0.0, 0.0); 471 Vector orthDirection (0.0, 0.0, 1.0); 472 473 byte code = 0; 474 475 /* iterate through all bytes */ 476 for( int i = 0; i < length; i++) 477 { 478 code = data[i]; 479 480 /* is it a time code? */ 481 if( code == TIME) 482 { 483 /* is it the first time */ 484 if( time > 0.0f ) 485 { 486 /* apply movement */ 487 Vector move = accel * time; 488 489 if (accel.z < 0) 490 this->setRelDirSoft(Quaternion(-.4, Vector(1,0,0)), 5); 491 else if (accel.z > 0) 492 this->setRelDirSoft(Quaternion(.4, Vector(1,0,0)), 5); 493 else 494 this->setRelDirSoft(Quaternion(0, Vector(1,0,0)), 5); 495 this->shiftCoor (move); 496 } 497 /* read out new movement */ 498 time = (float)(data[++i] / 100.0f); 499 PRINTF(0)("Got time: %f msec\n", time); 500 } 501 else if( code == UP && this->getRelCoor().x < 20) 502 accel = accel+(direction*acceleration); 503 else if( code == DOWN && this->getRelCoor().x > -5) 504 accel = accel -(direction*acceleration); 505 else if( code == LEFT && TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2) 506 accel = accel - (orthDirection*acceleration); 507 else if( code == RIGHT && TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2) 508 accel = accel + (orthDirection*acceleration); 509 } 510 511 512 513 514 /* and debug output */ 515 this->writeDebug(); 516 } 517 518 519 /** 520 * read data from Synchronizeable 521 */ 522 int Player::readBytes(byte* data) 523 { 524 PRINTF(0)("Player: sent %i bytes of data\n", this->sentLength); 525 526 /* copy data */ 527 for( int i = 0; i < this->outLength; ++i) 528 data[i] = this->outData[i]; 529 530 531 532 /* debug msg */ 533 this->readDebug(); 534 535 int length = this->outLength; 536 this->outLength = 0; 537 /* return the length of the test */ 538 return length; 539 } 540 541 542 void Player::writeDebug() const 543 { 544 545 } 546 547 548 void Player::readDebug() const 549 { 550 551 } 552 -
branches/network/src/world_entities/player.h
r5500 r5829 11 11 #include "event_listener.h" 12 12 13 template<class T> class tList; 13 template<class T> 14 class tList; 14 15 class Weapon; 15 16 class WeaponManager; … … 25 26 class Player : public WorldEntity, public EventListener 26 27 { 27 friend class World;28 friend class World; 28 29 29 30 public: … … 39 40 void removeWeapon(Weapon* weapon); 40 41 42 /* WorldEntity functions */ 41 43 virtual void postSpawn(); 42 44 virtual void leftWorld(); … … 48 50 virtual void process(const Event &event); 49 51 52 /* Synchronizeable functions */ 53 virtual void writeBytes(const byte* data, int length); 54 virtual int readBytes(byte* data); 50 55 51 56 private: 52 57 void move(float time); 53 58 void weaponAction(); 59 60 /* Synchronizeable functions */ 61 virtual void writeDebug() const; 62 virtual void readDebug() const; 54 63 55 64 // !! temporary !! … … 70 79 float travelSpeed; //!< the current speed of the player (to make soft movement) 71 80 float acceleration; //!< the acceleration of the player. 81 82 byte* inData; 83 int inLength; 84 int inBufferLength; 85 int recLength; 86 byte* outData; 87 int outLength; 88 int outBufferLength; 89 int sentLength; 90 72 91 }; 73 92 -
branches/network/src/world_entities/world_entity.cc
r5708 r5829 41 41 */ 42 42 WorldEntity::WorldEntity(const TiXmlElement* root) 43 : Synchronizeable() 43 44 { 44 45 this->setClassID(CL_WORLD_ENTITY, "WorldEntity"); -
branches/network/src/world_entities/world_entity.h
r5511 r5829 8 8 9 9 #include "p_node.h" 10 #include "synchronizeable.h" 11 #include "model.h" 10 12 11 13 #include "glincl.h" … … 21 23 22 24 //! Basis-class all interactive stuff in the world is derived from 23 class WorldEntity : public PNode 25 class WorldEntity : public PNode, public Synchronizeable 24 26 { 25 27 public:
Note: See TracChangeset
for help on using the changeset viewer.