Index: code/trunk/src/network/CMakeLists.txt
===================================================================
--- code/trunk/src/network/CMakeLists.txt	(revision 3301)
+++ code/trunk/src/network/CMakeLists.txt	(revision 3304)
@@ -31,5 +31,4 @@
   NetworkFunction.cc
   Host.cc
-  PacketBuffer.cc
   Server.cc
   ServerConnection.cc
Index: code/trunk/src/network/ClientInformation.h
===================================================================
--- code/trunk/src/network/ClientInformation.h	(revision 3301)
+++ code/trunk/src/network/ClientInformation.h	(revision 3304)
@@ -87,4 +87,5 @@
     static ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
     static ClientInformation *getBegin(){return head_;}
+    static bool hasClients(){ return ClientInformation::head_!=0; }
 
     bool setSynched(bool s);
Index: code/trunk/src/network/Connection.cc
===================================================================
--- code/trunk/src/network/Connection.cc	(revision 3301)
+++ code/trunk/src/network/Connection.cc	(revision 3304)
@@ -31,5 +31,4 @@
 #include <cassert>
 #include <enet/enet.h>
-#include <OgreTimer.h>
 #include "packet/Packet.h"
 
@@ -77,7 +76,6 @@
     
     assert(this->host_);
-    Ogre::Timer timer;
 
-    while( timer.getMilliseconds()<NETWORK_MAX_QUEUE_PROCESS_TIME && enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+    while( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
     {
       switch(event.type){
Index: code/trunk/src/network/GamestateClient.cc
===================================================================
--- code/trunk/src/network/GamestateClient.cc	(revision 3301)
+++ code/trunk/src/network/GamestateClient.cc	(revision 3304)
@@ -52,4 +52,9 @@
 
   GamestateClient::~GamestateClient() {
+      std::map<unsigned int, packet::Gamestate *>::iterator it;
+      for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it )
+          delete (*it).second;
+      if( this->tempGamestate_ )
+          delete this->tempGamestate_;
   }
 
Index: code/trunk/src/network/GamestateClient.h
===================================================================
--- code/trunk/src/network/GamestateClient.h	(revision 3301)
+++ code/trunk/src/network/GamestateClient.h	(revision 3304)
@@ -73,5 +73,4 @@
     std::map<unsigned int, packet::Gamestate *> gamestateMap_;
     packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue
-    unsigned char *shipCache_;
 
   };
Index: code/trunk/src/network/GamestateManager.cc
===================================================================
--- code/trunk/src/network/GamestateManager.cc	(revision 3301)
+++ code/trunk/src/network/GamestateManager.cc	(revision 3304)
@@ -42,6 +42,10 @@
 
 #include <cassert>
+#include <queue>
+// #include <boost/thread/mutex.hpp>
 
 #include "util/Debug.h"
+#include "core/Executor.h"
+#include "core/ThreadPool.h"
 #include "ClientInformation.h"
 #include "packet/Acknowledgement.h"
@@ -56,4 +60,6 @@
   {
     trafficControl_ = new TrafficControl();
+//     threadMutex_ = new boost::mutex();
+//     threadPool_ = new ThreadPool();
   }
 
@@ -61,8 +67,17 @@
   {
     if( this->reference )
-      delete this->reference;
-    for( std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.begin(); it != gamestateQueue.end(); it++ )
+        delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it;
+    for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
       delete (*it).second;
-    delete trafficControl_;
+    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1;
+    std::map<unsigned int, packet::Gamestate*>::iterator it2;
+    for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1 )
+    {
+      for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
+        delete (*it2).second;
+    }
+    delete this->trafficControl_;
+//     delete this->threadMutex_;
+//     delete this->threadPool_;
   }
 
@@ -84,4 +99,6 @@
 
   bool GamestateManager::processGamestates(){
+    if( this->gamestateQueue.empty() )
+        return true;
     std::map<unsigned int, packet::Gamestate*>::iterator it;
     // now push only the most recent gamestates we received (ignore obsolete ones)
@@ -109,30 +126,79 @@
     return true;
   }
-
-
-  packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) {
+  
+  void GamestateManager::sendGamestates()
+  {
+    ClientInformation *temp = ClientInformation::getBegin();
+    std::queue<packet::Gamestate*> clientGamestates;
+    while(temp != NULL){
+      if( !(temp->getSynched()) ){
+        COUT(5) << "Server: not sending gamestate" << std::endl;
+        temp=temp->next();
+        if(!temp)
+          break;
+        continue;
+      }
+      COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
+      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
+      int cid = temp->getID(); //get client id
+      
+      unsigned int gID = temp->getGamestateID();
+      if(!reference)
+        return;
+      
+      packet::Gamestate *client=0;
+      if(gID != GAMESTATEID_INITIAL){
+        assert(gamestateMap_.find(cid)!=gamestateMap_.end());
+        std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID);
+        if(it!=gamestateMap_[cid].end())
+        {
+          client = it->second;
+        }
+      }
+      
+      clientGamestates.push(0);
+      finishGamestate( cid, &clientGamestates.back(), client, reference );
+      //FunctorMember<GamestateManager>* functor = 
+//       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate) );
+//       executor->setObject(this);
+//       executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
+//       (*static_cast<Executor*>(executor))();
+//       this->threadPool_->passFunction( executor, true );
+//       (*functor)( cid, &(clientGamestates.back()), client, reference );
+      
+      temp = temp->next();
+    }
+    
+//     threadPool_->synchronise();
+    
+    while( !clientGamestates.empty() )
+    {
+      if(clientGamestates.front())
+        clientGamestates.front()->send();
+      clientGamestates.pop();
+    }
+  }
+
+
+  void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
     //why are we searching the same client's gamestate id as we searched in
     //Server::sendGameState?
-    packet::Gamestate *gs;
-    unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID();
-    if(!reference)
-      return 0;
-    gs = reference->doSelection(clientID, 10000);
     // save the (undiffed) gamestate in the clients gamestate map
-    gamestateMap_[clientID][gs->getID()]=gs;
     //chose wheather the next gamestate is the first or not
-    packet::Gamestate *client=0;
-    if(gID != GAMESTATEID_INITIAL){
-      assert(gamestateMap_.find(clientID)!=gamestateMap_.end());
-      std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[clientID].find(gID);
-      if(it!=gamestateMap_[clientID].end())
-      {
-        client = it->second;
-      }
-    }
-    if(client){
+    
+    packet::Gamestate *gs = gamestate->doSelection(clientID, 20000);
+//     packet::Gamestate *gs = new packet::Gamestate(*gamestate);
+//     packet::Gamestate *gs = new packet::Gamestate();
+//     gs->collectData( id_, 0x1 );
+//     this->threadMutex_->lock();
+    gamestateMap_[clientID][gamestate->getID()]=gs;
+//     this->threadMutex_->unlock();
+    
+    if(base)
+    {
+        
 //       COUT(3) << "diffing" << std::endl;
 //       packet::Gamestate* gs1  = gs;
-      packet::Gamestate *diffed = gs->diff(client);
+      packet::Gamestate *diffed = gs->diff(base);
       //packet::Gamestate *gs2 = diffed->undiff(gs);
 //       assert(*gs == *gs2);
@@ -143,15 +209,17 @@
     }
     else{
-//       COUT(3) << "not diffing" << std::endl;
       gs = new packet::Gamestate(*gs);
     }
+    
+    
     bool b = gs->compressData();
     assert(b);
-    COUT(4) << "sending gamestate with id " << gs->getID();
-    if(gs->isDiffed())
-    COUT(4) << " and baseid " << gs->getBaseID() << endl;
-    else
-    COUT(4) << endl;
-    return gs;
+//     COUT(4) << "sending gamestate with id " << gs->getID();
+//     if(gamestate->isDiffed())
+//     COUT(4) << " and baseid " << gs->getBaseID() << endl;
+//     else
+//     COUT(4) << endl;
+    gs->setClientID(clientID);
+    *destgamestate = gs;
   }
 
@@ -175,5 +243,5 @@
 
     assert(curid==GAMESTATEID_INITIAL || curid<gamestateID);
-    COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
+    COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
     std::map<unsigned int, packet::Gamestate*>::iterator it;
     for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){
Index: code/trunk/src/network/GamestateManager.h
===================================================================
--- code/trunk/src/network/GamestateManager.h	(revision 3301)
+++ code/trunk/src/network/GamestateManager.h	(revision 3304)
@@ -45,4 +45,5 @@
 #include <map>
 #include "GamestateHandler.h"
+#include "core/CorePrereqs.h"
 
 namespace orxonox
@@ -73,5 +74,7 @@
     bool processGamestates();
     bool update();
-    packet::Gamestate *popGameState(unsigned int clientID);
+    void sendGamestates();
+//     packet::Gamestate *popGameState(unsigned int clientID);
+    void finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
 
     bool getSnapshot();
@@ -79,14 +82,14 @@
     bool ack(unsigned int gamestateID, unsigned int clientID);
     void removeClient(ClientInformation *client);
-    private:
+  private:
     bool processGamestate(packet::Gamestate *gs);
 
     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
-    //std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate*
-    //std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate
     std::map<unsigned int, packet::Gamestate*> gamestateQueue;
     packet::Gamestate *reference;
     TrafficControl *trafficControl_;
     unsigned int id_;
+//     boost::mutex* threadMutex_;
+    ThreadPool*   /*thread*/Pool_;
   };
 
Index: code/trunk/src/network/Host.cc
===================================================================
--- code/trunk/src/network/Host.cc	(revision 3301)
+++ code/trunk/src/network/Host.cc	(revision 3304)
@@ -74,19 +74,4 @@
 }
 
-
-// bool Host::chat(std::string& message){
-//   if(!instance_)
-//     return false;
-//   packet::Chat *c = new packet::Chat(message, getPlayerID());
-//   return instance_->sendChat(c);
-// }
-
-// bool Host::receiveChat(packet::Chat *message, unsigned int clientID){
-//   if(instance_)
-//     return instance_->processChat(message, clientID);
-//   else
-//     return false;
-// }
-
 /**
  * This function returns the ID of the player
Index: code/trunk/src/network/NetworkFunction.cc
===================================================================
--- code/trunk/src/network/NetworkFunction.cc	(revision 3301)
+++ code/trunk/src/network/NetworkFunction.cc	(revision 3304)
@@ -56,4 +56,11 @@
   
   
+  void NetworkFunctionBase::destroyAllNetworkFunctions()
+  {
+    std::map<std::string, NetworkFunctionBase*>::iterator it;
+    for( it=NetworkFunctionBase::nameMap_.begin(); it!=NetworkFunctionBase::nameMap_.end(); ++it )
+      delete it->second;
+  }
+  
   
   NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p):
Index: code/trunk/src/network/NetworkFunction.h
===================================================================
--- code/trunk/src/network/NetworkFunction.h	(revision 3301)
+++ code/trunk/src/network/NetworkFunction.h	(revision 3304)
@@ -37,4 +37,5 @@
 #include <string>
 #include <boost/preprocessor/cat.hpp>
+#include <boost/static_assert.hpp>
 
 #include "core/OrxonoxClass.h"
@@ -46,7 +47,7 @@
 {
 
-#ifdef ORXONOX_COMPILER_GCC
+#if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32)
 static const unsigned int MAX_FUNCTION_POINTER_SIZE = 8;
-#else //ORXONOX_COMPILER_GCC
+#else
 static const unsigned int MAX_FUNCTION_POINTER_SIZE = 16;
 #endif //ORXONOX_COMPILER_GCC
@@ -57,5 +58,5 @@
   bool operator<(const NetworkFunctionPointer& b) const
   {
-#ifdef ORXONOX_COMPILER_GCC
+#if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32)
     return pointer[0]<b.pointer[0] ? true : pointer[1]<b.pointer[1];
 #else //ORXONOX_COMPILER_GCC
@@ -80,4 +81,6 @@
     
     static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
+    
+    static void destroyAllNetworkFunctions();
     
   protected:
@@ -193,5 +196,6 @@
 template<class T> inline void copyPtr( T ptr, NetworkFunctionPointer& destptr)
 {
-  memset((uint8_t*)&destptr + sizeof(T), 0, sizeof(NetworkFunctionPointer)-sizeof(T));
+  if( sizeof(NetworkFunctionPointer)-sizeof(T) > 0)
+    memset((uint8_t*)&destptr + sizeof(T), 0, sizeof(NetworkFunctionPointer)-sizeof(T));
   T p2 = ptr;
   memcpy( &destptr, &p2, sizeof(T) );
@@ -202,4 +206,5 @@
 template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name )
 {
+  BOOST_STATIC_ASSERT( sizeof(T)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for static functions than defined above
   NetworkFunctionPointer destptr;
   copyPtr( ptr, destptr );
@@ -210,4 +215,5 @@
 template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, const std::string& name )
 {
+  BOOST_STATIC_ASSERT( sizeof(PT)<=sizeof(NetworkFunctionPointer) ); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above
   NetworkFunctionPointer destptr;
   copyPtr( ptr, destptr );
Index: code/trunk/src/network/NetworkPrereqs.h
===================================================================
--- code/trunk/src/network/NetworkPrereqs.h	(revision 3301)
+++ code/trunk/src/network/NetworkPrereqs.h	(revision 3304)
@@ -102,5 +102,4 @@
   template <class T> class NetworkMemeberFunction;
   struct NetworkFunctionPointer;
-  class PacketBuffer;
   class Server;
   class ServerConnection;
Index: code/trunk/src/network/PacketBuffer.cc
===================================================================
--- code/trunk/src/network/PacketBuffer.cc	(revision 3301)
+++ 	(revision )
@@ -1,146 +1,0 @@
-/*
- *   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, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-// C++ PacketBuffer
-// d
-// Author Oliver Scheuss
-
-#include "PacketBuffer.h"
-
-//#include <iostream>
-#include <boost/thread/recursive_mutex.hpp>
-
-namespace orxonox
-{
-  static boost::recursive_mutex packetBuffer_mutex_g;
-
-  PacketBuffer::PacketBuffer() {
-    closed=false;
-    first=NULL;
-    last=NULL;
-  }
-  //this is needed in order to make the packetbuffer threadsafe
-
-
-  bool PacketBuffer::push(ENetEvent *ev) {
-    boost::recursive_mutex::scoped_lock lock(packetBuffer_mutex_g);
-    //std::cout << "event size inside packetbuffer " << ev->packet->dataLength << std::endl;
-    //   if(closed)
-    //     return false;
-    // first element?
-    if(first==NULL){
-      first=new QueueItem;
-      last=first;
-      last->next=NULL;
-      // change this!!!!!!!  ---- we are not doing stl so we won't change this
-      last->event = ev;
-      //last->address = ev->peer->address;
-    } else {
-      //insert a new element at the bottom
-      last->next = new QueueItem;
-      last=last->next;
-      // initialize last->next
-      last->next=NULL;
-      // save the packet to the new element
-      last->event = ev;
-      //last->address = ev->peer->address;
-    }
-    lock.unlock();
-    return true;
-  }
-
-  //returns the first element in the list without deleting it but
-  //moving first pointer to next element
-  /*ENetPacket *PacketBuffer::pop() {
-    ENetAddress address;
-    return pop(address);
-  }*/
-  
-  ENetEvent *PacketBuffer::pop(){
-    boost::recursive_mutex::scoped_lock lock(packetBuffer_mutex_g);
-    //std::cout << "packetbuffer pop(address)" << std::endl;
-    if(first!=NULL /*&& !closed*/){
-      QueueItem *temp = first;
-      // get packet
-      ENetEvent *ev=first->event;
-      //address = first->address;
-      // remove first element
-      first = first->next;
-      delete temp;
-      lock.unlock();
-      //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
-      return ev;
-    } else{
-      lock.unlock();
-      return NULL;
-    }
-  }
-
-  /*ENetPacket *PacketBuffer::pop(ENetAddress &address) {
-    boost::recursive_mutex::scoped_lock lock(packetBuffer_mutex_g);
-    //std::cout << "packetbuffer pop(address)" << std::endl;
-    if(first!=NULL ){
-      QueueItem *temp = first;
-      // get packet
-      ENetPacket *pck=first->event->packet;
-      address = first->event->peer->address;
-      // remove first element
-      first = first->next;
-      delete temp;
-      lock.unlock();
-      //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
-      return pck;
-    } else{
-      lock.unlock();
-      return NULL;
-    }
-  }*/
-
-  bool PacketBuffer::isEmpty() {
-    return (first==NULL);
-  }
-
-  void PacketBuffer::print() {
-    QueueItem *temp=first;
-    while(temp!=NULL){
-      //    std::cout << temp->packet->data << std::endl;
-      temp=temp->next;
-    }
-
-  }
-
-  bool PacketBuffer::isClosed() {
-    return closed;
-  }
-
-  void PacketBuffer::setClosed(bool value){
-    closed=value;
-    return;
-  }
-
-} // namespace orxonox
Index: code/trunk/src/network/PacketBuffer.h
===================================================================
--- code/trunk/src/network/PacketBuffer.h	(revision 3301)
+++ 	(revision )
@@ -1,80 +1,0 @@
-/*
- *   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, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-//
-// C++ Interface: PacketBuffer
-//
-// Description:
-//
-//
-// Author:  Oliver Scheuss, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-
-#ifndef _PacketBuffer_H__
-#define _PacketBuffer_H__
-
-#include "NetworkPrereqs.h"
-
-namespace orxonox
-{
-  struct _NetworkExport PacketEnvelope{
-    int length;
-    int data;
-  };
-
-  struct _NetworkExport QueueItem{
-    ENetEvent *event;
-    //ENetAddress address;
-    QueueItem *next;
-  };
-
-  class _NetworkExport PacketBuffer{
-  public:
-    PacketBuffer();
-    bool isEmpty();
-    bool isClosed();
-    void setClosed(bool value);
-    void print();
-    // pops a packet from the queue
-    //ENetPacket *pop();
-    //ENetPacket *pop(ENetAddress &address);
-    ENetEvent *pop();
-    // pushs a packet to the queue
-    bool push(ENetEvent *ev);
-
-  private:
-    QueueItem *first;
-    QueueItem *last;
-    bool closed;
-  };
-
-} //namespace
-#endif /* _PacketBuffer_H__ */
Index: code/trunk/src/network/Server.cc
===================================================================
--- code/trunk/src/network/Server.cc	(revision 3301)
+++ code/trunk/src/network/Server.cc	(revision 3304)
@@ -48,4 +48,5 @@
 #include "core/Clock.h"
 #include "core/ObjectList.h"
+#include "core/Executor.h"
 #include "packet/Chat.h"
 #include "packet/ClassID.h"
@@ -68,12 +69,10 @@
   */
   Server::Server() {
-    timeSinceLastUpdate_=0;
-    gamestates_ = new GamestateManager();
+    this->timeSinceLastUpdate_=0;
   }
 
   Server::Server(int port){
     this->setPort( port );
-    timeSinceLastUpdate_=0;
-    gamestates_ = new GamestateManager();
+    this->timeSinceLastUpdate_=0;
   }
 
@@ -86,6 +85,5 @@
     this->setPort( port );
     this->setBindAddress( bindAddress );
-    timeSinceLastUpdate_=0;
-    gamestates_ = new GamestateManager();
+    this->timeSinceLastUpdate_=0;
   }
 
@@ -94,6 +92,4 @@
   */
   Server::~Server(){
-    if(gamestates_)
-      delete gamestates_;
   }
 
@@ -138,15 +134,24 @@
   */
   void Server::update(const Clock& time) {
+    // receive incoming packets
     Connection::processQueue();
-    gamestates_->processGamestates();
-    //this steers our network frequency
-    timeSinceLastUpdate_+=time.getDeltaTime();
-    if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+    
+    if ( ClientInformation::hasClients() )
     {
-      timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
-      updateGamestate();
+      // process incoming gamestates
+      GamestateManager::processGamestates();
+      
+      // send function calls to clients
       FunctionCallManager::sendCalls();
-    }
-    sendPackets(); // flush the enet queue
+      
+      //this steers our network frequency
+      timeSinceLastUpdate_+=time.getDeltaTime();
+      if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+      {
+        timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
+        updateGamestate();
+      }
+      sendPackets(); // flush the enet queue
+    }
   }
 
@@ -175,8 +180,8 @@
   */
   void Server::updateGamestate() {
-//     if( ClientInformation::getBegin()==NULL )
+    if( ClientInformation::getBegin()==NULL )
       //no client connected
-//       return;
-    gamestates_->update();
+      return;
+    GamestateManager::update();
     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
     //std::cout << "updated gamestate, sending it" << std::endl;
@@ -197,38 +202,36 @@
   */
   bool Server::sendGameState() {
-    COUT(5) << "Server: starting function sendGameState" << std::endl;
-    ClientInformation *temp = ClientInformation::getBegin();
-    bool added=false;
-    while(temp != NULL){
-      if( !(temp->getSynched()) ){
-        COUT(5) << "Server: not sending gamestate" << std::endl;
-        temp=temp->next();
-        if(!temp)
-          break;
-        //think this works without continue
-        continue;
-      }
-      COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
-      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
-      int gid = temp->getGamestateID(); //get gamestate id
-      int cid = temp->getID(); //get client id
-      COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl;
-      packet::Gamestate *gs = gamestates_->popGameState(cid);
-      if(gs==NULL){
-        COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
-        temp = temp->next();
-        continue;
-      }
-      //std::cout << "adding gamestate" << std::endl;
-      gs->setClientID(cid);
-      if ( !gs->send() ){
-        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
-        temp->addFailure();
-      }else
-        temp->resetFailures();
-      added=true;
-      temp=temp->next();
-      // gs gets automatically deleted by enet callback
-    }
+//     COUT(5) << "Server: starting function sendGameState" << std::endl;
+//     ClientInformation *temp = ClientInformation::getBegin();
+//     bool added=false;
+//     while(temp != NULL){
+//       if( !(temp->getSynched()) ){
+//         COUT(5) << "Server: not sending gamestate" << std::endl;
+//         temp=temp->next();
+//         if(!temp)
+//           break;
+//         continue;
+//       }
+//       COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
+//       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
+//       int cid = temp->getID(); //get client id
+//       packet::Gamestate *gs = GamestateManager::popGameState(cid);
+//       if(gs==NULL){
+//         COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
+//         temp = temp->next();
+//         continue;
+//       }
+//       //std::cout << "adding gamestate" << std::endl;
+//       gs->setClientID(cid);
+//       if ( !gs->send() ){
+//         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
+//         temp->addFailure();
+//       }else
+//         temp->resetFailures();
+//       added=true;
+//       temp=temp->next();
+//       // gs gets automatically deleted by enet callback
+//     }
+    GamestateManager::sendGamestates();
     return true;
   }
@@ -324,5 +327,5 @@
   void Server::disconnectClient( ClientInformation *client ){
     ServerConnection::disconnectClient( client );
-    gamestates_->removeClient(client);
+    GamestateManager::removeClient(client);
 // inform all the listeners
     ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
Index: code/trunk/src/network/Server.h
===================================================================
--- code/trunk/src/network/Server.h	(revision 3301)
+++ code/trunk/src/network/Server.h	(revision 3304)
@@ -34,4 +34,5 @@
 #include "core/CorePrereqs.h"
 #include "Host.h"
+#include "GamestateManager.h"
 #include "ServerConnection.h"
 
@@ -43,5 +44,5 @@
   * It implements all functions necessary for a Server
   */
-  class _NetworkExport Server : public Host, public ServerConnection{
+  class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager{
   public:
     Server();
@@ -63,5 +64,5 @@
     unsigned int shipID(){return 0;}
     unsigned int playerID(){return 0;}
-
+    
     void addClient(ENetEvent *event);
     bool createClient(int clientID);
@@ -75,7 +76,4 @@
     void syncClassid(unsigned int clientID);
 
-    GamestateManager *gamestates_;
-
-
     float timeSinceLastUpdate_;
   };
Index: code/trunk/src/network/packet/ClassID.cc
===================================================================
--- code/trunk/src/network/packet/ClassID.cc	(revision 3301)
+++ code/trunk/src/network/packet/ClassID.cc	(revision 3304)
@@ -142,5 +142,5 @@
     classname = temp+2*sizeof(uint32_t);
     id=ClassByString( std::string((const char*)classname) );
-    COUT(0) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl;
+    COUT(3) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl;
     if(id==NULL){
       COUT(0) << "Recieved a bad classname" << endl;
Index: code/trunk/src/network/packet/FunctionIDs.cc
===================================================================
--- code/trunk/src/network/packet/FunctionIDs.cc	(revision 3301)
+++ code/trunk/src/network/packet/FunctionIDs.cc	(revision 3304)
@@ -132,5 +132,5 @@
     stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
     functionname = temp+2*sizeof(uint32_t);
-    COUT(0) << "processing functionid: " << networkID << " name: " << functionname << std::endl;
+    COUT(3) << "processing functionid: " << networkID << " name: " << functionname << std::endl;
     NetworkFunctionBase::setNetworkID((const char*)functionname, networkID);
     temp += 2*sizeof(uint32_t) + stringsize;
Index: code/trunk/src/network/synchronisable/NetworkCallbackManager.cc
===================================================================
--- code/trunk/src/network/synchronisable/NetworkCallbackManager.cc	(revision 3301)
+++ code/trunk/src/network/synchronisable/NetworkCallbackManager.cc	(revision 3304)
@@ -44,6 +44,6 @@
     if (it != callbackSet_.end())
     {
-      delete (*it);
       callbackSet_.erase(it);
+      delete cb;
     }
   }
Index: code/trunk/src/network/synchronisable/Synchronisable.cc
===================================================================
--- code/trunk/src/network/synchronisable/Synchronisable.cc	(revision 3301)
+++ code/trunk/src/network/synchronisable/Synchronisable.cc	(revision 3304)
@@ -96,10 +96,10 @@
       if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
         deletedObjects_.push(objectID);
-      // delete all Synchronisable Variables from syncList ( which are also in stringList )
-      for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
-        delete (*it);
-      syncList.clear();
-      stringList.clear();
-    }
+    }
+    // delete all Synchronisable Variables from syncList ( which are also in stringList )
+    for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
+      delete (*it);
+    syncList.clear();
+    stringList.clear();
     std::map<uint32_t, Synchronisable*>::iterator it;
     it = objectMap_.find(objectID);
@@ -247,6 +247,8 @@
       return 0;
     uint32_t tempsize = 0;
+#ifndef NDEBUG
     if (this->classID==0)
       COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
+#endif
 
     if (this->classID == static_cast<uint32_t>(-1))
Index: code/trunk/src/network/synchronisable/Synchronisable.h
===================================================================
--- code/trunk/src/network/synchronisable/Synchronisable.h	(revision 3301)
+++ code/trunk/src/network/synchronisable/Synchronisable.h	(revision 3304)
@@ -43,8 +43,4 @@
 #include "NetworkCallback.h"
 
-/*#define REGISTERDATA(varname, ...) \
-    registerVariable(static_cast<void*>(&varname), sizeof(varname), DATA, __VA_ARGS__)
-#define REGISTERSTRING(stringname, ...) \
-    registerVariable(&stringname, stringname.length()+1, STRING, __VA_ARGS__)*/
 
 namespace orxonox
Index: code/trunk/src/network/synchronisable/SynchronisableSpecialisations.cc
===================================================================
--- code/trunk/src/network/synchronisable/SynchronisableSpecialisations.cc	(revision 3301)
+++ code/trunk/src/network/synchronisable/SynchronisableSpecialisations.cc	(revision 3304)
@@ -38,20 +38,13 @@
 namespace orxonox{
   
-//   template <> void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
-//   {
-//     if (bidirectional)
-//       syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
-//     else
-//       syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
-//     stringList.push_back(syncList.back());
-//   }
-  
   template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
   {
+    SynchronisableVariableBase* sv;
     if (bidirectional)
-      syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
+      sv = new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb);
     else
-      syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
-    stringList.push_back(syncList.back());
+      sv = new SynchronisableVariable<const std::string>(variable, mode, cb);
+    syncList.push_back(sv);
+    stringList.push_back(sv);
   }
   
@@ -73,8 +66,4 @@
     registerVariable(variable.y, mode, cb, bidirectional);
   }
-//   template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
-//   {
-//     registerVariable( (const ColourValue&)variable, mode, cb, bidirectional);
-//   }
   
   template <> void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
Index: code/trunk/src/network/synchronisable/SynchronisableVariable.h
===================================================================
--- code/trunk/src/network/synchronisable/SynchronisableVariable.h	(revision 3301)
+++ code/trunk/src/network/synchronisable/SynchronisableVariable.h	(revision 3304)
@@ -117,5 +117,8 @@
   {
     if (this->callback_ != 0)
+    {
       NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion
+      // this is neccessary because for example for a Vector3 all 3 components of the vector use the same callback
+    }
   }
 
