Index: code/branches/network/src/network/ClientInformation.h
===================================================================
--- code/branches/network/src/network/ClientInformation.h	(revision 2348)
+++ code/branches/network/src/network/ClientInformation.h	(revision 2351)
@@ -45,4 +45,5 @@
 #include <enet/enet.h>
 #include <boost/thread/recursive_mutex.hpp>
+
 
 // WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE
Index: code/branches/network/src/network/GamestateManager.cc
===================================================================
--- code/branches/network/src/network/GamestateManager.cc	(revision 2348)
+++ code/branches/network/src/network/GamestateManager.cc	(revision 2351)
@@ -134,5 +134,6 @@
     if(!reference)
       return 0;
-    gs = reference->doSelection(clientID);
+    gs = reference->doSelection(clientID, 10000);
+//     gs = new packet::Gamestate(*reference);
     // save the (undiffed) gamestate in the clients gamestate map
     gamestateMap_[clientID].insert(std::pair<int, packet::Gamestate*>(gs->getID(), gs));
Index: code/branches/network/src/network/Synchronisable.h
===================================================================
--- code/branches/network/src/network/Synchronisable.h	(revision 2348)
+++ code/branches/network/src/network/Synchronisable.h	(revision 2351)
@@ -113,4 +113,5 @@
 
     inline unsigned int getObjectID(){return objectID;}
+    inline unsigned int getCreatorID(){return creatorID;}
     inline unsigned int getClassID(){return classID;}
     inline unsigned int getPriority(){ return objectFrequency_;}
Index: code/branches/network/src/network/TrafficControl.cc
===================================================================
--- code/branches/network/src/network/TrafficControl.cc	(revision 2348)
+++ code/branches/network/src/network/TrafficControl.cc	(revision 2351)
@@ -31,6 +31,4 @@
 #include <cassert>
 #include <boost/bind.hpp>
-#include "Synchronisable.h"
-#include "ClientInformation.h"
 
 namespace network {
@@ -86,18 +84,21 @@
     assert(clientListPerm_[clientID].find(j.objID) != clientListPerm_[clientID].end()); // make sure the object j is in the client list
     
-    return clientListPerm_[clientID][i.objID].objID < clientListPerm_[clientID][j.objID].objID;
+    int prio1 = clientListPerm_[clientID][i.objID].objValuePerm + clientListPerm_[clientID][i.objID].objValueSched;
+    int prio2 = clientListPerm_[clientID][j.objID].objValuePerm + clientListPerm_[clientID][j.objID].objValueSched;
+    // NOTE: smaller priority is better
+    return prio1 < prio2;
   }
 
 
-	std::vector<obj>* TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj> *list)
+	void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj> *list)
 	{
-	  copiedVector = *list;
+// 	  copiedVector = *list;
 	  currentClientID=clientID;
 	  currentGamestateID=gamestateID;
 	  evaluateList(clientID, list);
 	  //list hatte vorher ja vielmehr elemente, nach zuweisung nicht mehr... speicherplatz??
-	  *list=copiedVector;
+// 	  *list=copiedVector;
     //später wird copiedVector ja überschrieben, ist das ein problem für list-dh. für gamestatemanager?
-	  return list;
+	  return;
 	}
 	
@@ -212,13 +213,16 @@
     std::vector<obj>::iterator itvec;
     itvec = list->begin();
-//     unsigned int i=0;
     for(itvec = list->begin(); itvec != list->end() && size<targetsize; itvec++)
-//     while(size<targetsize && (itvec!=list.end()))
     {
-      size = size + (*itvec).objSize;//objSize is given in bytes!??
-//       i++;
-//       itvec = list.begin()+i;
+      if ( size + (*itvec).objSize < targetsize )
+      {
+        size = size + (*itvec).objSize;//objSize is given in bytes
+      }
+      else
+      {
+        clientListPerm_[currentClientID][(*itvec).objID].objValueSched -= SCHED_PRIORITY_OFFSET;
+        list->erase(itvec++);
+      }
     }
-    list->erase(itvec, list->end());
   }
 
@@ -235,12 +239,11 @@
 	  //compare listToProcess vs clientListPerm
     //if listToProcess contains new Objects, add them to clientListPerm
-	  std::map<unsigned int, objInfo>::iterator itproc;
+// 	  std::map<unsigned int, objInfo>::iterator itproc;
     std::vector<obj>::iterator itvec;
-	  std::map<unsigned int, std::map<unsigned int, objInfo> >::iterator itperm;
+// 	  std::map<unsigned int, std::map<unsigned int, objInfo> >::iterator itperm;
 // 	  std::map<unsigned int, objInfo>::iterator itpermobj;
-	  unsigned int permprio;
 	  for( itvec=list->begin(); itvec != list->end(); itvec++)
 	  {
-	    itperm = clientListPerm_.find(clientID);
+// 	    itperm = clientListPerm_.find(clientID);
 	    if ( clientListPerm_[clientID].find( (*itvec).objID) != clientListPerm_[clientID].end() )
       {
@@ -306,24 +309,33 @@
     // use boost bind here because we need to pass a memberfunction to stl sort
     sort(list->begin(), list->end(), boost::bind(&TrafficControl::priodiffer, this, clientID, _1, _2) );
-    //swappen aufgrund von creator oder ganz rausnehmen!?
+    
+    //now we check, that the creator of an object always exists on a client
+    std::vector<obj>::iterator itcreator;
     for(itvec = list->begin(); itvec != list->end(); itvec++)
     { 
-      //TODO: TODO TODO TODO
-      itproc = (listToProcess_).find((*itvec).objID);
-      if((*itproc).second.objCreatorID)
-      {
-      //vor dem child in copiedvector einfügen, wie?
-        copiedVector.insert(copiedVector.find((*itproc).first),(*itproc).second.objCreatorID);
-      }
-      else continue;
+      if ( (*itvec).objCreatorID != OBJECTID_UNKNOWN )
+      {
+        if( clientListPerm_[clientID][(*itvec).objCreatorID].objCurGS != GAMESTATEID_INITIAL )
+          continue;
+        for( itcreator = list->begin(); itcreator != list->end(); itcreator++)
+        {
+          if ( (*itcreator).objID == (*itvec).objCreatorID )
+            break;
+        }
+        // if the creator is before the object everything is fine
+        if( itcreator < itvec )
+          continue;
+        // otherwise insert the creator right before our object and delete it at the old position
+        list->insert(itvec, *itcreator);
+        list->erase(itcreator);
+      }
     }
     //end of sorting
     //now the cutting, work the same obj out in processobjectlist and copiedvector, compression rate muss noch festgelegt werden. 
-    cut(copiedVector,targetSize);
+    cut(list, targetSize);
     //diese Funktion updateClientList muss noch gemacht werden
     updateClientListTemp(list);
     //end of sorting
   }
-
 
 
Index: code/branches/network/src/network/TrafficControl.h
===================================================================
--- code/branches/network/src/network/TrafficControl.h	(revision 2348)
+++ code/branches/network/src/network/TrafficControl.h	(revision 2351)
@@ -37,4 +37,5 @@
 #include "NetworkPrereqs.h"
 #include "Synchronisable.h"
+#include "ClientInformation.h"
 #include "util/Integers.h"
 
@@ -48,6 +49,6 @@
   uint32_t objID;
   uint32_t objCreatorID;
-  int32_t objCurGS;//current GameState ID
-  int32_t objDiffGS;//difference between current and latest GameState
+  uint32_t objCurGS;//current GameState ID
+  uint32_t objDiffGS;//difference between current and latest GameState
   uint32_t objSize;
   unsigned int objValuePerm;
@@ -55,4 +56,6 @@
   objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched)
     { objID = ID; objCreatorID = creatorID; objCurGS = curGsID; objDiffGS = diffGsID; objSize = size; objValuePerm = prioperm; objValueSched = priosched; }
+  objInfo()
+    { objID = OBJECTID_UNKNOWN; objCreatorID = OBJECTID_UNKNOWN; objCurGS = GAMESTATEID_INITIAL; objDiffGS = objCurGS; objSize = 0; objValuePerm = 0; objValueSched = 0; }
 };
 
@@ -62,9 +65,16 @@
 struct obj
 {
-  unsigned int objID;
-  unsigned int objCreatorID;
-  unsigned int objSize;
+  uint32_t objID;
+  uint32_t objCreatorID;
+  uint32_t objSize;
+  uint32_t objDataOffset;
+  obj()
+    { objID = OBJECTID_UNKNOWN; objCreatorID = OBJECTID_UNKNOWN; objSize = 0; objDataOffset = 0; }
+  obj( uint32_t ID, uint32_t creatorID, uint32_t size, uint32_t offset )
+  { objID = ID; objCreatorID = creatorID; objSize = size; objDataOffset = offset; }
 };
 
+
+const unsigned int SCHED_PRIORITY_OFFSET = -5;
 
 
@@ -88,5 +98,5 @@
     *creates list (typ map) that contains objids, struct with info concerning object(objid)
     */
-    std::map<unsigned int, objInfo> listToProcess_;//copy of argument, when traffic control tool is being called, the original of this must be returned later on, eg the vector given by GS
+//     std::map<unsigned int, objInfo> listToProcess_;//copy of argument, when traffic control tool is being called, the original of this must be returned later on, eg the vector given by GS
     /**
     *permanent client list: contains client ids, object ids and objectInfos (in this order)
@@ -118,5 +128,5 @@
     *copiedVector is a copy of the given Vector by the GSmanager, on this vector all manipulations are performed
     */
-    std::vector<obj> copiedVector;
+//     std::vector<obj> copiedVector;
 
 //     void updateReferenceList(std::map<unsigned int, objInfo> *list);//done
@@ -132,5 +142,5 @@
     *evaluates Data given (vector) and produces result(->Data to be updated)
     */
-    void evaluateList(unsigned int clientID, std::vector<obj> *list);//done
+    void evaluateList(unsigned int clientID, std::vector<obj> *list);//done    
 
   protected:
@@ -146,5 +156,5 @@
     *Elements of struct i are therefore: *list[i].objID
     */
-    std::vector<obj>* processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj>* list); //gets a pointer to the vector (containing objectIDs) and sorts it
+    void processObjectList(unsigned int clientID, unsigned int gamestateID, std::vector<obj>* list); //gets a pointer to the vector (containing objectIDs) and sorts it
     //done
     void processAck(unsigned int clientID, unsigned int gamestateID);	// this function gets called when the server receives an ack from the client
Index: code/branches/network/src/network/packet/Gamestate.cc
===================================================================
--- code/branches/network/src/network/packet/Gamestate.cc	(revision 2348)
+++ code/branches/network/src/network/packet/Gamestate.cc	(revision 2351)
@@ -117,5 +117,6 @@
 
     //if(it->doSelection(id))
-    dataMap_[mem-data_]=(*it);  // save the mem location of the synchronisable data
+    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
@@ -333,7 +334,7 @@
 }
 
-Gamestate* Gamestate::doSelection(unsigned int clientID){
+Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
   assert(data_);
-  std::map<unsigned int, Synchronisable *>::iterator it;
+  std::vector<obj>::iterator it;
 
   // allocate memory for new data
@@ -342,5 +343,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
@@ -349,17 +350,20 @@
   synchronisableHeader *oldobjectheader, *newobjectheader;
   unsigned int objectOffset;
+  unsigned int objectsize;
+  Synchronisable *object;
 
   //copy in the zeros
   for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
-    oldobjectheader = (synchronisableHeader*)origdata;
+    oldobjectheader = (synchronisableHeader*)(data_ + (*it).objDataOffset);
     newobjectheader = (synchronisableHeader*)newdata;
-    unsigned int objectsize = oldobjectheader->size;
-    assert(it->second->objectID==oldobjectheader->objectID);
+    objectsize = oldobjectheader->size;
+    object = Synchronisable::getSynchronisable( (*it).objID );
+    assert(object->objectID == oldobjectheader->objectID);
     *newobjectheader = *oldobjectheader;
     objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableDate variables in the objectheader
-    if(it->second->doSelection(HEADER->id)){
+    if ( object->doSelection(HEADER->id) ){
       newobjectheader->dataAvailable=true; //TODO: probably not neccessary
       while(objectOffset<objectsize){
-        *(newdata + objectOffset)=*(origdata + objectOffset);    // copy the data
+        *(newdata + objectOffset)=*(data_ + (*it).objDataOffset + objectOffset);    // copy the data
         objectOffset++;
       }
@@ -367,5 +371,5 @@
       newobjectheader->dataAvailable=false;
       while(objectOffset<objectsize){
-        *(newdata+objectOffset)=0;    // set to 0
+        *(data_ + (*it).objDataOffset + objectOffset)=0;    // set to 0
         objectOffset++;
       }
@@ -373,5 +377,5 @@
     }
     newdata += objectsize;
-    origdata += objectsize;
+//     origdata += objectsize;
   }
   return gs;
@@ -389,5 +393,5 @@
 
   //preparations
-  std::map<unsigned int, Synchronisable *>::iterator it;
+  std::vector<obj>::iterator it;
   uint8_t *origdata, *basedata, *destdata, *ndata;
   unsigned int objectOffset, streamOffset=0;    //data offset
@@ -395,4 +399,5 @@
   synchronisableHeader *origheader;
   synchronisableHeader *destheader;
+  Synchronisable *object;
 
   origdata = GAMESTATE_START(this->data_);
@@ -404,7 +409,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
@@ -457,5 +463,5 @@
 
   //preparations
-  std::map<unsigned int, Synchronisable *>::iterator it;
+  std::vector<obj>::iterator it;
   uint8_t *origdata, *basedata, *destdata, *ndata;
   unsigned int objectOffset, streamOffset=0;    //data offset
@@ -463,4 +469,5 @@
   synchronisableHeader *origheader;
   synchronisableHeader *destheader;
+  Synchronisable *object;
 
   origdata = GAMESTATE_START(this->data_);
@@ -474,4 +481,5 @@
     origheader = (synchronisableHeader *)(origdata+streamOffset);
     destheader = (synchronisableHeader *)(destdata+streamOffset);
+    object = Synchronisable::getSynchronisable( origheader->objectID );
     bool sendData;
 
Index: code/branches/network/src/network/packet/Gamestate.h
===================================================================
--- code/branches/network/src/network/packet/Gamestate.h	(revision 2348)
+++ code/branches/network/src/network/packet/Gamestate.h	(revision 2351)
@@ -35,5 +35,7 @@
 #include "Packet.h"
 #include "network/Synchronisable.h"
+#include "network/TrafficControl.h"
 #include <map>
+#include <vector>
 #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,5 @@
     unsigned int calcGamestateSize(unsigned int id, int mode=0x0);
     void removeObject(orxonox::ObjectListIterator<Synchronisable> &it);
-    std::map<unsigned int, Synchronisable*> dataMap_;
+    std::vector<obj> dataMap_;
 };
 
