Index: code/branches/network64/src/network/packet/Gamestate.cc
===================================================================
--- code/branches/network64/src/network/packet/Gamestate.cc	(revision 2316)
+++ code/branches/network64/src/network/packet/Gamestate.cc	(revision 2355)
@@ -28,6 +28,7 @@
 
 #include "Gamestate.h"
-#include "network/ClientInformation.h"
-#include "network/GamestateHandler.h"
+#include "../GamestateHandler.h"
+#include "../synchronisable/Synchronisable.h"
+#include "../TrafficControl.h"
 #include "core/CoreIncludes.h"
 #include "core/Iterator.h"
@@ -48,4 +49,6 @@
 
 #define PACKET_FLAG_GAMESTATE  ENET_PACKET_FLAG_RELIABLE
+  
+TrafficControl Gamestate::trafficControl_;
 
 Gamestate::Gamestate()
@@ -109,5 +112,7 @@
 
     //if(it->doSelection(id))
-    dataMap_[mem-data_]=(*it);  // save the mem location of the synchronisable data
+    if(tempsize!=0)
+      dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
+//     dataMap_[mem-data_]=(*it);  // save the mem location of the synchronisable data
     if(!it->getData(mem, id, mode))
       return false; // mem pointer gets automatically increased because of call by reference
@@ -148,5 +153,10 @@
     if(!s)
     {
-      Synchronisable::fabricate(mem, mode);
+      s = Synchronisable::fabricate(mem, mode);
+      if(s==0)
+        assert(0);
+//         COUT(0) << "could not fabricate synchronisable: " << objectheader->objectID << " classid: " << objectheader->classID << " creator: " << objectheader->creatorID << endl;
+//       else
+//         COUT(0) << "fabricated: " << objectheader->objectID << " classid: " << objectheader->classID << " creator: "  << objectheader->creatorID << endl;
     }
     else
@@ -332,7 +342,7 @@
 }
 
-Gamestate* Gamestate::doSelection(unsigned int clientID){
+Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
   assert(data_);
-  std::map<uint32_t, Synchronisable *>::iterator it;
+  std::list<obj>::iterator it;
 
   // allocate memory for new data
@@ -341,5 +351,5 @@
   Gamestate *gs = new Gamestate(gdata);
   uint8_t *newdata = gdata + sizeof(GamestateHeader);
-  uint8_t *origdata = GAMESTATE_START(data_);
+//   uint8_t *origdata = GAMESTATE_START(data_);
 
   //copy the GamestateHeader
@@ -348,16 +358,22 @@
   synchronisableHeader *oldobjectheader, *newobjectheader;
   uint32_t objectOffset;
-
+  unsigned int objectsize, destsize=0;
+  Synchronisable *object;
+
+  //call TrafficControl
+  trafficControl_.processObjectList( clientID, HEADER->id, &dataMap_ );
+  
   //copy in the zeros
   for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
-    oldobjectheader = (synchronisableHeader*)origdata;
+    oldobjectheader = (synchronisableHeader*)(data_ + (*it).objDataOffset);
     newobjectheader = (synchronisableHeader*)newdata;
-    uint32_t objectsize = oldobjectheader->size;
-    assert(it->second->objectID==oldobjectheader->objectID);
+    object = Synchronisable::getSynchronisable( (*it).objID );
+    assert(object->objectID == oldobjectheader->objectID);
+    objectsize = oldobjectheader->size;
     *newobjectheader = *oldobjectheader;
     objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader
-    if(it->second->doSelection(HEADER->id)){
+    if ( /*object->doSelection(HEADER->id)*/true ){
       assert(newobjectheader->dataAvailable==true);
-      memcpy(newdata+objectOffset, origdata+objectOffset, objectsize-objectOffset);
+      memcpy(newdata+objectOffset, data_ + (*it).objDataOffset + objectOffset, objectsize-objectOffset);
     }else{
       newobjectheader->dataAvailable=false;
@@ -366,6 +382,9 @@
     }
     newdata += objectsize;
-    origdata += objectsize;
-  }
+    destsize += objectsize;
+//     origdata += objectsize;
+  }
+  ((GamestateHeader*)gdata)->datasize = destsize;
+  assert(destsize!=0);
   return gs;
 }
@@ -382,5 +401,5 @@
 
   //preparations
-  std::map<uint32_t, Synchronisable *>::iterator it;
+  std::list<obj>::iterator it;
   uint8_t *origdata, *basedata, *destdata, *ndata;
   uint32_t objectOffset, streamOffset=0;    //data offset
@@ -388,4 +407,5 @@
   synchronisableHeader *origheader;
   synchronisableHeader *destheader;
+  Synchronisable *object;
 
   origdata = GAMESTATE_START(this->data_);
@@ -397,7 +417,8 @@
   for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
     assert(streamOffset<HEADER->datasize);
-    bool sendData = it->second->doSelection(HEADER->id);
     origheader = (synchronisableHeader *)(origdata+streamOffset);
     destheader = (synchronisableHeader *)(destdata+streamOffset);
+    object = Synchronisable::getSynchronisable(origheader->objectID);
+    bool sendData = object->doSelection(HEADER->id);
 
     //copy and partially diff the object header
@@ -450,5 +471,5 @@
 
   //preparations
-  std::map<uint32_t, Synchronisable *>::iterator it;
+  std::list<obj>::iterator it;
   uint8_t *origdata, *basedata, *destdata, *ndata;
   uint32_t objectOffset, streamOffset=0;    //data offset
@@ -456,4 +477,5 @@
   synchronisableHeader *origheader;
   synchronisableHeader *destheader;
+  Synchronisable *object;
 
   origdata = GAMESTATE_START(this->data_);
@@ -467,4 +489,5 @@
     origheader = (synchronisableHeader *)(origdata+streamOffset);
     destheader = (synchronisableHeader *)(destdata+streamOffset);
+    object = Synchronisable::getSynchronisable( origheader->objectID );
     bool sendData;
 
Index: code/branches/network64/src/network/packet/Gamestate.h
===================================================================
--- code/branches/network64/src/network/packet/Gamestate.h	(revision 2316)
+++ code/branches/network64/src/network/packet/Gamestate.h	(revision 2355)
@@ -31,9 +31,11 @@
 #define NETWORK_PACKETGAMESTATE_H
 
-#include "../NetworkPrereqs.h"
+#include "network/NetworkPrereqs.h"
 
 #include "Packet.h"
-#include "network/synchronisable/Synchronisable.h"
+#include "network/TrafficControl.h"
+#include "core/CoreIncludes.h"
 #include <map>
+#include <list>
 #ifndef NDEBUG
 #include "util/CRC32.h"
@@ -79,5 +81,5 @@
     Gamestate *undiff(Gamestate *base);
     Gamestate* intelligentUnDiff(Gamestate *base);
-    Gamestate* doSelection(unsigned int clientID);
+    Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
     bool compressData();
     bool decompressData();
@@ -92,5 +94,6 @@
     uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
     void removeObject(ObjectListIterator<Synchronisable> &it);
-    std::map<uint32_t, Synchronisable*> dataMap_;
+    std::list<obj> dataMap_;
+    static TrafficControl trafficControl_;
 };
 
