Index: code/branches/network64/src/network/CMakeLists.txt
===================================================================
--- code/branches/network64/src/network/CMakeLists.txt	(revision 2316)
+++ code/branches/network64/src/network/CMakeLists.txt	(revision 2355)
@@ -11,4 +11,5 @@
   PacketBuffer.cc
   Server.cc
+  TrafficControl.cc
   Host.cc
 )
Index: code/branches/network64/src/network/ClientInformation.cc
===================================================================
--- code/branches/network64/src/network/ClientInformation.cc	(revision 2316)
+++ code/branches/network64/src/network/ClientInformation.cc	(revision 2355)
@@ -45,4 +45,5 @@
 namespace orxonox
 {
+  
 
   ClientInformation *ClientInformation::head_=0;
Index: code/branches/network64/src/network/ClientInformation.h
===================================================================
--- code/branches/network64/src/network/ClientInformation.h	(revision 2316)
+++ code/branches/network64/src/network/ClientInformation.h	(revision 2355)
@@ -46,10 +46,9 @@
 #include <boost/thread/recursive_mutex.hpp>
 
+
 // WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE
 
 namespace orxonox
 {
-  static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
-  static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2;
 
   /**
Index: code/branches/network64/src/network/GamestateManager.cc
===================================================================
--- code/branches/network64/src/network/GamestateManager.cc	(revision 2316)
+++ code/branches/network64/src/network/GamestateManager.cc	(revision 2355)
@@ -137,6 +137,5 @@
     if(!reference)
       return 0;
-    gs = reference->doSelection(clientID);
-//     gs = new packet::Gamestate(*reference);
+    gs = reference->doSelection(clientID, 10000);
 //     gs = new packet::Gamestate(*reference);
     // save the (undiffed) gamestate in the clients gamestate map
Index: code/branches/network64/src/network/NetworkPrereqs.h
===================================================================
--- code/branches/network64/src/network/NetworkPrereqs.h	(revision 2316)
+++ code/branches/network64/src/network/NetworkPrereqs.h	(revision 2355)
@@ -57,8 +57,25 @@
 
 //-----------------------------------------------------------------------
+// Includes
+//-----------------------------------------------------------------------
+#include "util/Math.h"
+
+
+//-----------------------------------------------------------------------
 // Forward declarations
 //-----------------------------------------------------------------------
 namespace orxonox
 {
+
+// Constants definition
+
+  static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
+  static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2;
+  static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1);
+  static const unsigned int SCHED_PRIORITY_OFFSET = -5;
+
+  
+
+  
   class Client;
   class ClientConnection;
@@ -84,4 +101,6 @@
   struct QueueItem;
   struct syncData;
+  class obj;
+  class objInfo;
   namespace packet{
     class Gamestate;
Index: code/branches/network64/src/network/TrafficControl.cc
===================================================================
--- code/branches/network64/src/network/TrafficControl.cc	(revision 2355)
+++ code/branches/network64/src/network/TrafficControl.cc	(revision 2355)
@@ -0,0 +1,395 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "TrafficControl.h"
+
+#include "synchronisable/Synchronisable.h"
+
+#include <cassert>
+#include <boost/bind.hpp>
+
+namespace orxonox {
+
+  objInfo::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::objInfo()
+  { 
+    objID = OBJECTID_UNKNOWN; objCreatorID = OBJECTID_UNKNOWN; objCurGS = GAMESTATEID_INITIAL; objDiffGS = objCurGS; objSize = 0; objValuePerm = 0; objValueSched = 0; 
+  }
+  
+  
+  
+  obj::obj()
+  { 
+    objID = OBJECTID_UNKNOWN; objCreatorID = OBJECTID_UNKNOWN; objSize = 0; objDataOffset = 0; 
+  }
+  obj::obj( uint32_t ID, uint32_t creatorID, uint32_t size, uint32_t offset )
+  {
+    objID = ID; objCreatorID = creatorID; objSize = size; objDataOffset = offset;
+  }
+  
+/**
+*Initializing protected members
+*/
+	TrafficControl *TrafficControl::instance_=0;
+	
+	/**
+	* @brief Constructor: assures that only one reference will be created and sets the pointer
+	*/
+	TrafficControl::TrafficControl()
+	{
+	  assert(instance_==0);
+	  instance_=this;
+    targetSize = 1000;//5000bytes
+	}
+	
+	/**
+	* @brief Destructor: resets the instance pointer to 0
+	*/
+	TrafficControl::~TrafficControl()
+	{ 
+	  //was macht das genau? da instance ja gleich this ist im moment
+	  instance_=0;
+	  //muss ich alles deallozieren was ich im constructor aufgebaut habe?
+	}
+
+/**
+*Definition of public members
+*/
+
+  /**
+          *eigener sortieralgorithmus
+  */
+//   bool TrafficControl::priodiffer(obj i, obj j)
+//   {
+//     std::map<unsigned int, objInfo>::iterator iti;
+//     std::map<unsigned int, objInfo>::iterator itj;
+//     iti=listToProcess_.find(i.objID);
+//     itj=listToProcess_.find(j.objID);
+//     return iti->second.objValuePerm < itj->second.objValuePerm;
+//   }
+  
+  /**
+  * eigener sortieralgorithmus
+  */
+  bool TrafficControl::priodiffer(uint32_t clientID, obj i, obj j)
+  {
+    assert(clientListPerm_.find(clientID) != clientListPerm_.end());  //make sure the client exists in our list
+    assert(clientListPerm_[clientID].find(i.objID) != clientListPerm_[clientID].end()); // make sure the object i is in the client list
+    assert(clientListPerm_[clientID].find(j.objID) != clientListPerm_[clientID].end()); // make sure the object j is in the client list
+    
+    int prio1 = clientListPerm_[clientID][i.objID].objValuePerm + clientListPerm_[clientID][i.objID].objValueSched;
+    int prio2 = clientListPerm_[clientID][j.objID].objValuePerm + clientListPerm_[clientID][j.objID].objValueSched;
+//     int prio1 = clientListPerm_[clientID][i.objID].objID;
+//     int prio2 = clientListPerm_[clientID][j.objID].objID;
+    // NOTE: smaller priority is better
+    return prio1 < prio2;
+  }
+
+
+	void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj> *list)
+	{
+// 	  copiedVector = *list;
+	  currentClientID=clientID;
+	  currentGamestateID=gamestateID;
+	  evaluateList(clientID, list);
+	  //list hatte vorher ja vielmehr elemente, nach zuweisung nicht mehr... speicherplatz??
+// 	  *list=copiedVector;
+    //später wird copiedVector ja überschrieben, ist das ein problem für list-dh. für gamestatemanager?
+	  return;
+	}
+	
+	void TrafficControl::processAck(unsigned int clientID, unsigned int gamestateID)
+	{
+	  std::list<obj>::iterator itvec;  // iterator to iterate through the acked objects
+    
+    //assertions to make sure the maps already exist
+    assert(clientListTemp_.find(clientID) != clientListTemp_.end() );
+    assert(clientListPerm_.find(clientID) != clientListPerm_.end() );
+	  assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() );
+    
+    for(itvec = clientListTemp_[clientID][gamestateID].begin(); itvec != clientListTemp_[clientID][gamestateID].end(); itvec++)
+	  {
+      if(clientListPerm_[clientID].find((*itvec).objID) != clientListPerm_[clientID].end()) // check whether the obj already exists in our lists
+      {
+        clientListPerm_[clientID][(*itvec).objID].objID = gamestateID;
+      }
+      else
+      {
+        clientListPerm_[clientID][(*itvec).objID].objCurGS = gamestateID;
+        clientListPerm_[clientID][(*itvec).objID].objID = (*itvec).objID;
+        clientListPerm_[clientID][(*itvec).objID].objCreatorID = (*itvec).objCreatorID;
+        clientListPerm_[clientID][(*itvec).objID].objSize = (*itvec).objSize;
+      }
+	  }
+	   // remove temporary list (with acked objects) from the map
+    clientListTemp_[clientID].erase( clientListTemp_[clientID].find(gamestateID) );
+	}
+
+/**
+*Definition of private members
+*/
+	
+	
+	/**
+	*copyList gets list of Gamestate Manager and turns it to *listToProcess
+	*/
+// 	void TrafficControl::copyList(std::list<obj> *list)
+// 	{
+// 	  std::list<obj>::iterator itvec;
+// 	  for(itvec = (*list).begin(); itvec != (*list).end(); itvec++)
+// 	  {
+// 	    objInfo objectA;
+// 	    objectA.objCreatorID=(*itvec).objCreatorID;
+// 	    objectA.objSize = (*itvec).objSize;
+// 	    listToProcess_.insert(std::pair<currentClientID, map<(*itvec).objID,objectA>>);//unsicher: ob map<...> so richtig ist
+// 	  }
+// 	}
+	/**
+	*updateReferenceList compares the sent list by GSmanager with the current *reference list and updates it.
+	*returns void
+	*/
+// 	void TrafficControl::updateReferenceList(std::map<unsigned int, objInfo> *list)
+// 	{
+// 	  std::map<unsigned int, Synchronisable*>::iterator itref;
+// 	  std::map<unsigned int, objInfo>::iterator itproc;
+// 	  for(itproc=listToProcess_.begin(); itproc != listToProcess_.end(); itproc++)
+// 	  {
+// 	    //itproc->first=objectid that is looked for
+// 	    if(referenceList_->find(itproc->first))
+// 	    {
+// 	      continue;
+// 	    }
+// 	    else
+// 	    {
+// 	      (*referenceList_).insert(pair<unsigned int,          Synchronisable*>((*itproc).first,Synchronisable::getSynchronisable((*itproc).first)));//important: how to get adress of an object!
+// 	      insertinClientListPerm(currentClientID,itproc->first,itproc->second);
+// 	    }
+// 	  }
+// 	}
+	/**
+	*updateClientListPerm
+	*returns void
+	*/
+	void TrafficControl::insertinClientListPerm(unsigned int clientID, obj objinf)
+	{ 
+	  std::map<unsigned int,std::map<unsigned int, objInfo> >::iterator itperm;//iterator clientListPerm over clientIDs
+// 	  itperm = (clientListPerm_).find(clientID);
+// 	  assert(itperm != clientListPerm_.end() );
+    unsigned int gsid=GAMESTATEID_INITIAL, gsdiff=currentGamestateID, prioperm=Synchronisable::getSynchronisable(objinf.objID)->getPriority(), priomom=0;
+    clientListPerm_[clientID][objinf.objID] = objInfo(objinf.objID, objinf.objCreatorID,gsid,gsdiff, objinf.objSize,prioperm,priomom);
+// 	  itperm->second.insert(std::pair<unsigned int, objInfo>(objid,objinf));
+//     permObjPrio_.insert(objid, objinf.objValuePerm);
+	}
+	
+  /**
+  * updateClientListTemp
+  * takes the shortened list which will be sent to the gsmanager and puts the *info into clientListTemp
+  */	
+  void TrafficControl::updateClientListTemp(std::list<obj> *list)
+  {
+    clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(*list);
+//     std::list<obj>::iterator itvec;
+//     std::map<unsigned int,std::map<unsigned int, obj> >::iterator ittemp;
+//     std::map<unsigned int, obj>::iterator ittempgs;
+//     ittemp = clientListTemp_.find(currentClientID);
+//     ittempgs = (*ittemp).find(currentGamestateID);
+//     for(itvec = list.begin(); itvec!=list.end(), itvec++)
+//     {
+//       ittempgs.insert(itvec);
+//     }
+  }
+
+  /**
+  *cut
+  *takes the current list that has to be returned to the gsmanager and shortens it in criteria of bandwidth of clientID(XY)
+  */
+  void TrafficControl::cut(std::list<obj> *list, unsigned int targetsize)
+  {
+    unsigned int size=0;
+    std::list<obj>::iterator itvec;
+    assert(!list->empty());
+    itvec = list->begin();
+    for(itvec = list->begin(); itvec != list->end() && size<targetsize; itvec++)
+    {
+      assert( (*itvec).objSize < 1000);
+      if ( size + (*itvec).objSize < targetsize )
+      {
+        size += (*itvec).objSize;//objSize is given in bytes
+      }
+      else
+      {
+        clientListPerm_[currentClientID][(*itvec).objID].objValueSched -= SCHED_PRIORITY_OFFSET;
+        list->erase(itvec++);
+      }
+    }
+    assert(!list->empty());
+  }
+
+
+	/**
+	*evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this.
+	*/
+	void TrafficControl::evaluateList(unsigned int clientID, std::list<obj> *list)
+	{
+	  //copyList(list);
+	
+	  //now the sorting
+	
+	  //compare listToProcess vs clientListPerm
+    //if listToProcess contains new Objects, add them to clientListPerm
+// 	  std::map<unsigned int, objInfo>::iterator itproc;
+    std::list<obj>::iterator itvec;
+// 	  std::map<unsigned int, std::map<unsigned int, objInfo> >::iterator itperm;
+// 	  std::map<unsigned int, objInfo>::iterator itpermobj;
+	  for( itvec=list->begin(); itvec != list->end(); itvec++)
+	  {
+// 	    itperm = clientListPerm_.find(clientID);
+	    if ( clientListPerm_[clientID].find( (*itvec).objID) != clientListPerm_[clientID].end() )
+      {
+        // we already have the object in our map
+        //obj bleibt in liste und permanente prio wird berechnet
+        clientListPerm_[clientID][(*itvec).objID].objDiffGS = currentGamestateID - clientListPerm_[clientID][(*itvec).objID].objCurGS;
+//         ((*itpermobj).second).objDiffGS = ((*itpermobj).second).objCurGS - currentGamestateID;
+//         permprio = clientListPerm_[clientID][(*itproc).first].objValuePerm;
+//         itpermprio = (permObjPrio_).find((*itproc).first);
+//         ((*itpermobj).second).objValuePerm = ((*itpermobj).second).objDiffGS * (*itpermprio).second;
+        continue;//check next objId
+      }
+      else
+      {
+        // insert the object into clientListPerm
+        insertinClientListPerm(clientID,*itvec);
+//         itpermobj=(*itperm).find((*itproc).first)
+//         ((*itpermobj).second).objDiffGS = ((*itpermobj).second).objCurGS - currentGamestateID;
+//         itpermprio = (permObjPrio_).find((*itproc).first);
+//         ((*itpermobj).second).objValuePerm = ((*itpermobj).second).objDiffGS * (*itpermprio).second;
+        continue;//check next objId
+      }
+    }
+	  //end compare listToProcess vs clientListPerm
+	
+    //listToProc vs clientListTemp
+    //TODO: uncomment it again and change some things
+    /*
+    std::map<unsigned int, std::map<unsigned int, unsigned int> >::iterator ittemp;
+    std::map<unsigned int, unsigned int>::iterator ittempgs;
+    for( itproc=listToProcess_.begin(); itproc != listToProcess_.end();itproc++)
+    {
+      ittemp = clientListTemp_->find(currentClientID);
+      if( ittempgs = (*ittemp).find(currentGamestateID))
+      {
+        if((*itproc).first == (*ittempgs).find((*itproc).first))//ja, dann ist objekt schon in der zu sendenden liste-muss nicht nochmal gesendet werden
+        {
+          (listToProcess_).erase (itproc);
+        }
+        else
+          continue;
+      }
+      else
+        continue;
+    }*/
+    //end listToProc vs clientListTemp
+    
+    //TODO: check whether we need this, cause i don't think so.
+    //listToProcess contains obj to send now, and since we give gsmanager the copiedlist and not listToProcess shorten copiedlist therefor too.
+    /*std::list<obj>::iterator itvec;
+    for(itvec = copiedVector.begin(); itvec != copiedVector.end(); itvec++)
+    {
+      if ( listToProcess_.find(itvec->objID) )
+      {
+        continue;//therefore object wasnt thrown out yet and has to be sent back to gsmanager
+      }
+      else
+      {
+        copiedVector.remove(itvec);
+      }
+    }*/
+    //sort copied list aufgrund der objprioperm in clientlistperm
+    // use boost bind here because we need to pass a memberfunction to stl sort
+    list->sort(boost::bind(&TrafficControl::priodiffer, this, clientID, _1, _2) );
+    
+    //now we check, that the creator of an object always exists on a client
+    printList(list, clientID);
+    std::list<obj>::iterator itcreator;
+    for(itvec = list->begin(); itvec != list->end(); itvec++)
+    { 
+      fixCreatorDependencies(itvec, list, clientID);
+    }
+    //end of sorting
+    //now the cutting, work the same obj out in processobjectlist and copiedlist, compression rate muss noch festgelegt werden. 
+    cut(list, targetSize);
+    printList(list, clientID);
+    //diese Funktion updateClientList muss noch gemacht werden
+    updateClientListTemp(list);
+    //end of sorting
+  }
+
+  void TrafficControl::printList(std::list<obj> *list, unsigned int clientID)
+  {
+    std::list<obj>::iterator it;
+    COUT(0) << "=========== Objectlist ===========" << endl;
+    for( it=list->begin(); it!=list->end(); it++)
+      COUT(0) << "ObjectID: " << (*it).objID << " creatorID: " << (*it).objCreatorID << " Priority: " << clientListPerm_[clientID][(*it).objID].objValuePerm + clientListPerm_[clientID][(*it).objID].objValueSched << endl;
+  }
+  
+  void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj> *list, unsigned int clientID)
+  {
+    if ( (*it1).objCreatorID == OBJECTID_UNKNOWN )
+      return;
+    if( clientListPerm_[clientID][(*it1).objCreatorID].objCurGS != GAMESTATEID_INITIAL )
+      return;
+    std::list<obj>::iterator it2, it3=it1;
+    for( it2 = ++it3; it2 != list->end(); it2++ )
+    {
+      if( (*it2).objID == (*it1).objCreatorID )
+      {
+        it3 = list->insert(it1, *it2); //insert creator before it1
+        list->erase(it2);
+//         printList(list, clientID);
+        fixCreatorDependencies( it3, list, clientID );
+        break;
+      }
+    }
+  }
+
+
+/*
+void bvlabla(list *a){
+//sort a
+list *cache;
+cache = new list<unsigned int>(*a);
+return a;
+}
+*/
+
+
+}//namespace network
Index: code/branches/network64/src/network/TrafficControl.h
===================================================================
--- code/branches/network64/src/network/TrafficControl.h	(revision 2355)
+++ code/branches/network64/src/network/TrafficControl.h	(revision 2355)
@@ -0,0 +1,168 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+#ifndef NETWORK_TRAFFICCONTROL_H
+#define NETWORK_TRAFFICCONTROL_H
+
+#include "NetworkPrereqs.h"
+
+#include <string>
+#include <list>
+#include <map>
+#include <utility>
+#include <algorithm>
+#include "util/Integers.h"
+
+namespace orxonox {
+
+
+  /**
+   *a list of objects of this type will be given by the Server's Gamestate Manager
+   */
+  class objInfo
+  {
+    public:
+      uint32_t objID;
+      uint32_t objCreatorID;
+      uint32_t objCurGS;//current GameState ID
+      uint32_t objDiffGS;//difference between current and latest GameState
+      uint32_t objSize;
+      unsigned int objValuePerm;
+      unsigned int objValueSched;
+      objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched);
+      objInfo();
+  };
+
+/**
+   *a list of objects of this type will be given by the Server's Gamestate Manager
+ */
+  class obj
+  {
+    public:
+      uint32_t objID;
+      uint32_t objCreatorID;
+      uint32_t objSize;
+      uint32_t objDataOffset;
+      obj();
+      obj( uint32_t ID, uint32_t creatorID, uint32_t size, uint32_t offset );
+  };
+  
+
+
+
+/**
+*
+*/
+class TrafficControl{
+  private:
+
+    /**
+    *Lists that will be used:
+    *listToProcess
+    *clientListPerm
+    *clientListTemp
+    *referenceList
+    *permObjPrio list
+    *schedObjPrio
+    */
+    //start: lists to be used
+    /**
+    *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 list given by GS
+    /**
+    *permanent client list: contains client ids, object ids and objectInfos (in this order)
+    */
+    std::map<unsigned int, std::map<unsigned int, objInfo > > clientListPerm_;
+    //has to be created with constructor and then needs to be updated by evaluateList().
+
+    /**
+    *temporary client list: contains client ids, gamestate ids and object ids (in this order)
+    */
+    std::map<unsigned int, std::map<unsigned int, std::list<obj> > > clientListTemp_;
+    /**
+    *static priority list: contains obj id, basic priority (in this order)
+    */
+//     std::map<unsigned int, unsigned int> permObjPrio_;
+    /**
+    *dynamic priority list: contains obj id, dynamic priority (eg scheduled) (in this order)
+    */
+//     std::map<unsigned int, unsigned int> schedObjPrio_;
+    //end: lists to be used
+
+    /**updateReferenceList
+    *currentGamestateID and currentClientID will be defined as soon as TrafficControl is being called by Server
+    */
+    unsigned int currentGamestateID;
+    unsigned int currentClientID;
+    unsigned int targetSize;
+    /**
+    *copiedVector is a copy of the given Vector by the GSmanager, on this list all manipulations are performed
+    */
+//     std::list<obj> copiedVector;
+
+//     void updateReferenceList(std::map<unsigned int, objInfo> *list);//done
+    void insertinClientListPerm(unsigned int clientID, obj objinf);//done
+    /**
+    *creates listToProcess, which can be easialy compared with other lists
+    */
+//     void copyList(std::list<obj> *list);//done
+    
+    void cut(std::list<obj> *list, unsigned int targetsize);
+    void updateClientListTemp(std::list<obj> *list);//done
+    /**
+    *evaluates Data given (list) and produces result(->Data to be updated)
+    */
+    void evaluateList(unsigned int clientID, std::list<obj> *list);//done    
+
+  protected:
+    static TrafficControl *instance_;
+
+  public:
+    TrafficControl();
+    virtual ~TrafficControl();
+    /**
+    *is being used by GSManager from Server:
+    *list contains: ObjIds, CreatorIds, Size (in this order) from Client XY 
+    *Elements of list are accessed by *list[i]
+    *Elements of struct i are therefore: *list[i].objID
+    */
+    void processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>* list); //gets a pointer to the list (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
+    //done
+    void deleteObject(unsigned int objectID);				// this function gets called when an object has been deleted (in order to clean up lists and maps)
+    
+    bool priodiffer(uint32_t clientID, obj i, obj j);
+    void printList(std::list<obj> *list, unsigned int clientID);
+    void fixCreatorDependencies(std::list<obj>::iterator it, std::list<obj> *list, unsigned int clientID);
+};
+
+}
+
+#endif
+
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_;
 };
 
Index: code/branches/network64/src/network/synchronisable/Synchronisable.cc
===================================================================
--- code/branches/network64/src/network/synchronisable/Synchronisable.cc	(revision 2316)
+++ code/branches/network64/src/network/synchronisable/Synchronisable.cc	(revision 2355)
@@ -53,5 +53,4 @@
 namespace orxonox
 {
-
 
   std::map<uint32_t, Synchronisable *> Synchronisable::objectMap_;
Index: code/branches/network64/src/network/synchronisable/Synchronisable.h
===================================================================
--- code/branches/network64/src/network/synchronisable/Synchronisable.h	(revision 2316)
+++ code/branches/network64/src/network/synchronisable/Synchronisable.h	(revision 2355)
@@ -53,5 +53,4 @@
 namespace orxonox
 {
-  static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1);
 
   namespace objectDirection{
@@ -92,5 +91,8 @@
 
     inline uint32_t getObjectID(){return objectID;}
+    inline unsigned int getCreatorID(){return creatorID;}
     inline uint32_t getClassID(){return classID;}
+    inline unsigned int getPriority(){ return objectFrequency_;}
+
   protected:
     Synchronisable(BaseObject* creator);
@@ -99,5 +101,5 @@
     template <class T> void unregisterVariable(T& var);
     void setObjectMode(uint8_t mode);
-    void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }
+    void setObjectPriority(unsigned int freq){ objectFrequency_ = freq; }
 
 
Index: code/branches/network64/src/network/synchronisable/SynchronisableSpecialisations.cc
===================================================================
--- code/branches/network64/src/network/synchronisable/SynchronisableSpecialisations.cc	(revision 2316)
+++ code/branches/network64/src/network/synchronisable/SynchronisableSpecialisations.cc	(revision 2355)
Index: code/branches/network64/src/network/synchronisable/SynchronisableVariable.cc
===================================================================
--- code/branches/network64/src/network/synchronisable/SynchronisableVariable.cc	(revision 2316)
+++ code/branches/network64/src/network/synchronisable/SynchronisableVariable.cc	(revision 2355)
