Changeset 1699
- Timestamp:
- Sep 4, 2008, 9:47:34 AM (16 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 1 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/CMakeLists.txt
r1666 r1699 38 38 ##### test for gamestate stuff ##### 39 39 SET( TEST_SRC_FILES 40 ConnectionManager.cc 41 GameStateManager.cc 42 PacketBuffer.cc 43 PacketDecoder.cc 44 PacketGenerator.cc 45 ClientConnection.cc 46 ClientInformation.cc 47 diffTest.cc 48 GameStateClient.cc 49 Server.cc 50 Client.cc 51 Synchronisable.cc 40 ${NETWORK_SRC_FILES} 52 41 ) 53 54 42 ADD_EXECUTABLE(networktest ${TEST_SRC_FILES}) 55 43 TARGET_LINK_LIBRARIES( networktest … … 62 50 ##### end test for gamestate stuff ##### 63 51 ENDIF(NETWORK_TESTING_ENABLED) 64 # build this if you want dummyserver4 and dummyclient465 IF(NETWORKTRAFFIC_TESTING_ENABLED)66 ##### test network traffic #####67 SET( DUMMYSERVER4_SRC_FILES68 ConnectionManager.cc69 GameStateManager.cc70 PacketBuffer.cc71 PacketDecoder.cc72 PacketGenerator.cc73 ClientConnection.cc74 ClientInformation.cc75 GameStateClient.cc76 Server.cc77 Client.cc78 Synchronisable.cc79 dummyserver4.cc80 )81 82 SET( DUMMYCLIENT4_SRC_FILES83 ConnectionManager.cc84 GameStateManager.cc85 PacketBuffer.cc86 PacketDecoder.cc87 PacketGenerator.cc88 ClientConnection.cc89 ClientInformation.cc90 GameStateClient.cc91 Server.cc92 Client.cc93 Synchronisable.cc94 dummyclient4.cc95 )96 97 ADD_EXECUTABLE(dummyserver4 ${DUMMYSERVER4_SRC_FILES})98 TARGET_LINK_LIBRARIES( dummyserver499 network100 ${ENet_LIBRARY}101 ${ZLIB_LIBRARY}102 ${WINDOWS_ENET_DEPENDENCIES}103 ${Boost_thread_LIBRARIES}104 core105 orxonoxs106 audio107 )108 109 ADD_EXECUTABLE(dummyclient4 ${DUMMYCLIENT4_SRC_FILES})110 TARGET_LINK_LIBRARIES( dummyclient4111 network112 ${ENet_LIBRARY}113 ${ZLIB_LIBRARY}114 ${WINDOWS_ENET_DEPENDENCIES}115 ${Boost_thread_LIBRARIES}116 core117 orxonoxs118 audio119 )120 ENDIF(NETWORKTRAFFIC_TESTING_ENABLED)121 122 IF(BLABLA)123 SET( CHATCLIENT_SRC_FILES124 ClientConnection.cc125 Client.cc126 PacketBuffer.cc127 PacketDecoder.cc128 PacketGenerator.cc129 dummyclient3.cc130 )131 132 SET( CHATSERVER_SRC_FILES133 ConnectionManager.cc134 GameStateManager.cc135 PacketBuffer.cc136 PacketDecoder.cc137 PacketGenerator.cc138 dummyserver3.cc139 )140 141 # chatserver for testing purposes142 ADD_EXECUTABLE(chatserver ${CHATSERVER_SRC_FILES})143 TARGET_LINK_LIBRARIES( chatserver144 ${OGRE_LIBRARIES}145 network146 core147 #objects148 ${ENet_LIBRARY}149 ${ZLIB_LIBRARY}150 ${WINDOWS_ENET_DEPENDENCIES}151 )152 153 # chatclient for testing purpose154 ADD_EXECUTABLE(chatclient ${CHATCLIENT_SRC_FILES})155 TARGET_LINK_LIBRARIES( chatclient156 ${OGRE_LIBRARIES}157 network158 core159 #objects160 ${ENet_LIBRARY}161 ${ZLIB_LIBRARY}162 ${WINDOWS_ENET_DEPENDENCIES}163 )164 165 # client for testing purpose166 ADD_EXECUTABLE(client dummyclient2.cc)167 TARGET_LINK_LIBRARIES( client168 ${OGRE_LIBRARIES}169 network170 core171 #objects172 ${ENet_LIBRARY}173 ${ZLIB_LIBRARY}174 ${WINDOWS_ENET_DEPENDENCIES}175 )176 177 # server for testing purpose178 ADD_EXECUTABLE(server dummyserver.cc)179 TARGET_LINK_LIBRARIES( server180 ${OGRE_LIBRARIES}181 network182 core183 #objects184 ${ENet_LIBRARY}185 ${ZLIB_LIBRARY}186 ${WINDOWS_ENET_DEPENDENCIES}187 )188 ENDIF(BLABLA)189 -
code/branches/network/src/network/Client.cc
r1666 r1699 207 207 return; 208 208 } 209 210 bool Client::ackGamestateID(int gamestateID, int clientID){ 211 return true; 212 //TODO: maybe change this (not needed at the moment) 213 } 209 214 210 215 // void Client::processChat( chat *data, int clientId){ -
code/branches/network/src/network/Client.h
r1666 r1699 79 79 // static void Chat( std::string message ); 80 80 81 int shipID(){return shipID_;}81 unsigned int shipID(){return shipID_;} 82 82 int playerID(){return clientID_;} 83 83 … … 97 97 void processGamestate( GameStateCompressed *data, int clientID); 98 98 void processClassid(classid *clid); 99 bool ackGamestateID(int gamestateID, int clientID); 99 100 // void processChat( chat *data, int clientId ); 100 101 bool processWelcome( welcome *w ); -
code/branches/network/src/network/ClientInformation.h
r1666 r1699 72 72 bool setGameStateID(int id); 73 73 bool setPartialGamestateID(int id); 74 inline void setShipID( int id){ShipID_=id;}74 inline void setShipID(unsigned int id){ShipID_=id;} 75 75 76 76 // get functions 77 inline int getShipID(){return ShipID_;}77 inline unsigned int getShipID(){return ShipID_;} 78 78 int getID(); 79 79 int getGamestateID(); … … 112 112 int gamestateID_; 113 113 int partialGamestateID_; 114 int ShipID_; // this is the unique objectID114 unsigned int ShipID_; // this is the unique objectID 115 115 bool synched_; 116 116 unsigned short failures_; -
code/branches/network/src/network/ConnectionManager.cc
r1666 r1699 360 360 361 361 bool ConnectionManager::removeShip(ClientInformation *client){ 362 int id=client->getShipID();362 unsigned int id=client->getShipID(); 363 363 orxonox::Iterator<orxonox::SpaceShip> it; 364 364 for(it = orxonox::ObjectList<orxonox::SpaceShip>::start(); it; ++it){ -
code/branches/network/src/network/GameStateClient.cc
r1534 r1699 34 34 #include "core/BaseObject.h" 35 35 #include "Synchronisable.h" 36 36 #include "packet/Gamestate.h" 37 37 38 38 namespace network … … 125 125 if(b) 126 126 loadShipCache(); 127 packet::Gamestate *g = new packet::Gamestate(); 128 if(!g->collectData(1, 0x1)) 129 COUT(3) << "problem testing data collecting" << std::endl; 130 else 131 { 132 if(!g->spreadData(0x1)) 133 COUT(3) << "problem testing data spreading" << std::endl; 134 delete g; 135 } 127 136 return id; 128 137 } -
code/branches/network/src/network/Host.cc
r1675 r1699 31 31 if(!instance_) 32 32 return false; 33 packet::Chat *c = new packet::Chat(message );33 packet::Chat *c = new packet::Chat(message, getPlayerID()); 34 34 return instance_->sendChat(c); 35 35 } … … 48 48 } 49 49 50 int Host::getShipID(){50 unsigned int Host::getShipID(){ 51 51 if(!instance_) 52 52 return 0; … … 54 54 } 55 55 56 bool Host::ackGamestate(int gamestateID, int clientID){ 57 return instance_->ackGamestateID(gamestateID, clientID); 58 } 59 56 60 }//namespace network -
code/branches/network/src/network/Host.h
r1675 r1699 44 44 virtual bool sendChat(packet::Chat *chat)=0; 45 45 virtual bool queuePacket(ENetPacket *packet, int clientID)=0; 46 virtual int shipID()=0; 46 virtual bool ackGamestateID(int gamestateID, int clientID)=0; 47 virtual unsigned int shipID()=0; 47 48 virtual int playerID()=0; 48 49 … … 60 61 static bool receiveChat(packet::Chat *message, unsigned int clientID); 61 62 static int getPlayerID(); 62 static int getShipID(); 63 static unsigned int getShipID(); 64 static bool ackGamestate(int gamestateID, int clientID); 63 65 }; 64 66 -
code/branches/network/src/network/Server.cc
r1666 r1699 302 302 } 303 303 304 bool Server::ackGamestateID(int gamestateID, int clientID){ 305 gamestates->ackGameState(clientID, gamestateID); 306 return true; 307 } 308 304 309 void Server::processGamestate( GameStateCompressed *data, int clientID){ 305 310 COUT(4) << "processing partial gamestate from client " << clientID << std::endl; -
code/branches/network/src/network/Server.h
r1666 r1699 76 76 void updateGamestate(); 77 77 private: 78 int shipID(){return 0;}78 unsigned int shipID(){return 0;} 79 79 int playerID(){return 0;} 80 80 … … 89 89 bool processConnectRequest( connectRequest *con, int clientID ); 90 90 void processGamestate( GameStateCompressed *data, int clientID); 91 92 bool ackGamestateID(int gamestateID, int clientID); 93 91 94 //void processChat( chat *data, int clientId); 92 95 ConnectionManager *connection; -
code/branches/network/src/network/Synchronisable.cc
r1534 r1699 43 43 #include <string> 44 44 #include <iostream> 45 #include <assert.h> 45 46 46 47 #include "core/CoreIncludes.h" 48 #include "core/BaseObject.h" 47 49 // #include "core/Identifier.h" 48 50 … … 84 86 else // server 85 87 state_=0x1; 88 } 89 90 bool Synchronisable::fabricate(unsigned char*& mem, int mode) 91 { 92 int size, objectID, classID; 93 size = *(int *)mem; 94 objectID = *(int*)(mem+sizeof(int)); 95 classID = *(int*)(mem+2*sizeof(int)); 96 97 orxonox::Identifier* id = ID((unsigned int)classID); 98 if(!id){ 99 COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl; 100 return false; // most probably the gamestate is corrupted 101 } 102 Synchronisable *no = dynamic_cast<Synchronisable *>(id->fabricate()); 103 if(!no){ 104 COUT(2) << "coudl not frabricate classid: " << classID << " objectID: " << objectID << " identifier: " << id << std::endl; 105 return false; 106 } 107 no->objectID=objectID; 108 no->classID=classID; 109 // update data and create object/entity... 110 if( !no->updateData(mem, mode) ){ 111 COUT(1) << "We couldn't update the object: " << objectID << std::endl; 112 return false; 113 } 114 if( !no->create() ) 115 { 116 COUT(1) << "We couldn't manifest (create() ) the object: " << objectID << std::endl; 117 return false; 118 } 119 return true; 86 120 } 87 121 … … 108 142 } 109 143 110 /** 111 * note: only use this function for debug use, because it's inefficient (in order to produce a gamestate, you have to copy the whole data again to another memory location after this process) 112 * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct 113 * structure of the bitstream: 114 * (var1_size,var1,var2_size,var2,...) 115 * varx_size: size = sizeof(int) 116 * varx: size = varx_size 117 * @return data containing all variables and their sizes 118 */ 119 // syncData Synchronisable::getData(){ 120 // std::list<synchronisableVariable>::iterator i; 121 // int totalsize=0; 122 // //figure out size of data to be allocated 123 // for(i=syncList->begin(); i!=syncList->end(); i++){ 124 // // increase size (size of variable and size of size of variable ;) 125 // if(i->type == STRING) 126 // totalsize+=sizeof(int)+((std::string *)i->var)->length()+1; 127 // else 128 // totalsize+=sizeof(int)+i->size; 129 // } 130 // syncData retVal; 131 // retVal.objectID=this->objectID; 132 // retVal.classID=this->classID; 133 // retVal.length=totalsize; 134 // // allocate memory 135 // retVal.data = (unsigned char *)malloc(totalsize); 136 // // copy to location 137 // //CHANGED: REMOVED DECLARATION int n=0 FROM LOOP 138 // int n=0; 139 // for(i=syncList->begin(); n<totalsize && i!=syncList->end(); i++){ 140 // std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int)); 141 // n+=sizeof(int); 142 // switch(i->type){ 143 // case STRING: 144 // std::memcpy(retVal.data+n, (const void *)(((std::string *)i->var)->c_str()), ((std::string *)i->var)->length()+1); 145 // n+=((std::string *)i->var)->length()+1; 146 // break; 147 // case DATA: 148 // std::memcpy(retVal.data+n, ((const void*)i->var), i->size); 149 // n+=i->size; 150 // break; 151 // } 152 // } 153 // return retVal; 154 // } 144 155 145 /** 156 146 * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct … … 202 192 return retVal; 203 193 } 204 194 195 /** 196 * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct 197 * Difference to the above function: 198 * takes a pointer to already allocated memory (must have at least getSize bytes length) 199 * structure of the bitstream: 200 * (var1_size,var1,var2_size,var2,...) 201 * varx_size: size = sizeof(int) 202 * varx: size = varx_size 203 * @return data containing all variables and their sizes 204 */ 205 bool Synchronisable::getData2(unsigned char*& mem, int mode){ 206 //std::cout << "inside getData" << std::endl; 207 unsigned int tempsize = 0; 208 if(mode==0x0) 209 mode=state_; 210 if(classID==0) 211 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; 212 this->classID=this->getIdentifier()->getNetworkID(); 213 std::list<synchronisableVariable *>::iterator i; 214 unsigned int size; 215 size=getSize2(mode); 216 217 // start copy header 218 memcpy(mem, &size, sizeof(unsigned int)); 219 mem+=sizeof(unsigned int); 220 memcpy(mem, &(this->objectID), sizeof(unsigned int)); 221 mem+=sizeof(unsigned int); 222 memcpy(mem, &(this->classID), sizeof(unsigned int)); 223 mem+=sizeof(unsigned int); 224 tempsize+=12; 225 // end copy header 226 227 228 COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl; 229 // copy to location 230 for(i=syncList->begin(); i!=syncList->end(); ++i){ 231 //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int)); 232 if( ((*i)->mode & mode) == 0 ){ 233 COUT(5) << "not getting data: " << std::endl; 234 continue; // this variable should only be received 235 } 236 switch((*i)->type){ 237 case DATA: 238 memcpy( (void *)(mem), (void*)((*i)->var), (*i)->size); 239 mem+=(*i)->size; 240 tempsize+=(*i)->size; 241 break; 242 case STRING: 243 memcpy( (void *)(mem), (void *)&((*i)->size), sizeof(int) ); 244 mem+=sizeof(int); 245 const char *data = ( ( *(std::string *) (*i)->var).c_str()); 246 memcpy( mem, (void*)data, (*i)->size); 247 COUT(5) << "synchronisable: char: " << (const char *)(mem) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl; 248 mem+=(*i)->size; 249 tempsize+=(*i)->size + 4; 250 break; 251 } 252 } 253 assert(tempsize==size); 254 return true; 255 } 256 257 /*bool Synchronisable::getData(Bytestream& bs, int mode) 258 { 259 //std::cout << "inside getData" << std::endl; 260 if(mode==0x0) 261 mode=state_; 262 if(classID==0) 263 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; 264 this->classID=this->getIdentifier()->getNetworkID(); 265 std::list<synchronisableVariable *>::iterator i; 266 bs << this->getSize(); 267 bs << this->objectID; 268 bs << this->classID; 269 // copy to location 270 for(i=syncList->begin(); i!=syncList->end(); ++i){ 271 if( ((*i)->mode & mode) == 0 ){ 272 COUT(5) << "not getting data: " << std::endl; 273 continue; // this variable should only be received 274 } 275 switch((*i)->type){ 276 case DATA: 277 bs << *(*i)->var; 278 //std::memcpy( (void *)(retVal.data+n), (void*)((*i)->var), (*i)->size); 279 //n+=(*i)->size; 280 break; 281 case STRING: 282 bs << *(String *)((*i)->var); 283 //memcpy( (void *)(retVal.data+n), (void *)&((*i)->size), sizeof(int) ); 284 //n+=sizeof(int); 285 //const char *data = ( ( *(std::string *) (*i)->var).c_str()); 286 //std::memcpy( retVal.data+n, (void*)data, (*i)->size); 287 //COUT(5) << "synchronisable: char: " << (const char *)(retVal.data+n) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl; 288 //n+=(*i)->size; 289 break; 290 } 291 } 292 return true; 293 }*/ 294 295 205 296 /** 206 297 * This function takes a syncData struct and takes it to update the variables … … 246 337 } 247 338 // call the callback function, if defined 248 if(callback) 339 if(callback && (*i)->callback) 340 (*i)->callback->call(); 341 } 342 return true; 343 } 344 345 /** 346 * This function takes a syncData struct and takes it to update the variables 347 * @param vars data of the variables 348 * @return true/false 349 */ 350 bool Synchronisable::updateData(unsigned char*& mem, int mode){ 351 unsigned char *data = mem; 352 if(mode==0x0) 353 mode=state_; 354 std::list<synchronisableVariable *>::iterator i; 355 if(syncList->empty()){ 356 COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl; 357 return false; 358 } 359 360 // start extract header 361 unsigned int objectID, classID, size; 362 size = *(int *)mem; 363 mem+=sizeof(size); 364 objectID = *(int *)mem; 365 mem+=sizeof(objectID); 366 classID = *(int *)mem; 367 mem+=sizeof(classID); 368 // stop extract header 369 assert(this->objectID==objectID); 370 assert(this->classID==classID); 371 372 COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " size: " << size << " synchronising data" << std::endl; 373 for(i=syncList->begin(); i!=syncList->end() && mem <= data+size; i++){ 374 if( ((*i)->mode ^ mode) == 0 ){ 375 COUT(5) << "synchronisable: not updating variable " << std::endl; 376 continue; // this variable should only be set 377 } 378 COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl; 379 bool callback=false; 380 switch((*i)->type){ 381 case DATA: 382 if((*i)->callback) // check whether this variable changed (but only if callback was set) 383 if(strncmp((char *)(*i)->var, (char *)mem, (*i)->size)!=0) 384 callback=true; 385 memcpy((void*)(*i)->var, mem, (*i)->size); 386 mem+=(*i)->size; 387 break; 388 case STRING: 389 (*i)->size = *(int *)mem; 390 COUT(5) << "string size: " << (*i)->size << std::endl; 391 mem+=sizeof(int); 392 if((*i)->callback) // check whether this string changed 393 if( *(std::string *)((*i)->var) != std::string((char *)mem) ) 394 callback=true; 395 *((std::string *)((*i)->var)) = std::string((const char*)mem); 396 COUT(5) << "synchronisable: char: " << (const char*)mem << " string: " << std::string((const char*)mem) << std::endl; 397 mem += (*i)->size; 398 break; 399 } 400 // call the callback function, if defined 401 if(callback && (*i)->callback) 249 402 (*i)->callback->call(); 250 403 } … … 279 432 } 280 433 434 /** 435 * This function returns the total amount of bytes needed by getData to save the whole content of the variables 436 * @return amount of bytes 437 */ 438 int Synchronisable::getSize2(int mode){ 439 return 3*sizeof(unsigned int) + getSize( mode ); 440 } 441 442 bool Synchronisable::isMyData(unsigned char* mem) 443 { 444 unsigned int objectID, classID, size; 445 size = *(int *)mem; 446 mem+=sizeof(size); 447 objectID = *(int *)mem; 448 mem+=sizeof(objectID); 449 classID = *(int *)mem; 450 mem+=sizeof(classID); 451 452 assert(classID == this->classID); 453 return (objectID == this->objectID); 454 } 455 281 456 void Synchronisable::setBacksync(bool sync){ 282 457 backsync_=sync; -
code/branches/network/src/network/Synchronisable.h
r1534 r1699 35 35 #include "core/OrxonoxClass.h" 36 36 #include "NetworkCallback.h" 37 #include "util/Bytestream.h" 37 38 38 39 namespace network … … 44 45 45 46 struct syncData{ 46 int length;47 int objectID;48 int classID;47 unsigned int length; 48 unsigned int objectID; 49 unsigned int classID; 49 50 unsigned char *data; 50 51 }; 51 52 52 53 typedef struct synchronisableVariable{ 53 int size;54 unsigned int size; 54 55 int mode; // this determines in which direction the variable gets synchronised 55 56 void *var; … … 69 70 70 71 virtual ~Synchronisable(); 71 int objectID;72 int classID;72 unsigned int objectID; 73 unsigned int classID; 73 74 74 75 void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0); 75 76 // syncData getData(); 76 77 syncData getData(unsigned char *mem, int mode=0x0); 78 bool getData2(unsigned char*& men, int mode=0x0); 79 //bool getData(Bytestream& bs, int mode=0x0); 77 80 int getSize(int mode=0x0); 81 int getSize2(int mode=0x0); 78 82 bool updateData(syncData vars, int mode=0x0); 83 bool updateData(unsigned char*& mem, int mode=0x0); 84 bool isMyData(unsigned char* mem); 79 85 void setBacksync(bool sync); 80 86 bool getBacksync(); … … 82 88 virtual bool create(); 83 89 static void setClient(bool b); 90 91 static bool fabricate(unsigned char*& mem, int mode=0x0); 84 92 protected: 85 93 Synchronisable();
Note: See TracChangeset
for help on using the changeset viewer.