Changeset 2575
- Timestamp:
- Jan 6, 2009, 9:39:41 PM (16 years ago)
- Location:
- code/branches/presentation/src/network
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/network/GamestateManager.h
r2382 r2575 82 82 void removeClient(ClientInformation *client); 83 83 private: 84 // void cleanup(); // "garbage handler"85 84 bool processGamestate(packet::Gamestate *gs); 86 85 -
code/branches/presentation/src/network/Server.cc
r2415 r2575 216 216 */ 217 217 void Server::updateGamestate() { 218 // if( ClientInformation::getBegin()==NULL ) 219 //no client connected 220 // return; 218 221 gamestates_->update(); 219 222 COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; … … 274 277 bool Server::sendObjectDeletes(){ 275 278 ClientInformation *temp = ClientInformation::getBegin(); 279 if( temp == NULL ) 280 //no client connected 281 return true; 276 282 packet::DeleteObjects *del = new packet::DeleteObjects(); 277 283 if(!del->fetchIDs()) -
code/branches/presentation/src/network/packet/DeleteObjects.cc
r2506 r2575 61 61 if(number==0) 62 62 return false; 63 COUT( 3) << "sending DeleteObjects: ";63 COUT(4) << "sending DeleteObjects: "; 64 64 unsigned int size = sizeof(ENUM::Type) + sizeof(uint32_t)*(number+1); 65 65 data_ = new uint8_t[size]; … … 73 73 // assert(temp<10000); //ugly hack 74 74 *reinterpret_cast<uint32_t*>(tdata) = temp; 75 COUT( 3) << temp << " ";75 COUT(4) << temp << " "; 76 76 tdata += sizeof(uint32_t); 77 77 } 78 COUT( 3) << std::endl;78 COUT(4) << std::endl; 79 79 return true; 80 80 } … … 87 87 bool DeleteObjects::process(){ 88 88 for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){ 89 COUT( 3) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;89 COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl; 90 90 Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) ); 91 91 } -
code/branches/presentation/src/network/packet/Gamestate.cc
r2501 r2575 36 36 37 37 #include <zlib.h> 38 #include < assert.h>38 #include <cassert> 39 39 40 40 … … 43 43 44 44 namespace packet { 45 46 #define GAMESTATE_START(data) (data + sizeof(GamestateHeader))47 #define GAMESTATE_HEADER(data) ((GamestateHeader *)data)48 #define HEADER GAMESTATE_HEADER(data_)49 45 50 46 … … 93 89 ObjectList<Synchronisable>::iterator it; 94 90 for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 91 92 #ifndef NDEBUG 95 93 tempsize=it->getSize(id, mode); 96 97 94 if(currentsize+tempsize > size){ 98 95 assert(0); // if we don't use multithreading this part shouldn't be neccessary … … 108 105 size = currentsize+addsize; 109 106 }// stop allocate additional memory 110 107 #endif 111 108 112 109 //if(it->doSelection(id)) 113 if (tempsize!=0)110 if ( it->doSync( id, mode ) ) 114 111 dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) ); 115 112 // dataMap_[mem-data_]=(*it); // save the mem location of the synchronisable data … … 196 193 } 197 194 198 199 200 int Gamestate::getID(){201 return HEADER->id;202 }203 204 195 uint32_t Gamestate::getSize() const 205 196 { … … 255 246 case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl; return false; 256 247 } 257 #ifndef NDEBUG258 //decompress and compare the start and the decompressed data259 uint8_t *rdata = new uint8_t[HEADER->datasize+sizeof(GamestateHeader)];260 uint8_t *d2 = GAMESTATE_START(rdata);261 uLongf length2 = HEADER->datasize;262 uncompress(d2, &length2, dest, buffer);263 for(unsigned int i=0; i<HEADER->datasize; i++){264 assert(*(source+i)==*(d2+i));265 }266 delete[] rdata;267 #endif268 248 269 249 //copy and modify header 270 #ifndef NDEBUG271 HEADER->crc32 = calcCRC(data_+sizeof(GamestateHeader), HEADER->datasize);272 #endif273 250 *GAMESTATE_HEADER(ndata) = *HEADER; 274 251 //delete old data … … 305 282 case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return false; 306 283 } 307 #ifndef NDEBUG308 assert(HEADER->crc32==calcCRC(ndata+sizeof(GamestateHeader), HEADER->datasize));309 #endif310 284 311 285 //copy over the header … … 420 394 origdata += objectsize; 421 395 destsize += objectsize; 422 // origdata += objectsize;423 396 } 424 397 #ifndef NDEBUG … … 438 411 } 439 412 440 441 Gamestate* Gamestate::intelligentDiff(Gamestate *base, unsigned int clientID){442 // asserts443 assert(data_);444 assert(base->data_);445 assert(!GAMESTATE_HEADER(base->data_)->diffed);446 assert(!GAMESTATE_HEADER(base->data_)->compressed);447 assert(!HEADER->compressed);448 assert(!HEADER->diffed);449 450 //preparations451 std::list<obj>::iterator it;452 uint8_t *origdata, *basedata, *destdata, *ndata;453 uint32_t objectOffset, streamOffset=0; //data offset454 uint32_t minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;455 synchronisableHeader *origheader;456 synchronisableHeader *destheader;457 Synchronisable *object;458 459 origdata = GAMESTATE_START(this->data_);460 basedata = GAMESTATE_START(base->data_);461 ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)];462 destdata = ndata + sizeof(GamestateHeader);463 464 // do the diff465 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){466 assert(streamOffset<HEADER->datasize);467 origheader = (synchronisableHeader *)(origdata+streamOffset);468 destheader = (synchronisableHeader *)(destdata+streamOffset);469 object = Synchronisable::getSynchronisable(origheader->objectID);470 bool sendData = object->doSelection(HEADER->id);471 472 //copy and partially diff the object header473 assert(sizeof(synchronisableHeader)==3*sizeof(uint32_t)+sizeof(bool));474 *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff)475 *(bool*)(destdata+sizeof(uint32_t)) = sendData;476 if(sendData){477 *(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)478 *(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 }else{480 *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0;481 *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0;482 }483 objectOffset=sizeof(synchronisableHeader);484 streamOffset+=sizeof(synchronisableHeader);485 486 //now handle the object data or fill with zeros487 while(objectOffset<origheader->size ){488 489 if(sendData && streamOffset<minsize)490 *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor491 else if(sendData)492 *(destdata+objectOffset)=((uint8_t)0)^*(origdata+objectOffset); // xor with 0 (basestream is too short)493 else494 *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered495 496 objectOffset++;497 streamOffset++;498 }499 destdata+=objectOffset;500 origdata+=objectOffset;501 basedata+=objectOffset;502 }503 504 //copy over the gamestate header and set the diffed flag505 *(GamestateHeader *)ndata = *HEADER; //copy over the header506 Gamestate *gs = new Gamestate(ndata);507 GAMESTATE_HEADER(ndata)->diffed=true;508 return gs;509 }510 511 Gamestate* Gamestate::intelligentUnDiff(Gamestate *base){512 // asserts513 assert(data_);514 assert(base->data_);515 assert(!GAMESTATE_HEADER(base->data_)->diffed);516 assert(!GAMESTATE_HEADER(base->data_)->compressed);517 assert(!HEADER->compressed);518 assert(HEADER->diffed);519 520 //preparations521 std::list<obj>::iterator it;522 uint8_t *origdata, *basedata, *destdata, *ndata;523 uint32_t objectOffset, streamOffset=0; //data offset524 uint32_t minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;525 synchronisableHeader *origheader;526 synchronisableHeader *destheader;527 Synchronisable *object;528 529 origdata = GAMESTATE_START(this->data_);530 basedata = GAMESTATE_START(base->data_);531 ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)];532 destdata = ndata + sizeof(GamestateHeader);533 534 // do the undiff535 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){536 assert(streamOffset<HEADER->datasize);537 origheader = (synchronisableHeader *)(origdata+streamOffset);538 destheader = (synchronisableHeader *)(destdata+streamOffset);539 object = Synchronisable::getSynchronisable( origheader->objectID );540 bool sendData;541 542 //copy and partially diff the object header543 assert(sizeof(synchronisableHeader)==3*sizeof(uint32_t)+sizeof(bool));544 *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff)545 *(bool*)(destdata+sizeof(uint32_t)) = *(bool*)(origdata+sizeof(uint32_t));546 sendData = *(bool*)(origdata+sizeof(uint32_t));547 if(sendData){548 *(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)549 *(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)550 }else{551 *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0;552 *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0;553 }554 objectOffset=sizeof(synchronisableHeader);555 streamOffset+=sizeof(synchronisableHeader);556 557 //now handle the object data or fill with zeros558 while(objectOffset<origheader->size ){559 560 if(sendData && streamOffset<minsize)561 *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor562 else if(sendData)563 *(destdata+objectOffset)=((unsigned char)0)^*(origdata+objectOffset); // xor with 0 (basestream is too short)564 else565 *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered566 567 objectOffset++;568 streamOffset++;569 }570 destdata+=objectOffset;571 origdata+=objectOffset;572 basedata+=objectOffset;573 }574 575 //copy over the gamestate header and set the diffed flag576 *(GamestateHeader *)ndata = *HEADER; //copy over the header577 Gamestate *gs = new Gamestate(ndata);578 GAMESTATE_HEADER(ndata)->diffed=false;579 return gs;580 }581 413 582 414 Gamestate *Gamestate::undiff(Gamestate *base) … … 627 459 for(it = ObjectList<Synchronisable>::begin(); it; ++it) 628 460 size+=it->getSize(id, mode); // size of the actual data of the synchronisable 629 // size+=sizeof(GamestateHeader);630 461 return size; 631 462 } 632 463 633 /** 634 * This function removes a Synchronisable out of the universe 635 * @param it iterator of the list pointing to the object 636 * @return iterator pointing to the next object in the list 637 */ 638 void Gamestate::removeObject(ObjectList<Synchronisable>::iterator &it) { 639 ObjectList<Synchronisable>::iterator temp=it; 640 ++it; 641 delete *temp; 642 } 643 644 bool Gamestate::isDiffed(){ 645 return HEADER->diffed; 646 } 647 648 bool Gamestate::isCompressed(){ 649 return HEADER->compressed; 650 } 651 652 int Gamestate::getBaseID(){ 653 return HEADER->base_id; 654 } 655 } 656 657 } 464 } //namespace packet 465 466 } //namespace orxonox -
code/branches/presentation/src/network/packet/Gamestate.h
r2382 r2575 46 46 namespace packet { 47 47 48 #define GAMESTATE_START(data) (data + sizeof(GamestateHeader)) 49 #define GAMESTATE_HEADER(data) ((GamestateHeader *)data) 50 #define HEADER GAMESTATE_HEADER(data_) 51 48 52 struct _NetworkExport GamestateHeader{ 49 53 ENUM::Type packetType; … … 55 59 bool complete:1; // wheter it is a complete gamestate or only partial 56 60 bool compressed:1; 57 #ifndef NDEBUG58 uint32_t crc32;59 #endif60 61 }; 61 62 … … 73 74 bool collectData(int id, uint8_t mode=0x0); 74 75 bool spreadData( uint8_t mode=0x0); 75 in t getID();76 bool isDiffed();77 bool isCompressed();78 in t getBaseID();76 inline int32_t getID() const { return HEADER->id; } 77 inline bool isDiffed() const { return HEADER->diffed; } 78 inline bool isCompressed() const { return HEADER->compressed; } 79 inline int32_t getBaseID() const { return HEADER->base_id; } 79 80 Gamestate *diff(Gamestate *base); 80 Gamestate* intelligentDiff(Gamestate *base, unsigned int clientID);81 81 Gamestate *undiff(Gamestate *base); 82 Gamestate* intelligentUnDiff(Gamestate *base);83 82 Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); 84 83 bool compressData(); … … 88 87 private: 89 88 virtual uint32_t getSize() const; 90 virtual bool process();89 virtual inline bool process(); 91 90 92 91 bool operator ==(packet::Gamestate gs); 93 92 private: 94 93 uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0); 95 void removeObject(ObjectListIterator<Synchronisable> &it);96 94 std::list<obj> dataMap_; 97 // static TrafficControl *trafficControl_;98 95 }; 99 96 -
code/branches/presentation/src/network/synchronisable/Synchronisable.cc
r2540 r2575 422 422 } 423 423 424 bool Synchronisable::doSelection(int32_t id){425 return true; //TODO: change this426 //return ( id==0 || id%objectFrequency_==objectID%objectFrequency_ ) && ((objectMode_&state_)!=0);427 }428 429 424 /** 430 425 * This function looks at the header located in the bytestream and checks wheter objectID and classID match with the Synchronisables ones -
code/branches/presentation/src/network/synchronisable/Synchronisable.h
r2485 r2575 118 118 uint32_t getSize(int32_t id, uint8_t mode=0x0); 119 119 bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false); 120 bool isMyData(uint8_t* mem); 121 bool doSelection(int32_t id); 122 bool doSync(int32_t id, uint8_t mode=0x0); 120 inline bool isMyData(uint8_t* mem); 121 inline bool doSync(int32_t id, uint8_t mode=0x0); 123 122 124 123 uint32_t objectID; -
code/branches/presentation/src/network/synchronisable/SynchronisableVariable.h
r2371 r2575 75 75 76 76 virtual inline uint8_t getMode(){ return mode_; } 77 virtual void getData(uint8_t*& mem, uint8_t mode);77 virtual inline void getData(uint8_t*& mem, uint8_t mode); 78 78 virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false); 79 virtual uint32_t getSize(uint8_t mode);79 virtual inline uint32_t getSize(uint8_t mode); 80 80 virtual inline void* getReference(){ return (void *)&this->variable_; } 81 81 protected:
Note: See TracChangeset
for help on using the changeset viewer.