[Orxonox-commit 472] r3047 - in branches/netp3/src/network: . packet

scheusso at orxonox.net scheusso at orxonox.net
Mon May 25 00:47:15 CEST 2009


Author: scheusso
Date: 2009-05-25 00:47:15 +0200 (Mon, 25 May 2009)
New Revision: 3047

Modified:
   branches/netp3/src/network/GamestateManager.cc
   branches/netp3/src/network/packet/Gamestate.cc
   branches/netp3/src/network/packet/Gamestate.h
Log:
had to revert some things in Gamestate::diff


Modified: branches/netp3/src/network/GamestateManager.cc
===================================================================
--- branches/netp3/src/network/GamestateManager.cc	2009-05-24 21:53:09 UTC (rev 3046)
+++ branches/netp3/src/network/GamestateManager.cc	2009-05-24 22:47:15 UTC (rev 3047)
@@ -131,8 +131,11 @@
     }
     if(client){
 //       COUT(3) << "diffing" << std::endl;
+//       packet::Gamestate* gs1  = gs;
       gs = gs->diff(client);
+//       packet::Gamestate* gs2 = gs->undiff(client);
 //       gs = new packet::Gamestate(*gs);
+//       assert(*gs1==*gs2);
     }
     else{
 //       COUT(3) << "not diffing" << std::endl;
@@ -160,6 +163,7 @@
       std::map<unsigned int, packet::Gamestate*>::iterator it;
       for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){
         delete it->second;
+
         gamestateMap_[clientID].erase(it++);
       }
       return true;

Modified: branches/netp3/src/network/packet/Gamestate.cc
===================================================================
--- branches/netp3/src/network/packet/Gamestate.cc	2009-05-24 21:53:09 UTC (rev 3046)
+++ branches/netp3/src/network/packet/Gamestate.cc	2009-05-24 22:47:15 UTC (rev 3047)
@@ -225,16 +225,12 @@
 bool Gamestate::operator==(packet::Gamestate gs){
   uint8_t *d1 = data_+GamestateHeader::getSize();
   uint8_t *d2 = gs.data_+GamestateHeader::getSize();
+  GamestateHeader* h1 = new GamestateHeader(data_);
+  GamestateHeader* h2 = new GamestateHeader(gs.data_);
+  assert(h1->getDataSize() == h2->getDataSize());
   assert(!isCompressed());
   assert(!gs.isCompressed());
-  while(d1<data_+header_->getDataSize())
-  {
-    if(*d1!=*d2)
-      return false;
-    d1++;
-    d2++;
-  }
-  return true;
+  return memcmp(d1, d2, h1->getDataSize())==0;
 }
 
 bool Gamestate::process()
@@ -338,49 +334,19 @@
     return NULL;
   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
   uint8_t *dest = ndata + GamestateHeader::getSize();
-  
-  
-  // LOOP-UNROLLED DIFFING
-  uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs;
-  // diff in 4-byte steps
-  while( of < (uint32_t)(header_->getDataSize())/4 ){
-    if( of < (uint32_t)(diffHeader.getDataSize())/4 )
-    {
-      *(dest32+of)=*(base32+of) ^ *(gs32+of); // do the xor
-      ++of;
-    } else
-    {
-      *(dest32+of)=*(gs32+of); // same as 0 ^ *(gs32+of)
-      ++of;
+  while(of < diffHeader.getDataSize() && of < header_->getDataSize()){
+    *(dest+of)=*(basep+of)^*(gs+of); // do the xor
+    ++of;
+  }
+  if(diffHeader.getDataSize()!=header_->getDataSize()){
+    uint8_t n=0;
+    if(diffHeader.getDataSize() < header_->getDataSize()){
+      while(of<dest_length){
+        *(dest+of)=n^*(gs+of);
+        of++;
+      }
     }
   }
-  uint32_t base_rest = 0;
-  // fill the base_rest first with 0 and then with the remaining bytes in base32
-  switch( diffHeader.getDataSize()%sizeof(uint32_t) )
-  {
-    case 3:
-      *((uint8_t*)(&base_rest)+2) = *((uint8_t*)(base32+of-1)+2); // save the last byte to the buffer
-    case 2:
-      *((uint16_t*)(&base_rest)) = *((uint16_t*)(base32+of-1)); // xor 2 bytes at once (either 2nd and 3rd last or the 2 last bytes)
-      break;
-    case 1:
-      *((uint8_t*)(&base_rest)) = *((uint8_t*)(base32+of-1)); // xor the last byte
-    case 0:
-      break; // leave 0
-  }
-  // now diff the rest and save it to dest32 in 2- and 1-byte steps
-  switch( header_->getDataSize()%sizeof(uint32_t) )
-  {
-    case 3:
-      *((uint8_t*)(dest32+of)+2) = *((uint8_t*)&base_rest+2) ^ *((uint8_t*)(gs32+of-1)+2); // save the last byte to the buffer
-    case 2:
-      *((uint16_t*)(dest32+of)) = *((uint16_t*)&base_rest) ^ *((uint16_t*)(gs32+of-1)); // xor 2 bytes at once (either 2nd and 3rd last or the 2 last bytes)
-      break;
-    case 1:
-      *((uint8_t*)(dest32+of)) = *((uint8_t*)&base_rest) ^ *((uint8_t*)(gs32+of-1)); // xor the last byte
-    case 0:
-      break;
-  }
 
   Gamestate *g = new Gamestate(ndata, getClientID());
   *(g->header_) = *header_;
@@ -391,6 +357,58 @@
   return g;
 }
 
+// Gamestate *Gamestate::diff(Gamestate *base)
+// {
+//   assert(data_);
+//   assert(!header_->isCompressed());
+//   assert(!header_->isDiffed());
+//   GamestateHeader diffHeader(base->data_);
+//   uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
+//   uint32_t of=0; // pointers offset
+//   uint32_t dest_length=0;
+//   dest_length=header_->getDataSize();
+//   if(dest_length==0)
+//     return NULL;
+//   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
+//   uint8_t *dest = ndata + GamestateHeader::getSize();
+//   
+//   
+//   // LOOP-UNROLLED DIFFING
+//   uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs;
+//   // diff in 4-byte steps
+//   while( of < (uint32_t)(header_->getDataSize())/4 ){
+//     if( of < (uint32_t)(diffHeader.getDataSize())/4 )
+//     {
+//       *(dest32+of)=*(base32+of) ^ *(gs32+of); // do the xor
+//       ++of;
+//     }
+//     else
+//     {
+//       *(dest32+of)=*(gs32+of); // same as 0 ^ *(gs32+of)
+//       ++of;
+//     }
+//   }
+//   for( unsigned int of2 = 0; of2 < header_->getDataSize()%4; ++of2 )
+//   {
+//     if( of*4+of2 < diffHeader.getDataSize() )
+//     {
+//       *(dest+4*of+of2)=*(basep+4*of+of2) ^ *(gs+4*of+of2); // do the xor
+//     }
+//     else
+//     {
+//       *(dest+4*of+of2)=*(gs+4*of+of2); // same as 0 ^ *(gs32+of)
+//     }
+//   }
+// 
+//   Gamestate *g = new Gamestate(ndata, getClientID());
+//   *(g->header_) = *header_;
+//   g->header_->setDiffed( true );
+//   g->header_->setBaseID( base->getID() );
+//   g->flags_=flags_;
+//   g->packetDirection_ = packetDirection_;
+//   return g;
+// }
+
 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
   assert(data_);
   std::vector<obj>::iterator it;

Modified: branches/netp3/src/network/packet/Gamestate.h
===================================================================
--- branches/netp3/src/network/packet/Gamestate.h	2009-05-24 21:53:09 UTC (rev 3046)
+++ branches/netp3/src/network/packet/Gamestate.h	2009-05-24 22:47:15 UTC (rev 3047)
@@ -119,13 +119,13 @@
     Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
     bool compressData();
     bool decompressData();
+    bool operator ==(packet::Gamestate gs);
 
     // Packet functions
   private:
     virtual uint32_t getSize() const;
     virtual inline bool process();
 
-    bool operator ==(packet::Gamestate gs);
   private:
     uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
     std::vector<obj> dataVector_;




More information about the Orxonox-commit mailing list