Changeset 2371 for code/branches/presentation/src/network
- Timestamp:
- Dec 10, 2008, 12:50:05 PM (16 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 3 deleted
- 13 edited
- 12 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
- Property svn:mergeinfo changed
/code/branches/network (added) merged: 2356 /code/branches/network64 (added) merged: 2210-2211,2245-2247,2255,2307,2309-2312,2316,2355
- Property svn:mergeinfo changed
-
code/branches/presentation/src/network/CMakeLists.txt
r2131 r2371 11 11 PacketBuffer.cc 12 12 Server.cc 13 Synchronisable.cc13 TrafficControl.cc 14 14 Host.cc 15 15 ) 16 16 17 17 ADD_SOURCE_DIRECTORY(NETWORK_SRC_FILES packet) 18 ADD_SOURCE_DIRECTORY(NETWORK_SRC_FILES synchronisable) 19 18 20 19 21 IF(WIN32) -
code/branches/presentation/src/network/Client.cc
r2171 r2371 43 43 #include "Client.h" 44 44 #include "Host.h" 45 #include " Synchronisable.h"45 #include "synchronisable/Synchronisable.h" 46 46 #include "core/CoreIncludes.h" 47 47 #include "packet/Packet.h" -
code/branches/presentation/src/network/ClientInformation.cc
r2171 r2371 45 45 namespace orxonox 46 46 { 47 47 48 48 49 ClientInformation *ClientInformation::head_=0; -
code/branches/presentation/src/network/ClientInformation.h
r2171 r2371 46 46 #include <boost/thread/recursive_mutex.hpp> 47 47 48 48 49 // WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE 49 50 50 51 namespace orxonox 51 52 { 52 static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;53 static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2;54 53 55 54 /** -
code/branches/presentation/src/network/ConnectionManager.cc
r2171 r2371 52 52 #include "util/Sleep.h" 53 53 #include "ClientInformation.h" 54 #include " Synchronisable.h"54 #include "synchronisable/Synchronisable.h" 55 55 #include "packet/ClassID.h" 56 56 -
code/branches/presentation/src/network/GamestateClient.cc
r2171 r2371 35 35 #include "core/BaseObject.h" 36 36 #include "core/Iterator.h" 37 #include "Synchronisable.h" 37 #include "synchronisable/Synchronisable.h" 38 #include "synchronisable/NetworkCallbackManager.h" 38 39 #include "packet/Acknowledgement.h" 39 40 … … 77 78 packet::Gamestate *processed = processGamestate(tempGamestate_); 78 79 // assert(processed); 80 81 //now call the queued callbacks 82 NetworkCallbackManager::callCallbacks(); 83 79 84 if (!processed) 80 85 return false; -
code/branches/presentation/src/network/GamestateManager.cc
r2171 r2371 49 49 #include "core/BaseObject.h" 50 50 #include "ClientInformation.h" 51 #include "Synchronisable.h" 51 #include "synchronisable/Synchronisable.h" 52 #include "synchronisable/NetworkCallbackManager.h" 52 53 53 54 namespace orxonox … … 86 87 // now clear the queue 87 88 gamestateQueue.clear(); 89 //and call all queued callbacks 90 NetworkCallbackManager::callCallbacks(); 88 91 return true; 89 92 } … … 134 137 if(!reference) 135 138 return 0; 136 gs = reference->doSelection(clientID); 137 // gs = new packet::Gamestate(*reference); 139 gs = reference->doSelection(clientID, 10000); 138 140 // gs = new packet::Gamestate(*reference); 139 141 // save the (undiffed) gamestate in the clients gamestate map -
code/branches/presentation/src/network/NetworkPrereqs.h
r2171 r2371 57 57 58 58 //----------------------------------------------------------------------- 59 // Includes 60 //----------------------------------------------------------------------- 61 #include "util/Math.h" 62 63 64 //----------------------------------------------------------------------- 59 65 // Forward declarations 60 66 //----------------------------------------------------------------------- 61 67 namespace orxonox 62 68 { 69 70 // Constants definition 71 72 static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1; 73 static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2; 74 static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1); 75 static const unsigned int SCHED_PRIORITY_OFFSET = -5; 76 77 78 79 63 80 class Client; 64 81 class ClientConnection; … … 70 87 class GamestateManager; 71 88 class GamestateHandler; 89 class NetworkCallbackBase; 90 template <class T> class NetworkCallback; 91 class NetworkCallbackManager; 72 92 class PacketBuffer; 73 93 class Server; 74 94 class ServerFrameListener; 75 95 class Synchronisable; 96 class SynchronisableVariableBase; 97 template <class T> class SynchronisableVariable; 98 template <class T> class SynchronisableVariableBidirectional; 76 99 struct ClientList; 77 100 struct PacketEnvelope; 78 101 struct QueueItem; 79 102 struct syncData; 80 struct synchronisableVariable; 103 class obj; 104 class objInfo; 81 105 namespace packet{ 82 106 class Gamestate; -
code/branches/presentation/src/network/packet/DeleteObjects.cc
r2171 r2371 30 30 #include "DeleteObjects.h" 31 31 #include <enet/enet.h> 32 #include "network/ Synchronisable.h"32 #include "network/synchronisable/Synchronisable.h" 33 33 #include "core/CoreIncludes.h" 34 34 #include <assert.h> -
code/branches/presentation/src/network/packet/Gamestate.cc
r2171 r2371 28 28 29 29 #include "Gamestate.h" 30 #include "network/ClientInformation.h" 31 #include "network/GamestateHandler.h" 30 #include "../GamestateHandler.h" 31 #include "../synchronisable/Synchronisable.h" 32 #include "../TrafficControl.h" 32 33 #include "core/CoreIncludes.h" 33 34 #include "core/Iterator.h" … … 48 49 49 50 #define PACKET_FLAG_GAMESTATE ENET_PACKET_FLAG_RELIABLE 51 52 TrafficControl Gamestate::trafficControl_; 50 53 51 54 Gamestate::Gamestate() … … 73 76 bool Gamestate::collectData(int id, uint8_t mode) 74 77 { 75 u nsigned int tempsize=0, currentsize=0;78 uint32_t tempsize=0, currentsize=0; 76 79 assert(data_==0); 77 u nsigned int size = calcGamestateSize(id, mode);80 uint32_t size = calcGamestateSize(id, mode); 78 81 79 82 COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl; … … 109 112 110 113 //if(it->doSelection(id)) 111 dataMap_[mem-data_]=(*it); // save the mem location of the synchronisable data 114 if(tempsize!=0) 115 dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) ); 116 // dataMap_[mem-data_]=(*it); // save the mem location of the synchronisable data 112 117 if(!it->getData(mem, id, mode)) 113 118 return false; // mem pointer gets automatically increased because of call by reference … … 148 153 if(!s) 149 154 { 150 Synchronisable::fabricate(mem, mode); 155 s = Synchronisable::fabricate(mem, mode); 156 if(s==0) 157 assert(0); 158 // COUT(0) << "could not fabricate synchronisable: " << objectheader->objectID << " classid: " << objectheader->classID << " creator: " << objectheader->creatorID << endl; 159 // else 160 // COUT(0) << "fabricated: " << objectheader->objectID << " classid: " << objectheader->classID << " creator: " << objectheader->creatorID << endl; 151 161 } 152 162 else … … 166 176 } 167 177 168 u nsigned int Gamestate::getSize() const178 uint32_t Gamestate::getSize() const 169 179 { 170 180 assert(data_); … … 251 261 assert(HEADER->compressed); 252 262 COUT(4) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", datasize: " << HEADER->datasize << ", compsize: " << HEADER->compsize << std::endl; 253 u nsigned int datasize = HEADER->datasize;254 u nsigned int compsize = HEADER->compsize;255 u nsigned int bufsize;263 uint32_t datasize = HEADER->datasize; 264 uint32_t compsize = HEADER->compsize; 265 uint32_t bufsize; 256 266 // assert(compsize<=datasize); 257 267 bufsize = datasize; … … 302 312 //unsigned char *basep = base->getGs()/*, *gs = getGs()*/; 303 313 uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_); 304 u nsigned int of=0; // pointers offset305 u nsigned int dest_length=0;314 uint32_t of=0; // pointers offset 315 uint32_t dest_length=0; 306 316 dest_length=HEADER->datasize; 307 317 if(dest_length==0) … … 332 342 } 333 343 334 Gamestate* Gamestate::doSelection(unsigned int clientID ){344 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){ 335 345 assert(data_); 336 std:: map<unsigned int, Synchronisable *>::iterator it;346 std::list<obj>::iterator it; 337 347 338 348 // allocate memory for new data … … 341 351 Gamestate *gs = new Gamestate(gdata); 342 352 uint8_t *newdata = gdata + sizeof(GamestateHeader); 343 uint8_t *origdata = GAMESTATE_START(data_);353 // uint8_t *origdata = GAMESTATE_START(data_); 344 354 345 355 //copy the GamestateHeader … … 347 357 348 358 synchronisableHeader *oldobjectheader, *newobjectheader; 349 unsigned int objectOffset; 350 359 uint32_t objectOffset; 360 unsigned int objectsize, destsize=0; 361 Synchronisable *object; 362 363 //call TrafficControl 364 trafficControl_.processObjectList( clientID, HEADER->id, &dataMap_ ); 365 351 366 //copy in the zeros 352 367 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ 353 oldobjectheader = (synchronisableHeader*) origdata;368 oldobjectheader = (synchronisableHeader*)(data_ + (*it).objDataOffset); 354 369 newobjectheader = (synchronisableHeader*)newdata; 355 unsigned int objectsize = oldobjectheader->size; 356 assert(it->second->objectID==oldobjectheader->objectID); 370 object = Synchronisable::getSynchronisable( (*it).objID ); 371 assert(object->objectID == oldobjectheader->objectID); 372 objectsize = oldobjectheader->size; 357 373 *newobjectheader = *oldobjectheader; 358 374 objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader 359 if (it->second->doSelection(HEADER->id)){375 if ( /*object->doSelection(HEADER->id)*/true ){ 360 376 assert(newobjectheader->dataAvailable==true); 361 memcpy(newdata+objectOffset, origdata+objectOffset, objectsize-objectOffset);377 memcpy(newdata+objectOffset, data_ + (*it).objDataOffset + objectOffset, objectsize-objectOffset); 362 378 }else{ 363 379 newobjectheader->dataAvailable=false; … … 366 382 } 367 383 newdata += objectsize; 368 origdata += objectsize; 369 } 384 destsize += objectsize; 385 // origdata += objectsize; 386 } 387 ((GamestateHeader*)gdata)->datasize = destsize; 388 assert(destsize!=0); 370 389 return gs; 371 390 } … … 382 401 383 402 //preparations 384 std:: map<unsigned int, Synchronisable *>::iterator it;403 std::list<obj>::iterator it; 385 404 uint8_t *origdata, *basedata, *destdata, *ndata; 386 u nsigned int objectOffset, streamOffset=0; //data offset387 u nsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;405 uint32_t objectOffset, streamOffset=0; //data offset 406 uint32_t minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 388 407 synchronisableHeader *origheader; 389 408 synchronisableHeader *destheader; 409 Synchronisable *object; 390 410 391 411 origdata = GAMESTATE_START(this->data_); … … 397 417 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ 398 418 assert(streamOffset<HEADER->datasize); 399 bool sendData = it->second->doSelection(HEADER->id);400 419 origheader = (synchronisableHeader *)(origdata+streamOffset); 401 420 destheader = (synchronisableHeader *)(destdata+streamOffset); 421 object = Synchronisable::getSynchronisable(origheader->objectID); 422 bool sendData = object->doSelection(HEADER->id); 402 423 403 424 //copy and partially diff the object header 404 assert(sizeof(synchronisableHeader)==3*sizeof(u nsigned int)+sizeof(bool));425 assert(sizeof(synchronisableHeader)==3*sizeof(uint32_t)+sizeof(bool)); 405 426 *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff) 406 427 *(bool*)(destdata+sizeof(uint32_t)) = sendData; … … 450 471 451 472 //preparations 452 std:: map<unsigned int, Synchronisable *>::iterator it;473 std::list<obj>::iterator it; 453 474 uint8_t *origdata, *basedata, *destdata, *ndata; 454 u nsigned int objectOffset, streamOffset=0; //data offset455 u nsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;475 uint32_t objectOffset, streamOffset=0; //data offset 476 uint32_t minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 456 477 synchronisableHeader *origheader; 457 478 synchronisableHeader *destheader; 479 Synchronisable *object; 458 480 459 481 origdata = GAMESTATE_START(this->data_); … … 467 489 origheader = (synchronisableHeader *)(origdata+streamOffset); 468 490 destheader = (synchronisableHeader *)(destdata+streamOffset); 491 object = Synchronisable::getSynchronisable( origheader->objectID ); 469 492 bool sendData; 470 493 471 494 //copy and partially diff the object header 472 assert(sizeof(synchronisableHeader)==3*sizeof(u nsigned int)+sizeof(bool));473 *(u nsigned int*)destdata = *(unsigned int*)origdata; //size (do not diff)474 *(bool*)(destdata+sizeof(u nsigned int)) = *(bool*)(origdata+sizeof(unsigned int));475 sendData = *(bool*)(origdata+sizeof(u nsigned int));495 assert(sizeof(synchronisableHeader)==3*sizeof(uint32_t)+sizeof(bool)); 496 *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff) 497 *(bool*)(destdata+sizeof(uint32_t)) = *(bool*)(origdata+sizeof(uint32_t)); 498 sendData = *(bool*)(origdata+sizeof(uint32_t)); 476 499 if(sendData){ 477 *(u nsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+sizeof(unsigned int)+sizeof(bool)); //objectid (diff it)478 *(u nsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+2*sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+2*sizeof(unsigned int)+sizeof(bool)); //classid (diff it)500 *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+sizeof(uint32_t)+sizeof(bool)); //objectid (diff it) 501 *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+2*sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+2*sizeof(uint32_t)+sizeof(bool)); //classid (diff it) 479 502 }else{ 480 *(u nsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = 0;481 *(u nsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0;503 *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0; 504 *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0; 482 505 } 483 506 objectOffset=sizeof(synchronisableHeader); … … 517 540 uint8_t *basep = GAMESTATE_START(base->data_); 518 541 uint8_t *gs = GAMESTATE_START(this->data_); 519 u nsigned int of=0; // pointers offset520 u nsigned int dest_length=0;542 uint32_t of=0; // pointers offset 543 uint32_t dest_length=0; 521 544 dest_length=HEADER->datasize; 522 545 if(dest_length==0) … … 548 571 549 572 550 u nsigned int Gamestate::calcGamestateSize(unsigned int id, uint8_t mode)551 { 552 u nsigned int size=0;573 uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode) 574 { 575 uint32_t size=0; 553 576 // get the start of the Synchronisable list 554 577 ObjectList<Synchronisable>::iterator it; -
code/branches/presentation/src/network/packet/Gamestate.h
r2171 r2371 31 31 #define NETWORK_PACKETGAMESTATE_H 32 32 33 #include " ../NetworkPrereqs.h"33 #include "network/NetworkPrereqs.h" 34 34 35 35 #include "Packet.h" 36 #include "network/Synchronisable.h" 36 #include "network/TrafficControl.h" 37 #include "core/CoreIncludes.h" 37 38 #include <map> 39 #include <list> 38 40 #ifndef NDEBUG 39 41 #include "util/CRC32.h" … … 79 81 Gamestate *undiff(Gamestate *base); 80 82 Gamestate* intelligentUnDiff(Gamestate *base); 81 Gamestate* doSelection(unsigned int clientID );83 Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); 82 84 bool compressData(); 83 85 bool decompressData(); … … 85 87 // Packet functions 86 88 private: 87 virtual u nsigned int getSize() const;89 virtual uint32_t getSize() const; 88 90 virtual bool process(); 89 91 90 92 bool operator ==(packet::Gamestate gs); 91 93 private: 92 u nsigned int calcGamestateSize(unsigned int id, uint8_t mode=0x0);94 uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0); 93 95 void removeObject(ObjectListIterator<Synchronisable> &it); 94 std::map<unsigned int, Synchronisable*> dataMap_; 96 std::list<obj> dataMap_; 97 static TrafficControl trafficControl_; 95 98 }; 96 99 -
code/branches/presentation/src/network/packet/Welcome.cc
r2171 r2371 32 32 #include "Welcome.h" 33 33 #include "network/Host.h" 34 #include "network/ Synchronisable.h"34 #include "network/synchronisable/Synchronisable.h" 35 35 #include "core/CoreIncludes.h" 36 36 #include <assert.h> … … 43 43 #define _CLIENTID _PACKETID + sizeof(ENUM::Type) 44 44 #define _SHIPID _CLIENTID + sizeof(uint32_t) 45 #define _ENDIANTEST _SHIPID + sizeof(uint32_t) 45 46 46 47 Welcome::Welcome( unsigned int clientID, unsigned int shipID ) … … 52 53 assert(data_); 53 54 *(packet::ENUM::Type *)(data_ + _PACKETID ) = packet::ENUM::Welcome; 54 *(uint32_t *)&data_[ _CLIENTID ] = clientID; 55 *(uint32_t *)&data_[ _SHIPID ] = shipID; 55 *(uint32_t *)(data_ + _CLIENTID ) = clientID; 56 *(uint32_t *)(data_ + _SHIPID ) = shipID; 57 *(uint32_t *)(data_ + _ENDIANTEST ) = 0xFEDC4321; 56 58 } 57 59 … … 70 72 71 73 unsigned int Welcome::getSize() const{ 72 return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t);74 return sizeof(packet::ENUM::Type) + 3*sizeof(uint32_t); 73 75 } 74 76 … … 77 79 clientID = *(uint32_t *)&data_[ _CLIENTID ]; 78 80 shipID = *(uint32_t *)&data_[ _SHIPID ]; 81 assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321); 79 82 Host::setClientID(clientID); 80 83 Host::setShipID(shipID); -
code/branches/presentation/src/network/synchronisable/NetworkCallback.h
- Property svn:mergeinfo changed
/code/branches/network/src/network/synchronisable/NetworkCallback.h (added) merged: 2356
- Property svn:mergeinfo changed
-
code/branches/presentation/src/network/synchronisable/Synchronisable.cc
- Property svn:mergeinfo changed
/code/branches/network/src/network/synchronisable/Synchronisable.cc (added) merged: 2356
- Property svn:mergeinfo changed
-
code/branches/presentation/src/network/synchronisable/Synchronisable.h
- Property svn:mergeinfo changed
/code/branches/network/src/network/synchronisable/Synchronisable.h (added) merged: 2356
- Property svn:mergeinfo changed
Note: See TracChangeset
for help on using the changeset viewer.