[Orxonox-commit 3094] r7788 - in code/branches/presentation2: . src/libraries/network src/libraries/network/packet src/libraries/network/synchronisable src/libraries/util src/modules/weapons src/orxonox/controllers src/orxonox/gametypes

scheusso at orxonox.net scheusso at orxonox.net
Tue Dec 21 18:09:09 CET 2010


Author: scheusso
Date: 2010-12-21 18:09:09 +0100 (Tue, 21 Dec 2010)
New Revision: 7788

Modified:
   code/branches/presentation2/
   code/branches/presentation2/src/libraries/network/CMakeLists.txt
   code/branches/presentation2/src/libraries/network/Client.cc
   code/branches/presentation2/src/libraries/network/Client.h
   code/branches/presentation2/src/libraries/network/ClientConnection.cc
   code/branches/presentation2/src/libraries/network/ClientConnection.h
   code/branches/presentation2/src/libraries/network/ClientInformation.cc
   code/branches/presentation2/src/libraries/network/ClientInformation.h
   code/branches/presentation2/src/libraries/network/Connection.cc
   code/branches/presentation2/src/libraries/network/Connection.h
   code/branches/presentation2/src/libraries/network/FunctionCallManager.cc
   code/branches/presentation2/src/libraries/network/FunctionCallManager.h
   code/branches/presentation2/src/libraries/network/GamestateClient.cc
   code/branches/presentation2/src/libraries/network/GamestateClient.h
   code/branches/presentation2/src/libraries/network/GamestateHandler.cc
   code/branches/presentation2/src/libraries/network/GamestateHandler.h
   code/branches/presentation2/src/libraries/network/GamestateManager.cc
   code/branches/presentation2/src/libraries/network/GamestateManager.h
   code/branches/presentation2/src/libraries/network/Host.cc
   code/branches/presentation2/src/libraries/network/Host.h
   code/branches/presentation2/src/libraries/network/MasterServerComm.cc
   code/branches/presentation2/src/libraries/network/NetworkPrereqs.h
   code/branches/presentation2/src/libraries/network/Server.cc
   code/branches/presentation2/src/libraries/network/Server.h
   code/branches/presentation2/src/libraries/network/ServerConnection.cc
   code/branches/presentation2/src/libraries/network/ServerConnection.h
   code/branches/presentation2/src/libraries/network/WANDiscovery.cc
   code/branches/presentation2/src/libraries/network/packet/Acknowledgement.cc
   code/branches/presentation2/src/libraries/network/packet/Acknowledgement.h
   code/branches/presentation2/src/libraries/network/packet/Chat.cc
   code/branches/presentation2/src/libraries/network/packet/Chat.h
   code/branches/presentation2/src/libraries/network/packet/ClassID.cc
   code/branches/presentation2/src/libraries/network/packet/ClassID.h
   code/branches/presentation2/src/libraries/network/packet/DeleteObjects.cc
   code/branches/presentation2/src/libraries/network/packet/DeleteObjects.h
   code/branches/presentation2/src/libraries/network/packet/FunctionCalls.cc
   code/branches/presentation2/src/libraries/network/packet/FunctionCalls.h
   code/branches/presentation2/src/libraries/network/packet/FunctionIDs.cc
   code/branches/presentation2/src/libraries/network/packet/FunctionIDs.h
   code/branches/presentation2/src/libraries/network/packet/Gamestate.cc
   code/branches/presentation2/src/libraries/network/packet/Gamestate.h
   code/branches/presentation2/src/libraries/network/packet/Packet.cc
   code/branches/presentation2/src/libraries/network/packet/Packet.h
   code/branches/presentation2/src/libraries/network/packet/Welcome.cc
   code/branches/presentation2/src/libraries/network/packet/Welcome.h
   code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.cc
   code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h
   code/branches/presentation2/src/libraries/util/SignalHandler.cc
   code/branches/presentation2/src/modules/weapons/MuzzleFlash.cc
   code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc
   code/branches/presentation2/src/orxonox/gametypes/Gametype.cc
   code/branches/presentation2/src/orxonox/gametypes/Gametype.h
Log:
merged network5 into presentation2 branch (untested)



Property changes on: code/branches/presentation2
___________________________________________________________________
Modified: svn:mergeinfo
   - /code/branches/ai:6592-7033
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dynamicmatch:6584-7030
/code/branches/fps:6591-7072
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hudelements:6584-6941
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/lastmanstanding:7479-7644
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660
/code/branches/presentation2:6106-6416
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/steering:5949-6091
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051
/code/branches/weaponsystem:2742-2890
   + /code/branches/ai:6592-7033
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dynamicmatch:6584-7030
/code/branches/fps:6591-7072
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hudelements:6584-6941
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/lastmanstanding:7479-7644
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660
/code/branches/presentation2:6106-6416
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/steering:5949-6091
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051
/code/branches/weaponsystem:2742-2890

Modified: code/branches/presentation2/src/libraries/network/CMakeLists.txt
===================================================================
--- code/branches/presentation2/src/libraries/network/CMakeLists.txt	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/CMakeLists.txt	2010-12-21 17:09:09 UTC (rev 7788)
@@ -27,7 +27,7 @@
   FunctionCall.cc
   FunctionCallManager.cc
   GamestateManager.cc
-  GamestateClient.cc
+  #GamestateClient.cc
   GamestateHandler.cc
   LANDiscoverable.cc
   LANDiscovery.cc
@@ -52,7 +52,7 @@
   Connection.h
   FunctionCall.h
   FunctionCallManager.h
-  GamestateClient.h
+  #GamestateClient.h
   GamestateHandler.h
   GamestateManager.h
   Host.h

Modified: code/branches/presentation2/src/libraries/network/Client.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/Client.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/Client.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -63,7 +63,6 @@
   * initializes the address and the port to default localhost:NETWORK_PORT
   */
   Client::Client():
-      gamestate(0),
       isSynched_(false),
       gameStateFailure_(false),
       timeSinceLastUpdate_(0)
@@ -84,10 +83,10 @@
   bool Client::establishConnection()
   {
     Synchronisable::setClient(true);
-    this->gamestate = new GamestateClient();
     if( ClientConnection::establishConnection() )
     {
       Host::setActive(true);
+      GamestateManager::addPeer(NETWORK_PEER_ID_SERVER);
       return true;
     }
     else
@@ -100,10 +99,8 @@
   */
   bool Client::closeConnection()
   {
-    assert(this->gamestate);
-    delete this->gamestate;
-    this->gamestate = 0;
     Host::setActive(false);
+    GamestateManager::removePeer(NETWORK_PEER_ID_SERVER);
     return ClientConnection::closeConnection();
   }
 
@@ -113,11 +110,9 @@
     ClientConnection::setPort(port);
   }
 
-  bool Client::queuePacket(ENetPacket *packet, int clientID)
+  void Client::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)
   {
-    bool b = ClientConnection::addPacket(packet);
-    assert(b);
-    return b;
+    ClientConnection::addPacket(packet, channelID);
   }
 
   bool Client::processChat(const std::string& message, unsigned int playerID)
@@ -139,7 +134,7 @@
   bool Client::chat(const std::string& message)
   {
     packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
-    return m->send();
+    return m->send(static_cast<Host*>(this));
   }
 
 
@@ -158,28 +153,35 @@
       if ( isConnected() && isSynched_ )
       {
         COUT(4) << "popping partial gamestate: " << std::endl;
-        packet::Gamestate *gs = gamestate->getGamestate();
+//         packet::Gamestate *gs = GamestateClient::getGamestate();
+        GamestateManager::update();
+        std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
+        std::vector<packet::Gamestate*>::iterator it;
+        for( it = gamestates.begin(); it != gamestates.end(); ++it )
+        {
+          (*it)->send( static_cast<Host*>(this) );
+        }
         //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
-        if(gs){
-          COUT(4) << "client tick: sending gs " << gs << std::endl;
-          if( !gs->send() )
-            COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
-        // gs gets automatically deleted by enet callback
-        }
-        FunctionCallManager::sendCalls();
+//         if(gs){
+//           COUT(4) << "client tick: sending gs " << gs << std::endl;
+//           if( !gs->send() )
+//             COUT(2) << "Problem adding partial gamestate to queue" << std::endl;
+//         // gs gets automatically deleted by enet callback
+//         }
+        FunctionCallManager::sendCalls(static_cast<Host*>(this));
       }
     }
-    sendPackets(); // flush the enet queue
+//     sendPackets(); // flush the enet queue
 
     Connection::processQueue();
-    if(gamestate->processGamestates())
+    if(GamestateManager::processGamestates())
     {
       FunctionCallManager::processBufferedFunctionCalls();
       if(!isSynched_)
         isSynched_=true;
     }
-    gamestate->cleanup();
-    Connection::sendPackets();
+//     GamestateManager::cleanup();;
+//     Connection::sendPackets();
 
     return;
   }
@@ -199,7 +201,21 @@
     Game::getInstance().popState();
     Game::getInstance().popState();
   }
+  
+  void Client::processPacket(packet::Packet* packet)
+  {
+    if( packet->isReliable() )
+    {
+      if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
+        packet->process(static_cast<Host*>(this));
+      else
+        this->packetQueue_.push_back(packet);
+    }
+    else
+      packet->process(static_cast<Host*>(this));
+  }
 
 
 
+
 }

Modified: code/branches/presentation2/src/libraries/network/Client.h
===================================================================
--- code/branches/presentation2/src/libraries/network/Client.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/Client.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -44,11 +44,12 @@
 #include "NetworkPrereqs.h"
 
 #include <string>
+#include <deque>
 
 #include "util/UtilPrereqs.h"
 #include "util/Singleton.h"
 #include "ClientConnection.h"
-#include "GamestateClient.h"
+// #include "GamestateClient.h"
 #include "Host.h"
 #include "LANDiscovery.h"
 #include "packet/ServerInformation.h"
@@ -77,7 +78,8 @@
     bool establishConnection();
     void setDestination( const std::string& serverAddress, unsigned int port ); // tolua_export
     bool closeConnection();
-    bool queuePacket(ENetPacket *packet, int clientID);
+    void queuePacket(ENetPacket* packet, int clientID, uint8_t channelID);
+    virtual bool sendPacket( packet::Packet* packet ){ return packet->send( static_cast<Host*>(this) ); }
     bool processChat(const std::string& message, unsigned int playerID);
     virtual bool chat(const std::string& message);
     virtual bool broadcast(const std::string& message) { return false; }
@@ -89,10 +91,11 @@
   private:
     Client(const Client& copy); // not used
     virtual bool isServer_(){return false;}
+    void processPacket(packet::Packet* packet);
 
     static Client* singletonPtr_s;
-    GamestateClient* gamestate;
     bool isSynched_;
+    std::deque<packet::Packet*> packetQueue_;
 
     bool gameStateFailure_;
     float timeSinceLastUpdate_;

Modified: code/branches/presentation2/src/libraries/network/ClientConnection.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/ClientConnection.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/ClientConnection.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -38,7 +38,6 @@
   const unsigned int NETWORK_CLIENT_WAIT_TIME = 1;
   const unsigned int NETWORK_CLIENT_CONNECTION_TIMEOUT = 3000; //millisecs
   const unsigned int NETWORK_CLIENT_MAX_CONNECTIONS = 1;
-  const unsigned int NETWORK_CLIENT_CHANNELS = 1;
 
 
   ClientConnection::ClientConnection():
@@ -70,13 +69,19 @@
   {
     ENetEvent event;
 
-    this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0, 0);
+    // create host
+    this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0);
+    
     if ( this->host_ == NULL )
     {
       COUT(1) << "ClientConnection: host_ == NULL" << std::endl;
       // error handling
       return false;
     }
+    
+    // enable compression
+    this->enableCompression();
+    
     assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
     if (this->host_->socket4 == ENET_SOCKET_NULL)
         COUT(2) << "Warning: IPv4 Socket failed." << std::endl;
@@ -85,7 +90,7 @@
     else
         COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
 
-    this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CLIENT_CHANNELS, 0);
+    this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CHANNEL_COUNT, 0);
     if ( this->server_==NULL )
     {
       COUT(1) << "ClientConnection: server_ == NULL" << std::endl;
@@ -98,6 +103,7 @@
       if( enet_host_service(this->host_, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && event.type == ENET_EVENT_TYPE_CONNECT )
       {
         this->established_=true;
+        Connection::startCommunicationThread();
         return true;
       }
     }
@@ -111,6 +117,7 @@
     if ( !this->established_ )
       return true;
     this->established_ = false;
+    Connection::stopCommunicationThread();
     enet_peer_disconnect(this->server_, 0);
     for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++)
     {
@@ -137,10 +144,10 @@
   }
 
 
-  bool ClientConnection::addPacket(ENetPacket *packet) {
+  void ClientConnection::addPacket(ENetPacket *packet, uint8_t channelID) {
     assert( this->server_ );
     assert( packet );
-    return Connection::addPacket( packet, this->server_ );
+    return Connection::addPacket( packet, this->server_, channelID );
   }
 
   void ClientConnection::addPeer(ENetEvent* event)
@@ -152,6 +159,7 @@
     this->established_=false;
     COUT(1) << "Received disconnect Packet from Server!" << endl;
         // server closed the connection
+    this->stopCommunicationThread();
     this->connectionClosed();
   }
 

Modified: code/branches/presentation2/src/libraries/network/ClientConnection.h
===================================================================
--- code/branches/presentation2/src/libraries/network/ClientConnection.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/ClientConnection.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -43,14 +43,14 @@
     void setServerAddress( const std::string& serverAddress );
     void setPort( unsigned int port );
 
-    ENetEvent *getEvent();
+//     ENetEvent *getEvent();
     // check wheter the packet queue is empty
-    bool queueEmpty();
+//     bool queueEmpty();
     // create a new listener thread
     virtual bool establishConnection();
     virtual bool closeConnection();
     // add a packet to queue for the server
-    bool addPacket(ENetPacket *packet);
+    void addPacket(ENetPacket *packet, uint8_t channelID);
     inline bool isConnected(){ return this->established_; }
   protected:
     virtual void connectionClosed()=0;

Modified: code/branches/presentation2/src/libraries/network/ClientInformation.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/ClientInformation.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/ClientInformation.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -55,7 +55,6 @@
     gamestateID_=GAMESTATEID_INITIAL;
     preve=0;
     nexte=0;
-    partialGamestateID_=GAMESTATEID_INITIAL-1;
     synched_=false;
   }
 
@@ -132,13 +131,6 @@
     return true;
   }
 
-  bool ClientInformation::setPartialGamestateID(int id){
-    if(!this)
-      return false;
-    partialGamestateID_=id;
-    return true;
-  }
-
   unsigned int ClientInformation::getID() {
     if(!this)
       return CLIENTID_UNKNOWN;
@@ -153,16 +145,6 @@
       return NULL;
   }
 
-  int ClientInformation::getFailures(){
-    return failures_;
-  }
-  void ClientInformation::addFailure(){
-    failures_++;
-  }
-  void ClientInformation::resetFailures(){
-    failures_=0;
-  }
-
   uint32_t ClientInformation::getRTT(){
     return this->peer_->roundTripTime;
   }
@@ -178,13 +160,6 @@
       return static_cast<unsigned int>(-1);
   }
 
-  unsigned int ClientInformation::getPartialGamestateID() {
-    if(this)
-      return partialGamestateID_;
-    else
-      return static_cast<unsigned int>(-1);
-  }
-
   ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
     ClientInformation *temp = head_;
     if(temp==ins){

Modified: code/branches/presentation2/src/libraries/network/ClientInformation.h
===================================================================
--- code/branches/presentation2/src/libraries/network/ClientInformation.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/ClientInformation.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -65,19 +65,14 @@
     void setID(int clientID);
     bool setPeer(ENetPeer *peer);
     bool setGamestateID(int id);
-    bool setPartialGamestateID(int id);
     inline void setShipID(unsigned int id){ShipID_=id;}
 
     // get functions
     inline unsigned int getShipID(){return ShipID_;}
     unsigned int getID();
     unsigned int getGamestateID();
-    unsigned int getPartialGamestateID();
     ENetPeer *getPeer();
 
-    int getFailures();
-    void addFailure();
-    void resetFailures();
     uint32_t getRTT();
     double getPacketLoss();
 
@@ -105,10 +100,8 @@
     ENetPeer *peer_;
     unsigned int clientID_;
     unsigned int gamestateID_;
-    unsigned int partialGamestateID_;
     unsigned int ShipID_;   // this is the unique objectID
     bool synched_;
-    unsigned short failures_;
 
   };
 

Modified: code/branches/presentation2/src/libraries/network/Connection.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/Connection.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/Connection.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -29,57 +29,163 @@
 #include "Connection.h"
 
 #include <cassert>
+#include <deque>
 #define WIN32_LEAN_AND_MEAN
 #include <enet/enet.h>
+#include <boost/thread.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/date_time.hpp>
+
 #include "packet/Packet.h"
 
 namespace orxonox
 {
-//   Connection *Connection::instance_=0;
+  const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(20);
 
   Connection::Connection():
-    host_(0)
+    host_(0), bCommunicationThreadRunning_(false)
   {
-//     assert(instance_==0);
-//     Connection::instance_=this;
     enet_initialize();
     atexit(enet_deinitialize);
+    this->incomingEventsMutex_ = new boost::mutex;
+    this->outgoingEventsMutex_ = new boost::mutex;
   }
 
-  Connection::~Connection(){
-//     Connection::instance_=0;
+  Connection::~Connection()
+  {
+    delete this->incomingEventsMutex_;
+    delete this->outgoingEventsMutex_;
   }
 
-  int Connection::service(ENetEvent* event) {
-    return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
+  void Connection::startCommunicationThread()
+  {
+    this->bCommunicationThreadRunning_ = true;
+    this->communicationThread_ = new boost::thread(&Connection::communicationThread, this);
   }
+  
+  void Connection::stopCommunicationThread()
+  {
+    this->bCommunicationThreadRunning_ = false;
+    if( !this->communicationThread_->timed_join(NETWORK_COMMUNICATION_THREAD_WAIT_TIME) )
+    {
+      // force thread to stop
+      this->communicationThread_->interrupt();
+    }
+    delete this->communicationThread_;
+  }
 
-  void Connection::disconnectPeer(ENetPeer *peer) {
-    enet_peer_disconnect(peer, 0);
+
+//   int Connection::service(ENetEvent* event) {
+//     return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
+//   }
+
+  void Connection::disconnectPeer(ENetPeer *peer)
+  {
+    assert(peer);
+    outgoingEvent outEvent = { peer, outgoingEventType::disconnectPeer, (ENetPacket*)10, 15 };
+    
+    this->outgoingEventsMutex_->lock();
+    this->outgoingEvents_.push_back(outEvent);
+    this->outgoingEventsMutex_->unlock();
   }
 
-  bool Connection::addPacket(ENetPacket *packet, ENetPeer *peer) {
-    if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
-      return false;
-    else
-      return true;
+  void Connection::addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID)
+  {
+    assert(peer);
+    outgoingEvent outEvent = { peer, outgoingEventType::sendPacket, packet, channelID };
+    
+    this->outgoingEventsMutex_->lock();
+    this->outgoingEvents_.push_back(outEvent);
+    this->outgoingEventsMutex_->unlock();
   }
+  
+  void Connection::broadcastPacket(ENetPacket* packet, uint8_t channelID)
+  {
+    outgoingEvent outEvent = { (ENetPeer*)15, outgoingEventType::broadcastPacket, packet, channelID };
+    
+    this->outgoingEventsMutex_->lock();
+    this->outgoingEvents_.push_back(outEvent);
+    this->outgoingEventsMutex_->unlock();
+  }
 
-  bool Connection::sendPackets() {
-    if ( /*!Connection::instance_ || */this->host_==NULL )
-      return false;
-    enet_host_flush(this->host_);
-    return true;
+  
+  void Connection::communicationThread()
+  {
+    COUT(0) << "starting communication thread" << endl;
+    ENetEvent event;
+    
+    while( bCommunicationThreadRunning_ )
+    {
+      // Receive all pending incoming Events (such as packets, connects and disconnects)
+      while( enet_host_check_events( this->host_, &event ) > 0 )
+      {
+//         COUT(0) << "incoming event" << endl;
+        // received an event
+        this->incomingEventsMutex_->lock();
+        this->incomingEvents_.push_back(event);
+        this->incomingEventsMutex_->unlock();
+      }
+      
+      // Send all waiting outgoing packets
+      this->outgoingEventsMutex_->lock();
+      uint32_t outgoingEventsCount = this->outgoingEvents_.size();
+      this->outgoingEventsMutex_->unlock();
+      while( outgoingEventsCount > 0 )
+      {
+//         COUT(0) << "outgoing event" << endl;
+        this->outgoingEventsMutex_->lock();
+        outgoingEvent outEvent = this->outgoingEvents_.front();
+        this->outgoingEvents_.pop_front();
+        this->outgoingEventsMutex_->unlock();
+        
+        switch( outEvent.type )
+        {
+          case outgoingEventType::sendPacket:
+            enet_peer_send( outEvent.peer, outEvent.channelID, outEvent.packet );
+            break;
+          case outgoingEventType::disconnectPeer:
+            enet_peer_disconnect(outEvent.peer, 0);
+            break;
+          case outgoingEventType::broadcastPacket:
+            enet_host_broadcast( this->host_, outEvent.channelID, outEvent.packet );
+            break;
+          default:
+            assert(0);
+        }
+        this->outgoingEventsMutex_->lock();
+        outgoingEventsCount = this->outgoingEvents_.size();
+        this->outgoingEventsMutex_->unlock();
+      }
+      
+      // Wait for incoming events (at most NETWORK_WAIT_TIMEOUT ms)
+      if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+      {
+//         COUT(0) << "incoming event after wait" << endl;
+        //received an event
+        this->incomingEventsMutex_->lock();
+        this->incomingEvents_.push_back(event);
+        this->incomingEventsMutex_->unlock();
+      }
+    }
   }
 
-  void Connection::processQueue() {
+  void Connection::processQueue()
+  {
     ENetEvent event;
 
-    assert(this->host_);
-
-    while( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+    this->incomingEventsMutex_->lock();
+    uint32_t incomingEventsCount = this->incomingEvents_.size();
+    this->incomingEventsMutex_->unlock();
+    while( incomingEventsCount > 0 )
     {
-      switch(event.type){
+      packet::Packet* p;
+      this->incomingEventsMutex_->lock();
+      event = this->incomingEvents_.front();
+      this->incomingEvents_.pop_front();
+      this->incomingEventsMutex_->unlock();
+      
+      switch(event.type)
+      {
         // log handling ================
         case ENET_EVENT_TYPE_CONNECT:
           addPeer( &event );
@@ -88,17 +194,31 @@
           removePeer( &event );
           break;
         case ENET_EVENT_TYPE_RECEIVE:
-          processPacket( &event );
+//           COUT(0) << "ENET_EVENT_TYPE_RECEIVE" << endl;
+          p = createPacket( &event );
+          processPacket(p);
           break;
         case ENET_EVENT_TYPE_NONE:
           break;
       }
+      
+      this->incomingEventsMutex_->lock();
+      incomingEventsCount = this->incomingEvents_.size();
+      this->incomingEventsMutex_->unlock();
     }
   }
 
-  bool Connection::processPacket(ENetEvent* event) {
+  packet::Packet* Connection::createPacket(ENetEvent* event)
+  {
     packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer);
-    return p->process();
+    return p;
+//     return p->process();
   }
+  
+  void Connection::enableCompression()
+  {
+    enet_host_compress_with_range_coder( this->host_ );
+  }
 
+
 }

Modified: code/branches/presentation2/src/libraries/network/Connection.h
===================================================================
--- code/branches/presentation2/src/libraries/network/Connection.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/Connection.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -42,37 +42,76 @@
 
 #include "NetworkPrereqs.h"
 
+#include <deque>
+
+namespace boost
+{
+  class thread;
+  class mutex;
+}
+
 namespace orxonox
 {
-    const unsigned int NETWORK_PORT = 55556;
-    const unsigned int NETWORK_MAX_CONNECTIONS = 50;
-    const unsigned int NETWORK_WAIT_TIMEOUT = 0;
-    const unsigned int NETWORK_DEFAULT_CHANNEL = 0;
-    const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
-
-  class _NetworkExport Connection{
+  const unsigned int NETWORK_PORT                   = 55556;
+  const unsigned int NETWORK_MAX_CONNECTIONS        = 50;
+  const unsigned int NETWORK_WAIT_TIMEOUT           = 1;
+  const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
+  
+  namespace outgoingEventType
+  {
+    enum Value
+    {
+      sendPacket      = 1,
+      disconnectPeer  = 2,
+      broadcastPacket = 3
+    };
+    
+  }
+  
+  struct _NetworkExport outgoingEvent
+  {
+    ENetPeer*                 peer;
+    outgoingEventType::Value  type;
+    ENetPacket*               packet;
+    ENetChannelID             channelID;
+  };
+  
+  class _NetworkExport Connection
+  {
   public:
     virtual ~Connection();
 
-    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
-    bool sendPackets();
-    ENetHost* getHost(){ return this->host_; }
+    void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
+    void broadcastPacket(ENetPacket* packet, uint8_t channelID);
+//     ENetHost* getHost(){ return this->host_; }
 
   protected:
     Connection();
 //     static Connection* getInstance(){ return Connection::instance_; }
 
-    int service(ENetEvent* event);
+//     int service(ENetEvent* event);
+    void startCommunicationThread();
+    void stopCommunicationThread();
+    void communicationThread();
     virtual void disconnectPeer(ENetPeer *peer);
+    
+    void enableCompression();
 
     void processQueue();
     virtual void addPeer(ENetEvent* event)=0;
     virtual void removePeer(ENetEvent* event)=0;
-    virtual bool processPacket(ENetEvent* event);
+    virtual void processPacket( packet::Packet* packet)=0;
+    virtual packet::Packet* createPacket(ENetEvent* event);
 
-    ENetHost *host_;
+    ENetHost*                   host_;
   private:
-    ENetAddress *bindAddress_;
+    boost::thread*              communicationThread_;
+    bool                        bCommunicationThreadRunning_;
+    ENetAddress*                bindAddress_;
+    std::deque<ENetEvent>       incomingEvents_;
+    std::deque<outgoingEvent>   outgoingEvents_;
+    boost::mutex*               incomingEventsMutex_;
+    boost::mutex*               outgoingEventsMutex_;
 
 //     static Connection *instance_;
 

Modified: code/branches/presentation2/src/libraries/network/FunctionCallManager.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/FunctionCallManager.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/FunctionCallManager.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -29,155 +29,157 @@
 #include "FunctionCallManager.h"
 #include "packet/FunctionCalls.h"
 #include "core/GameMode.h"
+#include "GamestateHandler.h"
 
 namespace orxonox {
 
-std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sClientMap_;
-std::vector<FunctionCall> FunctionCallManager::sIncomingFunctionCallBuffer_;
+std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sPeerMap_;
+std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > > FunctionCallManager::sIncomingFunctionCallBuffer_;
 
 // Static calls
 
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallStatic(functionID);
+  FunctionCallManager::sPeerMap_[peerID]->addCallStatic(functionID);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
 }
 
 
 // MemberCalls
 
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
 }
 
 // Send calls
 
-void FunctionCallManager::sendCalls()
+void FunctionCallManager::sendCalls(orxonox::Host* host)
 {
   std::map<uint32_t, packet::FunctionCalls*>::iterator it;
-  for (it = FunctionCallManager::sClientMap_.begin(); it != FunctionCallManager::sClientMap_.end(); ++it )
+  for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it )
   {
-    assert(!FunctionCallManager::sClientMap_.empty());
-    it->second->send();
+    assert(!FunctionCallManager::sPeerMap_.empty());
+    it->second->send(host);
   }
-  FunctionCallManager::sClientMap_.clear();
+  FunctionCallManager::sPeerMap_.clear();
 }
 
-void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall)
+void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID)
 {
-  if( !GameMode::isMaster() )
-    FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( fctCall );
+  FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, peerID)));
 }
 
 void FunctionCallManager::processBufferedFunctionCalls()
 {
-  std::vector<FunctionCall>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
+  std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > >::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
   while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() )
   {
-    if( it->execute() )
+    if( it->first.execute() )
       FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it);
     else
+    {
       ++it;
+    }
   }
 }
 

Modified: code/branches/presentation2/src/libraries/network/FunctionCallManager.h
===================================================================
--- code/branches/presentation2/src/libraries/network/FunctionCallManager.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/FunctionCallManager.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -33,6 +33,7 @@
 
 #include <map>
 #include <vector>
+#include <utility>
 #include "util/UtilPrereqs.h"
 #include "FunctionCall.h"
 
@@ -44,27 +45,27 @@
 class _NetworkExport FunctionCallManager
 {
 public:
-  static void addCallStatic(uint32_t functionID, uint32_t clientID);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
 
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
 
-  static void sendCalls();
+  static void sendCalls(orxonox::Host* host);
   
-  static void bufferIncomingFunctionCall( const FunctionCall& fctCall );
+  static void bufferIncomingFunctionCall( const FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID );
   static void processBufferedFunctionCalls();
 
-  static std::map<uint32_t, packet::FunctionCalls*> sClientMap_;
-  static std::vector<FunctionCall>                  sIncomingFunctionCallBuffer_;
+  static std::map<uint32_t, packet::FunctionCalls*>                           sPeerMap_;
+  static std::vector<std::pair<FunctionCall,std::pair<uint32_t, uint32_t> > > sIncomingFunctionCallBuffer_;
 protected:
   FunctionCallManager();
   ~FunctionCallManager();

Modified: code/branches/presentation2/src/libraries/network/GamestateClient.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/GamestateClient.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/GamestateClient.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -38,19 +38,22 @@
 
 namespace orxonox
 {
-  struct _NetworkExport GameStateItem{
+  struct _NetworkExport GameStateItem
+  {
     packet::Gamestate *state;
     unsigned int id;
   };
 
-  GamestateClient::GamestateClient() {
+  GamestateClient::GamestateClient()
+  {
     COUT(5) << "this: " << this << std::endl;
-    last_diff_=0;
-    last_gamestate_=GAMESTATEID_INITIAL-1;
+    lastAckedGamestateID_=GAMESTATEID_INITIAL-1;
+    lastProcessedGamestateID_=GAMESTATEID_INITIAL-1;
     tempGamestate_=NULL;
   }
 
-  GamestateClient::~GamestateClient() {
+  GamestateClient::~GamestateClient()
+  {
       std::map<unsigned int, packet::Gamestate *>::iterator it;
       for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it )
           delete it->second;
@@ -58,12 +61,15 @@
           delete this->tempGamestate_;
   }
 
-  bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID){
+  bool GamestateClient::ackGamestate(unsigned int gamestateID, unsigned int clientID)
+  {
     return true;
   }
 
-  bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID){
-    if(tempGamestate_!=NULL){
+  bool GamestateClient::addGamestate(packet::Gamestate *gs, unsigned int clientID)
+  {
+    if(tempGamestate_!=NULL)
+    {
       //delete the obsolete gamestate
       if(tempGamestate_->getID()>gs->getID())
         return false;
@@ -73,7 +79,8 @@
     return true;
   }
 
-  bool GamestateClient::processGamestates(){
+  bool GamestateClient::processGamestates()
+  {
     if(tempGamestate_==NULL)
       return false;
     bool isDiffed = tempGamestate_->isDiffed();
@@ -84,15 +91,18 @@
     //now call the queued callbacks
     NetworkCallbackManager::callCallbacks();
 
-    if (!processed){
+    if (!processed)
+    {
+      assert(0);
       sendAck(0);
       return false;
     }
     //successfully loaded data from gamestate. now save gamestate for diff and delete the old gs
     tempGamestate_=NULL;
     gamestateMap_[processed->getID()]=processed;
+    lastProcessedGamestateID_ = processed->getID();
     if(isDiffed)
-      last_diff_ = processed->getBaseID();
+      lastAckedGamestateID_ = processed->getBaseID();
     id = processed->getID();
     sendAck(id);
     return true;
@@ -104,25 +114,30 @@
   * @param it iterator of the list pointing to the object
   * @return iterator pointing to the next object in the list
   */
-  void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it) {
+  void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it)
+  {
     ObjectListIterator<Synchronisable> temp=it;
     ++it;
     temp->destroy(); // or delete?
   }
 
-  packet::Gamestate *GamestateClient::getGamestate(){
+  packet::Gamestate *GamestateClient::getGamestate()
+  {
     packet::Gamestate *gs = new packet::Gamestate();
-    if(!gs->collectData(0,0x2)){
+    if(!gs->collectData(this->getLastProcessedGamestateID(NETWORK_PEER_ID_SERVER), 0x2))
+    {
       delete gs;
       return 0;
     }
     return gs;
   }
 
-  void GamestateClient::cleanup(){
+  void GamestateClient::cleanup()
+  {
     std::map<unsigned int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin();
-    while(it!=gamestateMap_.end()){
-      if(it->first>=last_diff_)
+    while(it!=gamestateMap_.end())
+    {
+      if(it->first>=lastAckedGamestateID_)
         break;
       // otherwise delete that stuff
       delete it->second;
@@ -132,29 +147,35 @@
     tempGamestate_=NULL;
   }
 
-  void GamestateClient::printGamestateMap(){
+  void GamestateClient::printGamestateMap()
+  {
     std::map<unsigned int, packet::Gamestate*>::iterator it;
     COUT(4) << "gamestates: ";
-    for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++){
+    for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++)
+    {
       COUT(4) << it->first << ':' << it->second << '|';
     }
     COUT(4) << std::endl;
 
   }
 
-  bool GamestateClient::sendAck(unsigned int gamestateID){
+  bool GamestateClient::sendAck(unsigned int gamestateID)
+  {
     packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, 0);
-    if(!ack->send()){
+    if(!ack->send())
+    {
       COUT(3) << "could not ack gamestate: " << gamestateID << std::endl;
       return false;
     }
-    else{
+    else
+    {
       COUT(5) << "acked a gamestate: " << gamestateID << std::endl;
       return true;
     }
   }
 
-  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
+  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs)
+  {
     if(gs->isCompressed())
     {
       bool b = gs->decompressData();

Modified: code/branches/presentation2/src/libraries/network/GamestateClient.h
===================================================================
--- code/branches/presentation2/src/libraries/network/GamestateClient.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/GamestateClient.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -56,8 +56,10 @@
     GamestateClient();
     ~GamestateClient();
 
-    bool add(packet::Gamestate *gs, unsigned int clientID);
-    bool ack(unsigned int gamestateID, unsigned int clientID);
+    virtual bool      addGamestate(packet::Gamestate *gs, unsigned int clientID);
+    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int clientID);
+    virtual uint32_t  getLastProcessedGamestateID(unsigned int clientID=0) { return this->lastProcessedGamestateID_; }
+    virtual uint32_t  getCurrentGamestateID(){ return this->lastProcessedGamestateID_; }
 
     bool processGamestates();
     packet::Gamestate *getGamestate();
@@ -68,8 +70,8 @@
     void printGamestateMap();
     bool sendAck(unsigned int gamestateID);
 
-    unsigned int           last_diff_;
-    unsigned int           last_gamestate_;
+    unsigned int           lastAckedGamestateID_;
+    unsigned int           lastProcessedGamestateID_;
     std::map<unsigned int, packet::Gamestate *> gamestateMap_;
     packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue
 

Modified: code/branches/presentation2/src/libraries/network/GamestateHandler.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/GamestateHandler.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/GamestateHandler.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -31,18 +31,15 @@
 
 namespace orxonox {
 
-GamestateHandler *GamestateHandler::instance_=0;
+// GamestateHandler *GamestateHandler::instance_=0;
 
 GamestateHandler::GamestateHandler()
 {
-  assert(instance_==0);
-  instance_=this;
 }
 
 
 GamestateHandler::~GamestateHandler()
 {
-  instance_=0;
 }
 
 

Modified: code/branches/presentation2/src/libraries/network/GamestateHandler.h
===================================================================
--- code/branches/presentation2/src/libraries/network/GamestateHandler.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/GamestateHandler.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -31,26 +31,27 @@
 
 #include "NetworkPrereqs.h"
 
+#include <cassert>
+
 namespace orxonox {
 
 /**
     @author Oliver Scheuss
 */
-class _NetworkExport GamestateHandler{
+class _NetworkExport GamestateHandler
+{
   private:
-    virtual bool add(packet::Gamestate *gs, unsigned int clientID)=0;
-    virtual bool ack(unsigned int gamestateID, unsigned int clientID)=0;
 
-    static GamestateHandler *instance_;
 
-
   protected:
     GamestateHandler();
     virtual ~GamestateHandler();
 
   public:
-    static bool addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); }
-    static bool ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); }
+    virtual bool      addGamestate(packet::Gamestate* gs, unsigned int clientID) = 0;
+    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int clientID) = 0;
+    virtual uint32_t  getLastProcessedGamestateID( unsigned int clientID )=0;
+    virtual uint32_t  getCurrentGamestateID()=0;
 };
 
 }

Modified: code/branches/presentation2/src/libraries/network/GamestateManager.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/GamestateManager.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/GamestateManager.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -42,42 +42,43 @@
 
 #include <cassert>
 #include <queue>
-#include "util/Clock.h"
 // #include <boost/thread/mutex.hpp>
 
-#include "util/Debug.h"
-#include "core/ThreadPool.h"
-#include "core/command/Executor.h"
-#include "ClientInformation.h"
 #include "packet/Acknowledgement.h"
 #include "packet/Gamestate.h"
 #include "synchronisable/NetworkCallbackManager.h"
-#include "TrafficControl.h"
 
+#include "core/ThreadPool.h"
+#include "core/command/Executor.h"
+#include "core/GameMode.h"
+#include "util/Debug.h"
+#include "util/Clock.h"
+// #include "TrafficControl.h"
+
 namespace orxonox
 {
   GamestateManager::GamestateManager() :
-  reference(0), id_(0)
+  currentGamestate_(0), id_(0)
   {
-    trafficControl_ = new TrafficControl();
+//     trafficControl_ = new TrafficControl();
 //     threadMutex_ = new boost::mutex();
 //     threadPool_ = new ThreadPool();
   }
 
   GamestateManager::~GamestateManager()
   {
-    if( this->reference )
-        delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it;
+    if( this->currentGamestate_ )
+        delete this->currentGamestate_;std::map<unsigned int, packet::Gamestate*>::iterator it;
     for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
       delete it->second;
-    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 )
+    std::map<uint32_t, peerInfo>::iterator peerIt;
+    std::map<uint32_t, packet::Gamestate*>::iterator gamestateIt;
+    for( peerIt = peerMap_.begin(); peerIt != peerMap_.end(); ++peerIt )
     {
-      for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
-        delete it2->second;
+      for( gamestateIt = peerIt->second.gamestates.begin(); gamestateIt != peerIt->second.gamestates.end(); ++gamestateIt )
+        delete gamestateIt->second;
     }
-    this->trafficControl_->destroy();
+//     this->trafficControl_->destroy();
 //     delete this->threadMutex_;
 //     delete this->threadPool_;
   }
@@ -87,7 +88,8 @@
     return getSnapshot();
   }
 
-  bool GamestateManager::add(packet::Gamestate *gs, unsigned int clientID){
+  bool GamestateManager::addGamestate(packet::Gamestate *gs, unsigned int clientID)
+  {
     assert(gs);
     std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID);
     if(it!=gamestateQueue.end()){
@@ -98,7 +100,8 @@
     return true;
   }
 
-  bool GamestateManager::processGamestates(){
+  bool GamestateManager::processGamestates()
+  {
     if( this->gamestateQueue.empty() )
         return true;
     std::map<unsigned int, packet::Gamestate*>::iterator it;
@@ -106,6 +109,7 @@
     for(it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++){
       bool b = processGamestate(it->second);
       assert(b);
+      sendAck( it->second->getID(), it->second->getPeerID() );
       delete it->second;
     }
     // now clear the queue
@@ -114,73 +118,94 @@
     NetworkCallbackManager::callCallbacks();
     return true;
   }
+  
+  bool GamestateManager::sendAck(unsigned int gamestateID, uint32_t peerID)
+  {
+    packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, peerID);
+    if( !this->sendPacket(ack))
+    {
+      COUT(3) << "could not ack gamestate: " << gamestateID << std::endl;
+      return false;
+    }
+    else
+    {
+      COUT(5) << "acked a gamestate: " << gamestateID << std::endl;
+      return true;
+    }
+  }
 
 
   bool GamestateManager::getSnapshot(){
-    if ( reference != 0 )
-      delete reference;
-    reference = new packet::Gamestate();
-    if(!reference->collectData(++id_, 0x1)){ //we have no data to send
-      delete reference;
-      reference=0;
+    if ( currentGamestate_ != 0 )
+      delete currentGamestate_;
+    currentGamestate_ = new packet::Gamestate();
+    uint8_t gsMode;
+    if( GameMode::isMaster() )
+      gsMode = packet::GAMESTATE_MODE_SERVER;
+    else
+      gsMode = packet::GAMESTATE_MODE_CLIENT;
+    uint32_t newID;
+    if( GameMode::isMaster() )
+      newID = ++id_;
+    else
+      newID = peerMap_[NETWORK_PEER_ID_SERVER].lastProcessedGamestateID;
+    
+    if(!currentGamestate_->collectData(newID, gsMode)){ //we have no data to send
+      delete currentGamestate_;
+      currentGamestate_=0;
     }
     return true;
   }
 
-  void GamestateManager::sendGamestates()
+  std::vector<packet::Gamestate*> GamestateManager::getGamestates()
   {
-    ClientInformation *temp = ClientInformation::getBegin();
-    std::queue<packet::Gamestate*> clientGamestates;
-    while(temp != NULL){
-      if( !(temp->getSynched()) ){
+    if(!currentGamestate_)
+      return std::vector<packet::Gamestate*>();
+    std::vector<packet::Gamestate*> peerGamestates;
+    
+    std::map<uint32_t, peerInfo>::iterator peerIt;
+    for( peerIt=peerMap_.begin(); peerIt!=peerMap_.end(); ++peerIt )
+    {
+      if( !peerIt->second.isSynched )
+      {
         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(4) << "client id: " << peerIt->first << std::endl;
       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
-      int cid = temp->getID(); //get client id
+      int peerID = peerIt->first; //get client id
 
-      unsigned int gID = temp->getGamestateID();
-      if(!reference)
-        return;
+      unsigned int lastAckedGamestateID = peerIt->second.lastAckedGamestateID;
 
-      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;
-        }
+      packet::Gamestate* baseGamestate=0;
+      if(lastAckedGamestateID != GAMESTATEID_INITIAL)
+      {
+        assert(peerMap_.find(peerID)!=peerMap_.end());
+        std::map<uint32_t, packet::Gamestate*>::iterator it = peerMap_[peerID].gamestates.find(lastAckedGamestateID);
+        assert(it!=peerMap_[peerID].gamestates.end());
+        baseGamestate = it->second;
       }
 
-      clientGamestates.push(0);
-      finishGamestate( cid, clientGamestates.back(), client, reference );
+      peerGamestates.push_back(0);  // insert an empty gamestate* to change
+      finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ );
+      if( peerGamestates.back()==0 )
+        // nothing to send to remove pointer from vector
+        peerGamestates.pop_back();
       //FunctorMember<GamestateManager>* functor =
 //       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) );
-//       executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
+//       executor->setDefaultValues( cid, &clientGamestates.back(), client, currentGamestate_ );
 //       (*static_cast<Executor*>(executor))();
 //       this->threadPool_->passFunction( executor, true );
-//       (*functor)( cid, &(clientGamestates.back()), client, reference );
-
-      temp = temp->next();
+//       (*functor)( cid, &(clientGamestates.back()), client, currentGamestate_ );
     }
 
 //     threadPool_->synchronise();
 
-    while( !clientGamestates.empty() )
-    {
-      if(clientGamestates.front())
-        clientGamestates.front()->send();
-      clientGamestates.pop();
-    }
+    return peerGamestates;
   }
 
 
-  void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
+  void GamestateManager::finishGamestate( unsigned int peerID, 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?
     // save the (undiffed) gamestate in the clients gamestate map
@@ -193,10 +218,10 @@
 //     packet::Gamestate *gs = new packet::Gamestate();
 //     gs->collectData( id_, 0x1 );
 //     this->threadMutex_->lock();
-    gamestateMap_[clientID][gamestate->getID()]=gs;
+    peerMap_[peerID].gamestates[gamestate->getID()]=gs;
 //     this->threadMutex_->unlock();
-      Clock clock;
-      clock.capture();
+    Clock clock;
+    clock.capture();
 
     if(base)
     {
@@ -215,68 +240,130 @@
     }
 
 
-    bool b = gs->compressData();
-    assert(b);
-      clock.capture();
-      COUT(0) << "diff time: " << clock.getDeltaTime() << endl;
+//     bool b = gs->compressData();
+//     assert(b);
+    clock.capture();
+    COUT(4) << "diff and compress time: " << clock.getDeltaTime() << endl;
 //     COUT(5) << "sending gamestate with id " << gs->getID();
 //     if(gamestate->isDiffed())
 //       COUT(5) << " and baseid " << gs->getBaseID() << endl;
 //     else
 //       COUT(5) << endl;
-    gs->setClientID(clientID);
+    gs->setPeerID(peerID);
     destgamestate = gs;
   }
 
 
-  bool GamestateManager::ack(unsigned int gamestateID, unsigned int clientID) {
-    ClientInformation *temp = ClientInformation::findClient(clientID);
-    assert(temp);
-    unsigned int curid = temp->getGamestateID();
+  bool GamestateManager::ackGamestate(unsigned int gamestateID, unsigned int peerID)
+  {
+//     ClientInformation *temp = ClientInformation::findClient(peerID);
+//     assert(temp);
+    std::map<uint32_t, peerInfo>::iterator it = this->peerMap_.find(peerID);
+    assert(it!=this->peerMap_.end());
+    unsigned int curid = it->second.lastAckedGamestateID;
 
     if(gamestateID == ACKID_NACK){
-      temp->setGamestateID(GAMESTATEID_INITIAL);
+      it->second.lastAckedGamestateID = GAMESTATEID_INITIAL;
+//       temp->setGamestateID(GAMESTATEID_INITIAL);
       // now delete all saved gamestates for this client
-      std::map<unsigned int, packet::Gamestate*>::iterator it;
-      for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){
-        delete it->second;
-
-        gamestateMap_[clientID].erase(it++);
+      std::map<uint32_t, packet::Gamestate*>::iterator it2;
+      for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){
+        delete it2->second;
       }
+      it->second.gamestates.clear();
       return true;
     }
 
-    assert(curid==GAMESTATEID_INITIAL || curid<gamestateID);
-    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; ){
-      delete it->second;
-      gamestateMap_[clientID].erase(it++);
+    assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID);
+    COUT(5) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl;
+    std::map<uint32_t, packet::Gamestate*>::iterator it2;
+    for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); )
+    {
+      if( it2->second->getID() < gamestateID )
+      {
+        delete it2->second;
+        it->second.gamestates.erase(it2++);
+      }
+      else
+        ++it2;
     }
-    temp->setGamestateID(gamestateID);
-    TrafficControl::processAck(clientID, gamestateID);
+    
+//     std::map<unsigned int, packet::Gamestate*>::iterator it;
+//     for(it = gamestateMap_[peerID].begin(); it!=gamestateMap_[peerID].end() && it->first<gamestateID; ){
+//       delete it->second;
+//       gamestateMap_[peerID].erase(it++);
+//     }
+    it->second.lastAckedGamestateID = gamestateID;
+//     temp->setGamestateID(gamestateID);
+//     TrafficControl::processAck(peerID, gamestateID);
     return true;
   }
+  
+  uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int peerID)
+  {
+    assert( this->peerMap_.find(peerID)!=this->peerMap_.end() );
+    if( this->peerMap_.find(peerID) != this->peerMap_.end() )
+      return this->peerMap_[peerID].lastProcessedGamestateID;
+    else
+      return GAMESTATEID_INITIAL;
+  }
+  
+  
+  void GamestateManager::addPeer(uint32_t peerID)
+  {
+    assert(peerMap_.find(peerID)==peerMap_.end());
+    peerMap_[peerID].peerID = peerID;
+    peerMap_[peerID].lastProcessedGamestateID = GAMESTATEID_INITIAL;
+    peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL;
+    if( GameMode::isMaster() )
+      peerMap_[peerID].isSynched = false;
+    else
+      peerMap_[peerID].isSynched = true;
+  }
 
-  void GamestateManager::removeClient(ClientInformation* client){
-    assert(client);
-    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
-    // first delete all remained gamestates
-    std::map<unsigned int, packet::Gamestate*>::iterator it;
-    for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++)
-      delete it->second;
-    // now delete the clients gamestatemap
-    gamestateMap_.erase(clientMap);
+  void GamestateManager::removePeer(uint32_t peerID)
+  {
+    assert(peerMap_.find(peerID)!=peerMap_.end());
+    std::map<uint32_t, packet::Gamestate*>::iterator peerIt;
+    for( peerIt = peerMap_[peerID].gamestates.begin(); peerIt!=peerMap_[peerID].gamestates.end(); ++peerIt )
+    {
+      delete peerIt->second;
+    }
+    peerMap_.erase(peerMap_.find(peerID));
   }
 
-  bool GamestateManager::processGamestate(packet::Gamestate *gs){
+
+//   void GamestateManager::removeClient(ClientInformation* client){
+//     assert(client);
+//     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
+//     // first delete all remained gamestates
+//     std::map<unsigned int, packet::Gamestate*>::iterator it;
+//     for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++)
+//       delete it->second;
+//     // now delete the clients gamestatemap
+//     gamestateMap_.erase(clientMap);
+//   }
+
+  bool GamestateManager::processGamestate(packet::Gamestate *gs)
+  {
     if(gs->isCompressed())
     {
        bool b = gs->decompressData();
        assert(b);
     }
     assert(!gs->isDiffed());
-    return gs->spreadData(0x1);
+    uint8_t gsMode;
+    if( GameMode::isMaster() )
+      gsMode = packet::GAMESTATE_MODE_SERVER;
+    else
+      gsMode = packet::GAMESTATE_MODE_CLIENT;
+    if( gs->spreadData(gsMode) )
+    {
+      this->peerMap_[gs->getPeerID()].lastProcessedGamestateID = gs->getID();
+      return true;
+    }
+    else
+      return false;
   }
 
 }

Modified: code/branches/presentation2/src/libraries/network/GamestateManager.h
===================================================================
--- code/branches/presentation2/src/libraries/network/GamestateManager.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/GamestateManager.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -45,6 +45,8 @@
 #include <map>
 #include "GamestateHandler.h"
 #include "core/CorePrereqs.h"
+#include "packet/Gamestate.h"
+#include <boost/concept_check.hpp>
 
 namespace orxonox
 {
@@ -65,29 +67,51 @@
   * diff(a,diff(a,x))=x (hope this is correct)
   * @author Oliver Scheuss
   */
-  class _NetworkExport GamestateManager: public GamestateHandler{
+  class _NetworkExport GamestateManager: public GamestateHandler
+  {
+    struct peerInfo
+    {
+      uint32_t  peerID;
+      uint32_t  lastProcessedGamestateID;
+      uint32_t  lastAckedGamestateID;
+      bool      isSynched;
+      std::map< uint32_t, packet::Gamestate* > gamestates;
+    };
+    
   public:
+    
     GamestateManager();
     ~GamestateManager();
 
-    bool add(packet::Gamestate *gs, unsigned int clientID);
+    virtual bool      addGamestate(packet::Gamestate *gs, unsigned int peerID);
+    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int peerID);
+    virtual uint32_t  getLastProcessedGamestateID( unsigned int peerID );
+    virtual uint32_t  getCurrentGamestateID(){ return currentGamestate_->getID(); }
+    
     bool processGamestates();
+    bool sendAck(unsigned int gamestateID, uint32_t peerID);
     bool update();
-    void sendGamestates();
-//     packet::Gamestate *popGameState(unsigned int clientID);
-    void finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
+    std::vector<packet::Gamestate*> getGamestates();
+    void finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
 
     bool getSnapshot();
 
-    bool ack(unsigned int gamestateID, unsigned int clientID);
-    void removeClient(ClientInformation *client);
+    void addPeer( uint32_t peerID );
+    void setSynched( uint32_t peerID )
+      { assert(peerMap_.find(peerID)!=peerMap_.end()); peerMap_[peerID].isSynched = true; }
+    void removePeer( uint32_t peerID );
+//     void removeClient(ClientInformation *client);
+  protected:
+    virtual bool sendPacket( packet::Packet* packet ) = 0;
   private:
     bool processGamestate(packet::Gamestate *gs);
 
-    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
+//     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
     std::map<unsigned int, packet::Gamestate*> gamestateQueue;
-    packet::Gamestate *reference;
-    TrafficControl *trafficControl_;
+//     std::map<unsigned int, uint32_t> lastProcessedGamestateID_;
+    std::map<uint32_t, peerInfo> peerMap_;
+    packet::Gamestate* currentGamestate_;
+//     TrafficControl *trafficControl_;
     unsigned int id_;
 //     boost::mutex* threadMutex_;
     ThreadPool*   /*thread*/Pool_;

Modified: code/branches/presentation2/src/libraries/network/Host.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/Host.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/Host.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -44,7 +44,7 @@
 
   // Host*               Host::instance_=0;
   uint32_t            Host::clientID_s=0;
-  uint32_t            Host::shipID_s=-1;
+//   uint32_t            Host::shipID_s=-1;
   std::vector<Host*>  Host::instances_s;
 
   /**
@@ -75,18 +75,15 @@
   * @param clientID ID of the client the packet should be sent to
   * @return success?
   */
-  bool Host::addPacket(ENetPacket *packet, int clientID)
+  void Host::addPacket(ENetPacket *packet, int clientID, uint8_t channelID)
   {
-    bool result = true;
     for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
     {
       if( (*it)->isActive() )
       {
-        if( !(*it)->queuePacket(packet, clientID) )
-          result = false;
+        (*it)->queuePacket(packet, clientID, channelID);
       }
     }
-    return result;
   }
 
   void Host::Chat(const std::string& message)

Modified: code/branches/presentation2/src/libraries/network/Host.h
===================================================================
--- code/branches/presentation2/src/libraries/network/Host.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/Host.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -30,6 +30,7 @@
 #define _NETWORK_Host_H__
 
 #include "NetworkPrereqs.h"
+#include "GamestateManager.h"
 #include "core/CorePrereqs.h"
 
 #include <vector>
@@ -48,12 +49,13 @@
 *       - is the interface to be used when communicating with the network
 *       @author Oliver Scheuss
 */
-class _NetworkExport Host{
+class _NetworkExport Host: public GamestateManager
+{
   private:
     //TODO add these functions or adequate
     //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0;
     //virtual bool sendChat(packet::Chat *chat)=0;
-    virtual bool queuePacket(ENetPacket *packet, int clientID)=0;
+    virtual void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)=0;
     virtual bool chat(const std::string& message)=0;
     virtual bool broadcast(const std::string& message)=0;
     virtual bool processChat(const std::string& message, unsigned int playerID)=0;
@@ -70,13 +72,11 @@
   public:
 //     static Host* getInstance(){ return instance_; }
     static bool running(){ return instances_s.size(); }
-    static bool addPacket(ENetPacket *packet, int clientID=0);
+    static void addPacket(ENetPacket* packet, int clientID = NETWORK_PEER_ID_SERVER, uint8_t channelID = 0);
     //static bool chat(std::string& message);
 //     static bool receiveChat(packet::Chat *message, unsigned int clientID);
     static unsigned int getPlayerID(){ return clientID_s; }
-    static unsigned int getShipID(){return shipID_s;}
     static void setClientID(unsigned int id){ clientID_s = id; }
-    static void setShipID(unsigned int id){ shipID_s = id; }
     static bool isServer();
     static void Chat(const std::string& message);
     static bool Broadcast(const std::string& message);
@@ -85,7 +85,6 @@
     bool isActive(){ return bIsActive_; }
   private:
     static uint32_t clientID_s;
-    static uint32_t shipID_s;
     static std::vector<Host*> instances_s;
     bool bIsActive_;
 };

Modified: code/branches/presentation2/src/libraries/network/MasterServerComm.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/MasterServerComm.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/MasterServerComm.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -89,7 +89,7 @@
     }
 
     /* Wait up to 2 seconds for the connection attempt to succeed. */
-    if (enet_host_service (this->client, this->event, 2000) > 0 &&
+    if (enet_host_service (this->client, this->event, 500) > 0 &&
         this->event->type == ENET_EVENT_TYPE_CONNECT )
       COUT(3) << "Connection to master server succeeded.\n";
     else

Modified: code/branches/presentation2/src/libraries/network/NetworkPrereqs.h
===================================================================
--- code/branches/presentation2/src/libraries/network/NetworkPrereqs.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/NetworkPrereqs.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -63,11 +63,15 @@
 
 namespace orxonox
 {
-  static const unsigned int GAMESTATEID_INITIAL     = static_cast<unsigned int>(-1);
-  static const unsigned int CLIENTID_UNKNOWN        = static_cast<unsigned int>(-2);
+  static const unsigned int GAMESTATEID_INITIAL       = static_cast<unsigned int>(-1);
+  static const unsigned int CLIENTID_UNKNOWN          = static_cast<unsigned int>(-2);
   extern const char* LAN_DISCOVERY_MESSAGE;
   extern const char* LAN_DISCOVERY_ACK;
-  static const unsigned int LAN_DISCOVERY_PORT      = 55557;
+  static const unsigned int LAN_DISCOVERY_PORT          = 55557;
+  static const unsigned int NETWORK_PEER_ID_SERVER      = 0;
+  static const unsigned int NETWORK_CHANNEL_DEFAULT     = 0;
+  static const unsigned int NETWORK_CHANNEL_UNRELIABLE  = 1;
+  static const unsigned int NETWORK_CHANNEL_COUNT       = 2;
 }
 
 //-----------------------------------------------------------------------
@@ -82,9 +86,9 @@
     {
       enum Value
       {
-        Reliable   = 1,
-        Unsequence = 2,
-        NoAllocate = 4
+        Reliable    = 1,
+        Unsequenced = 2,
+        NoAllocate  = 4
       };
     }
   }
@@ -96,15 +100,16 @@
 
 // from ENet
 struct _ENetPeer;
-typedef _ENetPeer ENetPeer;
+typedef _ENetPeer     ENetPeer;
 struct _ENetPacket;
-typedef _ENetPacket ENetPacket;
+typedef _ENetPacket   ENetPacket;
 struct _ENetEvent;
-typedef _ENetEvent ENetEvent;
+typedef _ENetEvent    ENetEvent;
 struct _ENetHost;
-typedef _ENetHost ENetHost;
+typedef _ENetHost     ENetHost;
 struct _ENetAddress;
-typedef _ENetAddress ENetAddress;
+typedef _ENetAddress  ENetAddress;
+typedef uint8_t       ENetChannelID;
 
 namespace orxonox
 {
@@ -160,4 +165,10 @@
   class SynchronisableVariableBidirectional;
 }
 
+namespace boost
+{
+  class mutex;
+  class thread;
+}
+
 #endif /* _NetworkPrereqs_H__ */

Modified: code/branches/presentation2/src/libraries/network/Server.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/Server.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/Server.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -155,8 +155,8 @@
     packet::Chat *chat;
     while(temp){
       chat = new packet::Chat(message, playerID);
-      chat->setClientID(temp->getID());
-      if(!chat->send())
+      chat->setPeerID(temp->getID());
+      if(!chat->send( static_cast<Host*>(this) ))
         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
       temp = temp->next();
     }
@@ -210,9 +210,10 @@
     {
       // process incoming gamestates
       GamestateManager::processGamestates();
+      FunctionCallManager::processBufferedFunctionCalls();
 
       // send function calls to clients
-      FunctionCallManager::sendCalls();
+      FunctionCallManager::sendCalls( static_cast<Host*>(this) );
 
       //this steers our network frequency
       timeSinceLastUpdate_+=time.getDeltaTime();
@@ -221,13 +222,13 @@
         timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
         updateGamestate();
       }
-      sendPackets(); // flush the enet queue
+//       sendPackets(); // flush the enet queue
     }
   }
 
-  bool Server::queuePacket(ENetPacket *packet, int clientID)
+  void Server::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)
   {
-    return ServerConnection::addPacket(packet, clientID);
+    ServerConnection::addPacket(packet, clientID, channelID);
   }
 
   /**
@@ -263,60 +264,30 @@
       //no client connected
       return;
     GamestateManager::update();
-    COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
+//     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
     //std::cout << "updated gamestate, sending it" << std::endl;
     //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
-    sendGameState();
+    sendGameStates();
     sendObjectDeletes();
-    COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
+//     COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
     //std::cout << "sent gamestate" << std::endl;
   }
 
-  bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){
-    packet::Packet *p = packet::Packet::createPacket(packet, peer);
-    return p->process();
-  }
-
   /**
-  * sends the gamestate
+  * sends the current gamestate to all peers
   */
-  bool Server::sendGameState()
+  bool Server::sendGameStates()
   {
-//     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();
+    std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
+    std::vector<packet::Gamestate*>::iterator it;
+    for( it = gamestates.begin(); it != gamestates.end(); ++it )
+    {
+      (*it)->send(static_cast<Host*>(this));
+    }
     return true;
   }
 
+
   bool Server::sendObjectDeletes()
   {
     ClientInformation *temp = ClientInformation::getBegin();
@@ -340,9 +311,9 @@
       int cid = temp->getID(); //get client id
       packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
       assert(cd);
-      cd->setClientID(cid);
-      if ( !cd->send() )
-        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
+      cd->setPeerID(cid);
+      if ( !cd->send( static_cast<Host*>(this) ) )
+        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl;
       temp=temp->next();
       // gs gets automatically deleted by enet callback
     }
@@ -366,6 +337,7 @@
 
     // inform all the listeners
     ClientConnectionListener::broadcastClientConnected(newid);
+    GamestateManager::addPeer(newid);
 
     ++newid;
 
@@ -381,12 +353,27 @@
       return;
     else
     {
+      GamestateManager::removePeer(client->getID());
       //ServerConnection::disconnectClient( client );
       //ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now
       delete client;
     }
   }
+  
+  void Server::processPacket(packet::Packet* packet)
+  {
+    if( packet->isReliable() )
+    {
+      if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
+        packet->process(static_cast<Host*>(this));
+      else
+        this->packetQueue_.push_back(packet);
+    }
+    else
+      packet->process(static_cast<Host*>(this));
+  }
 
+
   bool Server::createClient(int clientID)
   {
     ClientInformation *temp = ClientInformation::findClient(clientID);
@@ -395,39 +382,42 @@
       COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
       return false;
     }
-    COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl;
+    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
 
     // synchronise class ids
     syncClassid(temp->getID());
 
     // now synchronise functionIDs
     packet::FunctionIDs *fIDs = new packet::FunctionIDs();
-    fIDs->setClientID(clientID);
-    bool b = fIDs->send();
+    fIDs->setPeerID(clientID);
+    bool b = fIDs->send( static_cast<Host*>(this) );
     assert(b);
 
     temp->setSynched(true);
+    GamestateManager::setSynched(clientID);
+    
     COUT(4) << "sending welcome" << std::endl;
     packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
-    w->setClientID(temp->getID());
-    b = w->send();
+    w->setPeerID(temp->getID());
+    b = w->send( static_cast<Host*>(this) );
     assert(b);
     packet::Gamestate *g = new packet::Gamestate();
-    g->setClientID(temp->getID());
-    b = g->collectData(0,0x1);
+    g->setPeerID(temp->getID());
+    b = g->collectData(0,packet::GAMESTATE_MODE_SERVER);
+    assert(b);
     if(!b)
       return false; //no data for the client
-    b = g->compressData();
+//     b = g->compressData();
+//     assert(b);
+    b = g->send( static_cast<Host*>(this) );
     assert(b);
-    b = g->send();
-    assert(b);
     return true;
   }
 
   void Server::disconnectClient( ClientInformation *client )
   {
     ServerConnection::disconnectClient( client );
-    GamestateManager::removeClient(client);
+    GamestateManager::removePeer(client->getID());
     // inform all the listeners
     // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
   }
@@ -449,8 +439,8 @@
     while(temp)
     {
       chat = new packet::Chat(message, clientID);
-      chat->setClientID(temp->getID());
-      if(!chat->send())
+      chat->setPeerID(temp->getID());
+      if(!chat->send( static_cast<Host*>(this) ))
         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
       temp = temp->next();
     }
@@ -465,8 +455,8 @@
   {
     int failures=0;
     packet::ClassID *classid = new packet::ClassID();
-    classid->setClientID(clientID);
-    while(!classid->send() && failures < 10){
+    classid->setPeerID(clientID);
+    while(!classid->send( static_cast<Host*>(this) ) && failures < 10){
       failures++;
     }
     assert(failures<10);

Modified: code/branches/presentation2/src/libraries/network/Server.h
===================================================================
--- code/branches/presentation2/src/libraries/network/Server.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/Server.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -31,10 +31,12 @@
 
 #include "NetworkPrereqs.h"
 
+#include <deque>
+
 #include "util/UtilPrereqs.h"
 #include "core/CorePrereqs.h"
 #include "Host.h"
-#include "GamestateManager.h"
+// #include "GamestateManager.h"
 #include "ServerConnection.h"
 #include "LANDiscoverable.h"
 #include "MasterServerComm.h"
@@ -48,7 +50,7 @@
   * This class is the root class of the network module for a server.
   * It implements all functions necessary for a Server
   */
-  class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager, public LANDiscoverable{
+  class _NetworkExport Server : public Host, public ServerConnection, public LANDiscoverable{
   public:
     Server();
     Server(int port);
@@ -63,7 +65,8 @@
     void open();
     void close();
     bool processChat(const std::string& message, unsigned int playerID);
-    bool queuePacket(ENetPacket *packet, int clientID);
+    void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID);
+    virtual bool sendPacket( packet::Packet* packet ){ return packet->send( static_cast<Host*>(this) ); }
     void update(const Clock& time);
     unsigned int getRTT(unsigned int clientID);
     virtual void printRTT();
@@ -72,16 +75,15 @@
     void updateGamestate();
   private:
     virtual bool isServer_(){return true;}
-    unsigned int shipID(){return 0;}
     unsigned int playerID(){return 0;}
 
     void addPeer(ENetEvent *event);
     void removePeer(ENetEvent *event);
+    void processPacket(packet::Packet* packet);
 
     bool createClient(int clientID);
     void disconnectClient( ClientInformation *client);
-    bool processPacket( ENetPacket *packet, ENetPeer *peer );
-    bool sendGameState();
+    bool sendGameStates();
     bool sendObjectDeletes();
     virtual bool chat(const std::string& message);
     virtual bool broadcast(const std::string& message);
@@ -89,6 +91,7 @@
     void syncClassid(unsigned int clientID);
 
     float timeSinceLastUpdate_;
+    std::deque<packet::Packet*> packetQueue_;
   };
 
 

Modified: code/branches/presentation2/src/libraries/network/ServerConnection.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/ServerConnection.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/ServerConnection.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -48,13 +48,15 @@
     this->bindAddress_->port = NETWORK_PORT;
   }
 
-  ServerConnection::~ServerConnection(){
+  ServerConnection::~ServerConnection()
+  {
     if ( this->bListening_ )
       closeListener();
     delete this->bindAddress_;
   }
 
-  void ServerConnection::setBindAddress( const std::string& bindAddress ) {
+  void ServerConnection::setBindAddress( const std::string& bindAddress )
+  {
     if (enet_address_set_host (this->bindAddress_, bindAddress.c_str()) < 0)
         COUT(1) << "Error: Could not resolve \"" << bindAddress << "\"." << std::endl;
   }
@@ -63,13 +65,19 @@
       this->bindAddress_->port = port;
   }
 
-  bool ServerConnection::openListener() {
-    this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0, 0);
+  bool ServerConnection::openListener()
+  {
+    // create host
+    this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0);
+    
     if ( this->host_ == NULL )
     {
         COUT(1) << "ServerConnection: host_ == NULL" << std::endl;
         return false;
     }
+    
+    // enable compression
+    this->enableCompression();
     assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
     if (this->host_->socket4 == ENET_SOCKET_NULL)
         COUT(2) << "Warning: IPv4 Socket failed." << std::endl;
@@ -77,89 +85,74 @@
         COUT(2) << "Warning: IPv6 Socket failed." << std::endl;
     else
         COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
+    
+    // start communication thread
+    Connection::startCommunicationThread();
 
     return true;
   }
 
-  bool ServerConnection::closeListener() {
+  bool ServerConnection::closeListener()
+  {
     this->bListening_=false;
     disconnectClients();
+    Connection::stopCommunicationThread();
     enet_host_destroy(this->host_);
     return true;
   }
 
-  bool ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID) {
+  void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID)
+  {
     if ( clientID == CLIENTID_UNKNOWN )
     {
-      return addPacketAll(packet);
+      broadcastPacket(packet, channelID);
     }
     else
     {
       ClientInformation *temp = ClientInformation::findClient(clientID);
       if(!temp){
         COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
-        return false;
       }
-      return Connection::addPacket(packet, temp->getPeer());
+      Connection::addPacket(packet, temp->getPeer(), channelID);
     }
   }
 
-  bool ServerConnection::addPacketAll(ENetPacket *packet) {
-//     if ( !Connection::getInstance() )
-//       return false;
-    enet_host_broadcast( Connection::getHost(), 0, packet);
-    return true;
-  }
-
   void ServerConnection::disconnectClient(ClientInformation *client)
   {
     Connection::disconnectPeer( client->getPeer() );
   }
 
-  void ServerConnection::disconnectClient(int clientID){
+  void ServerConnection::disconnectClient(int clientID)
+  {
     ClientInformation *client = ClientInformation::findClient(clientID);
     if(client)
       ServerConnection::disconnectClient(client);
   }
 
-  void ServerConnection::disconnectClients() {
-    ENetEvent event;
+  void ServerConnection::disconnectClients()
+  {
     ClientInformation *temp = ClientInformation::getBegin();
-    while(temp!=0){
+    while(temp!=0)
+    {
       ServerConnection::disconnectClient( temp );
       temp = temp->next();
     }
-    temp = ClientInformation::getBegin();
-    while( temp!=0 ){
-      if( service( &event ) )
-      {
-        switch (event.type)
-        {
-        case ENET_EVENT_TYPE_NONE: break;
-        case ENET_EVENT_TYPE_CONNECT: break;
-        case ENET_EVENT_TYPE_RECEIVE:
-          enet_packet_destroy(event.packet);
-          break;
-        case ENET_EVENT_TYPE_DISCONNECT:
-          removePeer( &event );
-          temp = ClientInformation::getBegin();
-          break;
-        }
-      }
-    }
     return;
   }
 
 
-  int ServerConnection::getClientID(ENetPeer* peer) {
+  int ServerConnection::getClientID(ENetPeer* peer)
+  {
     return getClientID(&(peer->address));
   }
 
-  int ServerConnection::getClientID(ENetAddress* address) {
+  int ServerConnection::getClientID(ENetAddress* address)
+  {
     return ClientInformation::findClient(address)->getID();
   }
 
-  ENetPeer *ServerConnection::getClientPeer(int clientID) {
+  ENetPeer *ServerConnection::getClientPeer(int clientID)
+  {
     return ClientInformation::findClient(clientID)->getPeer();
   }
 

Modified: code/branches/presentation2/src/libraries/network/ServerConnection.h
===================================================================
--- code/branches/presentation2/src/libraries/network/ServerConnection.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/ServerConnection.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -55,8 +55,7 @@
 
     bool openListener();
     bool closeListener();
-    bool addPacket(ENetPacket *packet, unsigned int ID);
-    bool addPacketAll(ENetPacket *packet);
+    void addPacket(ENetPacket *packet, unsigned int ID, uint8_t channelID);
     virtual void disconnectClient(ClientInformation *client);
     void disconnectClient(int clientID);
   protected:

Modified: code/branches/presentation2/src/libraries/network/WANDiscovery.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/WANDiscovery.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/WANDiscovery.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -70,7 +70,7 @@
     /* update msaddress string from orxonox.ini config file, if it 
      * has changed. 
      */
-    SetConfigValue( msaddress, "localhost");
+    SetConfigValue( msaddress, "orxonox.net");
   } 
 
   WANDiscovery::~WANDiscovery()

Modified: code/branches/presentation2/src/libraries/network/packet/Acknowledgement.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/Acknowledgement.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/Acknowledgement.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -30,6 +30,7 @@
 
 #include "util/Debug.h"
 #include "network/GamestateHandler.h"
+#include "network/Host.h"
 
 namespace orxonox {
 namespace packet {
@@ -38,18 +39,18 @@
 #define _PACKETID           0
 #define _ACKID              _PACKETID + sizeof(packet::Type::Value)
 
-Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
+Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID )
  : Packet()
 {
   flags_ = flags_ | PACKET_FLAGS_ACK;
   data_=new uint8_t[ getSize() ];
   *(Type::Value *)(data_ + _PACKETID ) = Type::Acknowledgement;
   *(uint32_t *)(data_ + _ACKID ) = id;
-  clientID_=clientID;
+  peerID_=peerID;
 }
 
-Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID )
-  : Packet(data, clientID)
+Acknowledgement::Acknowledgement( uint8_t *data, unsigned int peerID )
+  : Packet(data, peerID)
 {
 }
 
@@ -61,9 +62,9 @@
   return _ACKID + sizeof(uint32_t);
 }
 
-bool Acknowledgement::process(){
+bool Acknowledgement::process(orxonox::Host* host){
   COUT(5) << "processing ACK with ID: " << getAckID() << endl;
-  bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);
+  bool b = host->ackGamestate(getAckID(), peerID_);
   delete this;
   return b;
 }

Modified: code/branches/presentation2/src/libraries/network/packet/Acknowledgement.h
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/Acknowledgement.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/Acknowledgement.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -41,12 +41,12 @@
 class _NetworkExport Acknowledgement : public Packet
 {
 public:
-  Acknowledgement( unsigned int id, unsigned int clientID );
-  Acknowledgement( uint8_t* data, unsigned int clientID );
+  Acknowledgement( unsigned int id, unsigned int peerID );
+  Acknowledgement( uint8_t* data, unsigned int peerID );
   ~Acknowledgement();
 
   inline unsigned int getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
   unsigned int getAckID();
 private:

Modified: code/branches/presentation2/src/libraries/network/packet/Chat.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/Chat.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/Chat.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -79,8 +79,8 @@
   return _MESSAGE + messageLength_;
 }
 
-bool Chat::process(){
-  bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
+bool Chat::process(orxonox::Host* host){
+  bool b = host->incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
   delete this;
   return b;
 }

Modified: code/branches/presentation2/src/libraries/network/packet/Chat.h
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/Chat.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/Chat.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -51,7 +51,7 @@
   inline unsigned int getSize() const;
 
   /* process chat message packet and remove it afterwards */
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
   /* Get the length of the message (not the full size of the packet) */
   unsigned int getMessageLength(){ return messageLength_; };

Modified: code/branches/presentation2/src/libraries/network/packet/ClassID.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/ClassID.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/ClassID.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -119,7 +119,7 @@
 }
 
 
-bool ClassID::process(){
+bool ClassID::process(orxonox::Host* host){
   int nrOfClasses;
   uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
   uint32_t networkID;

Modified: code/branches/presentation2/src/libraries/network/packet/ClassID.h
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/ClassID.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/ClassID.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -47,7 +47,7 @@
   ~ClassID();
 
   uint32_t getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
 };

Modified: code/branches/presentation2/src/libraries/network/packet/DeleteObjects.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/DeleteObjects.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/DeleteObjects.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -56,7 +56,8 @@
 {
 }
 
-bool DeleteObjects::fetchIDs(){
+bool DeleteObjects::fetchIDs()
+{
   unsigned int number = Synchronisable::getNumberOfDeletedObject();
   if(number==0)
     return false;
@@ -78,13 +79,16 @@
   return true;
 }
 
-unsigned int DeleteObjects::getSize() const{
+unsigned int DeleteObjects::getSize() const
+{
   assert(data_);
   return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t);
 }
 
-bool DeleteObjects::process(){
-  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){
+bool DeleteObjects::process(orxonox::Host* host)
+{
+  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++)
+  {
     COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;
     Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
   }

Modified: code/branches/presentation2/src/libraries/network/packet/DeleteObjects.h
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/DeleteObjects.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/DeleteObjects.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -31,8 +31,10 @@
 #include "network/NetworkPrereqs.h"
 #include "Packet.h"
 
-namespace orxonox {
-namespace packet {
+namespace orxonox
+{
+namespace packet
+{
 /**
     @author
 */
@@ -46,7 +48,7 @@
   bool fetchIDs();
 
   inline unsigned int getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
 };

Modified: code/branches/presentation2/src/libraries/network/packet/FunctionCalls.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/FunctionCalls.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/FunctionCalls.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -31,6 +31,7 @@
 #include <cassert>
 #include "network/FunctionCall.h"
 #include "network/FunctionCallManager.h"
+#include "network/GamestateHandler.h"
 
 namespace orxonox {
 namespace packet {
@@ -39,15 +40,15 @@
 #define   _PACKETID         0
 const unsigned int FUNCTIONCALLS_MEM_ALLOCATION = 1000;
 
-FunctionCalls::FunctionCalls()
- : Packet()
+FunctionCalls::FunctionCalls():
+  Packet(), minGamestateID_(GAMESTATEID_INITIAL)
 {
   flags_ = flags_ | PACKET_FLAGS_FUNCTIONCALLS;
-  currentSize_ = 2*sizeof(uint32_t); // for packetid and nrOfCalls
+  currentSize_ = 3*sizeof(uint32_t); // for packetid, nrOfCalls and minGamestateID_
 }
 
-FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID )
-  : Packet(data, clientID)
+FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID ): 
+  Packet(data, clientID), minGamestateID_(GAMESTATEID_INITIAL)
 {
 }
 
@@ -56,25 +57,31 @@
 }
 
 
-bool FunctionCalls::process(){
+bool FunctionCalls::process(orxonox::Host* host)
+{
   assert(isDataENetAllocated());
   
   uint8_t* temp = data_+sizeof(uint32_t); //skip packetid
   uint32_t nrOfCalls = *(uint32_t*)temp;
   temp += sizeof(uint32_t);
+  this->minGamestateID_ = *(uint32_t*)temp;
+  temp += sizeof(uint32_t);
   for( unsigned int i = 0; i<nrOfCalls; i++ )
   {
     FunctionCall fctCall;
     fctCall.loadData(temp);
     if( !fctCall.execute() )
-      FunctionCallManager::bufferIncomingFunctionCall( fctCall );
+    {
+      FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getPeerID() );
+    }
   }
   
   delete this;
   return true;
 }
 
-void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
+void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5)
+{
   assert(!isDataENetAllocated());
   
   this->functionCalls_.push(orxonox::FunctionCall());
@@ -82,7 +89,8 @@
   this->currentSize_ += this->functionCalls_.back().getSize();
 }
 
-void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
+void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5)
+{
   assert(!isDataENetAllocated());
   
   this->functionCalls_.push(orxonox::FunctionCall());
@@ -90,13 +98,15 @@
   this->currentSize_ += this->functionCalls_.back().getSize();
 }
 
-bool FunctionCalls::send()
+bool FunctionCalls::send(orxonox::Host* host)
 {
+  this->minGamestateID_ = host->getCurrentGamestateID();
   assert(this->functionCalls_.size());
   data_=new uint8_t[ currentSize_ ];
   *(Type::Value *)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID
-  *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls to 0
-  uint8_t* temp = data_+2*sizeof(uint32_t);
+  *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls
+  *(uint32_t*)(data_+2*sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_
+  uint8_t* temp = data_+3*sizeof(uint32_t);
   
   while( this->functionCalls_.size() )
   {
@@ -106,7 +116,7 @@
   
   assert( temp==data_+currentSize_ );
   
-  Packet::send();
+  Packet::send(host);
   return true;
 }
 

Modified: code/branches/presentation2/src/libraries/network/packet/FunctionCalls.h
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/FunctionCalls.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/FunctionCalls.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -53,14 +53,15 @@
 
   inline unsigned int getSize() const
     { assert(!this->isDataENetAllocated()); return currentSize_; }
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
   void addCallStatic( uint32_t networkID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
   void addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
-  virtual bool send();
+  virtual bool send(orxonox::Host* host);
 private:
   std::queue<orxonox::FunctionCall> functionCalls_;
   unsigned int                      clientID_;
+  uint32_t                          minGamestateID_;
   uint32_t                          currentSize_;
 };
 

Modified: code/branches/presentation2/src/libraries/network/packet/FunctionIDs.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/FunctionIDs.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/FunctionIDs.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -45,7 +45,8 @@
 #define _PACKETID                 0
 
 
-FunctionIDs::FunctionIDs( ) : Packet(){
+FunctionIDs::FunctionIDs( ) : Packet()
+{
   unsigned int nrOfFunctions=0;
   unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nroffunctions
   uint32_t networkID;
@@ -54,7 +55,8 @@
 
   //calculate total needed size (for all strings and integers)
   ObjectList<NetworkFunctionBase>::iterator it;
-  for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it){
+  for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it)
+  {
     const std::string& functionname = it->getName();
     networkID = it->getNetworkID();
     // now push the network id and the classname to the stack
@@ -75,7 +77,8 @@
 
   // now save all classids and classnames
   std::pair<uint32_t, std::string> tempPair;
-  while( !tempQueue.empty() ){
+  while( !tempQueue.empty() )
+  {
     tempPair = tempQueue.front();
     tempQueue.pop();
     *(uint32_t*)temp = tempPair.first;
@@ -97,7 +100,8 @@
 {
 }
 
-uint32_t FunctionIDs::getSize() const{
+uint32_t FunctionIDs::getSize() const
+{
   assert(this->data_);
   uint8_t *temp = data_+sizeof(uint32_t); // packet identification
   uint32_t totalsize = sizeof(uint32_t); // data size
@@ -113,7 +117,8 @@
 }
 
 
-bool FunctionIDs::process(){
+bool FunctionIDs::process(orxonox::Host* host)
+{
   int nrOfFunctions;
   uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
   uint32_t networkID;
@@ -126,7 +131,8 @@
   nrOfFunctions = *(uint32_t*)temp;
   temp += sizeof(uint32_t);
 
-  for( int i=0; i<nrOfFunctions; i++){
+  for( int i=0; i<nrOfFunctions; i++)
+  {
     networkID = *(uint32_t*)temp;
     stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
     functionname = temp+2*sizeof(uint32_t);

Modified: code/branches/presentation2/src/libraries/network/packet/FunctionIDs.h
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/FunctionIDs.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/FunctionIDs.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -46,8 +46,8 @@
   FunctionIDs( uint8_t* data, unsigned int clientID );
   ~FunctionIDs();
 
-  uint32_t getSize() const;
-  bool process();
+  virtual uint32_t getSize() const;
+  virtual bool process(orxonox::Host* host);
 
 private:
 };

Modified: code/branches/presentation2/src/libraries/network/packet/Gamestate.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/Gamestate.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/Gamestate.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -35,6 +35,7 @@
 #include "core/ObjectList.h"
 #include "network/synchronisable/Synchronisable.h"
 #include "network/GamestateHandler.h"
+#include "network/Host.h"
 
 namespace orxonox {
 
@@ -42,7 +43,8 @@
 
 #define GAMESTATE_START(data) (data + GamestateHeader::getSize())
 
-#define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
+// #define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
+#define PACKET_FLAG_GAMESTATE  0
 
 inline bool memzero( uint8_t* data, uint32_t datalength)
 {
@@ -64,47 +66,42 @@
 
 
 Gamestate::Gamestate():
-  header_(0)
+  header_()
 {
   flags_ = flags_ | PACKET_FLAG_GAMESTATE;
 }
 
 
 Gamestate::Gamestate(uint8_t *data, unsigned int clientID):
-  Packet(data, clientID)
+  Packet(data, clientID), header_(data)
 {
   flags_ = flags_ | PACKET_FLAG_GAMESTATE;
-  header_ = new GamestateHeader(data_);
 }
 
 
-Gamestate::Gamestate(uint8_t *data)
+Gamestate::Gamestate(uint8_t *data):
+  header_(data)
 {
   flags_ = flags_ | PACKET_FLAG_GAMESTATE;
   data_ = data;
-  header_ = new GamestateHeader(data_);
 }
 
 
 Gamestate::Gamestate(const Gamestate& g) :
-    Packet( *(Packet*)&g ), nrOfVariables_(0)
+  Packet( *(Packet*)&g ), header_(this->data_), nrOfVariables_(0)
 {
   flags_ = flags_ | PACKET_FLAG_GAMESTATE;
-  header_ = new GamestateHeader(data_);
   sizes_ = g.sizes_;
 }
 
 
 Gamestate::~Gamestate()
 {
-  if( header_ )
-    delete header_;
 }
 
 
 bool Gamestate::collectData(int id, uint8_t mode)
 {
-  assert(this->header_==0); // make sure the header didn't exist before
   uint32_t tempsize=0, currentsize=0;
   assert(data_==0);
   uint32_t size = calcGamestateSize(id, mode);
@@ -119,9 +116,8 @@
     return false;
   }
 
-  // create the header object
-  assert( header_ == 0 );
-  header_ = new GamestateHeader(data_);
+  // tell the gamestate header where to store the data
+  header_.setData(this->data_);
 
   //start collect data synchronisable by synchronisable
   uint8_t *mem = data_; // in this stream store all data of the variables and the headers of the synchronisable
@@ -141,7 +137,7 @@
     {
       assert(0); // if we don't use multithreading this part shouldn't be neccessary
       // start allocate additional memory
-      COUT(3) << "G.St.Man: need additional memory" << std::endl;
+      COUT(3) << "Gamestate: need additional memory" << std::endl;
       ObjectList<Synchronisable>::iterator temp = it;
       uint32_t addsize=tempsize;
       while(++temp)
@@ -160,30 +156,30 @@
 
 
   //start write gamestate header
-  header_->setDataSize( currentsize );
-  header_->setID( id );
-  header_->setBaseID( GAMESTATEID_INITIAL );
-  header_->setDiffed( false );
-  header_->setComplete( true );
-  header_->setCompressed( false );
+  header_.setDataSize( currentsize );
+  header_.setID( id );
+  header_.setBaseID( GAMESTATEID_INITIAL );
+  header_.setDiffed( false );
+  header_.setComplete( true );
+  header_.setCompressed( false );
   //stop write gamestate header
 
-  COUT(5) << "G.ST.Man: Gamestate size: " << currentsize << std::endl;
-  COUT(5) << "G.ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
+  COUT(5) << "Gamestate: Gamestate size: " << currentsize << std::endl;
+  COUT(5) << "Gamestate: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
   return true;
 }
 
 
 bool Gamestate::spreadData(uint8_t mode)
 {
-  COUT(4) << "processing gamestate with id " << header_->getID() << endl;
+  COUT(5) << "processing gamestate with id " << header_.getID() << endl;
   assert(data_);
-  assert(!header_->isCompressed());
+  assert(!header_.isCompressed());
   uint8_t *mem=data_+GamestateHeader::getSize();
   Synchronisable *s;
-
+  
   // update the data of the objects we received
-  while(mem < data_+GamestateHeader::getSize()+header_->getDataSize())
+  while(mem < data_+GamestateHeader::getSize()+header_.getDataSize())
   {
     SynchronisableHeader objectheader(mem);
 
@@ -196,15 +192,19 @@
       }
       else
       {
+//         COUT(4) << "not creating object of classid " << objectheader.getClassID() << endl;
         mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() );
       }
     }
     else
     {
+//       COUT(4) << "updating object of classid " << objectheader.getClassID() << endl;
       bool b = s->updateData(mem, mode);
       assert(b);
     }
   }
+  assert(mem-data_ == GamestateHeader::getSize()+header_.getDataSize());
+  
    // In debug mode, check first, whether there are no duplicate objectIDs
 #ifndef NDEBUG
   if(this->getID()%1000==1)
@@ -248,11 +248,11 @@
 uint32_t Gamestate::getSize() const
 {
   assert(data_);
-  if(header_->isCompressed())
-    return header_->getCompSize()+GamestateHeader::getSize();
+  if(header_.isCompressed())
+    return header_.getCompSize()+GamestateHeader::getSize();
   else
   {
-    return header_->getDataSize()+GamestateHeader::getSize();
+    return header_.getDataSize()+GamestateHeader::getSize();
   }
 }
 
@@ -270,17 +270,17 @@
 }
 
 
-bool Gamestate::process()
+bool Gamestate::process(orxonox::Host* host)
 {
-  return GamestateHandler::addGamestate(this, getClientID());
+  return host->addGamestate(this, getPeerID());
 }
 
 
 bool Gamestate::compressData()
 {
   assert(data_);
-  assert(!header_->isCompressed());
-  uLongf buffer = (uLongf)(((header_->getDataSize() + 12)*1.01)+1);
+  assert(!header_.isCompressed());
+  uLongf buffer = (uLongf)(((header_.getDataSize() + 12)*1.01)+1);
   if(buffer==0)
     return false;
 
@@ -288,7 +288,7 @@
   uint8_t *dest = ndata + GamestateHeader::getSize();
   uint8_t *source = data_ + GamestateHeader::getSize();
   int retval;
-  retval = compress( dest, &buffer, source, (uLong)(header_->getDataSize()) );
+  retval = compress( dest, &buffer, source, (uLong)(header_.getDataSize()) );
   switch ( retval )
   {
     case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
@@ -298,16 +298,17 @@
   }
 
   //copy and modify header
-  GamestateHeader *temp = header_;
-  header_ = new GamestateHeader(ndata, temp);
+  GamestateHeader *temp = new GamestateHeader(data_);
+  header_.setData(ndata);
+  header_ = *temp;
   delete temp;
   //delete old data
   delete[] data_;
   //save new data
   data_ = ndata;
-  header_->setCompSize( buffer );
-  header_->setCompressed( true );
-  COUT(0) << "gamestate compress datasize: " << header_->getDataSize() << " compsize: " << header_->getCompSize() << std::endl;
+  header_.setCompSize( buffer );
+  header_.setCompressed( true );
+  COUT(4) << "gamestate compress datasize: " << header_.getDataSize() << " compsize: " << header_.getCompSize() << std::endl;
   return true;
 }
 
@@ -315,10 +316,10 @@
 bool Gamestate::decompressData()
 {
   assert(data_);
-  assert(header_->isCompressed());
-  COUT(4) << "GameStateClient: uncompressing gamestate. id: " << header_->getID() << ", baseid: " << header_->getBaseID() << ", datasize: " << header_->getDataSize() << ", compsize: " << header_->getCompSize() << std::endl;
-  uint32_t datasize = header_->getDataSize();
-  uint32_t compsize = header_->getCompSize();
+  assert(header_.isCompressed());
+  COUT(4) << "GameStateClient: uncompressing gamestate. id: " << header_.getID() << ", baseid: " << header_.getBaseID() << ", datasize: " << header_.getDataSize() << ", compsize: " << header_.getCompSize() << std::endl;
+  uint32_t datasize = header_.getDataSize();
+  uint32_t compsize = header_.getCompSize();
   uint32_t bufsize;
   bufsize = datasize;
   assert(bufsize!=0);
@@ -337,8 +338,9 @@
   }
 
   //copy over the header
-  GamestateHeader *temp = header_;
-  header_ = new GamestateHeader( data_, header_ );
+  GamestateHeader* temp = new GamestateHeader( data_ );
+  header_.setData(ndata);
+  header_ = *temp;
   delete temp;
 
   if (this->bDataENetAllocated_)
@@ -356,221 +358,238 @@
 
   //set new pointers
   data_ = ndata;
-  header_->setCompressed( false );
-  assert(header_->getDataSize()==datasize);
-  assert(header_->getCompSize()==compsize);
+  header_.setCompressed( false );
+  assert(header_.getDataSize()==datasize);
+  assert(header_.getCompSize()==compsize);
   return true;
 }
 
 
+inline void /*Gamestate::*/diffObject( uint8_t*& newDataPtr, uint8_t*& origDataPtr, uint8_t*& baseDataPtr, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes )
+{
+  assert( objectHeader.getDataSize() == SynchronisableHeader(baseDataPtr).getDataSize() );
+  
+  uint32_t objectOffset = SynchronisableHeader::getSize(); // offset inside the object in the origData and baseData
+  // Check whether the whole object stayed the same
+  if( memcmp( origDataPtr+objectOffset, baseDataPtr+objectOffset, objectHeader.getDataSize()) == 0 )
+  {
+//     COUT(4) << "skip object " << Synchronisable::getSynchronisable(objectHeader.getObjectID())->getIdentifier()->getName() << endl;
+    origDataPtr += objectOffset + objectHeader.getDataSize(); // skip the whole object
+    baseDataPtr += objectOffset + objectHeader.getDataSize();
+    sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables();
+  }
+  else
+  {
+    // Now start to diff the Object
+    SynchronisableHeaderLight newObjectHeader(newDataPtr);
+    newObjectHeader = objectHeader; // copy over the objectheader
+    VariableID variableID = 0;
+    uint32_t diffedObjectOffset = SynchronisableHeaderLight::getSize();
+    // iterate through all variables
+    while( objectOffset < objectHeader.getDataSize()+SynchronisableHeader::getSize() )
+    {
+      // check whether variable changed and write id and copy over variable to the new stream
+      // otherwise skip variable
+      uint32_t varSize = *sizes;
+      assert( varSize == Synchronisable::getSynchronisable(objectHeader.getObjectID())->getVarSize(variableID) );
+      if ( varSize != 0 )
+      {
+        if ( memcmp(origDataPtr+objectOffset, baseDataPtr+objectOffset, varSize) != 0 )
+        {
+          *(VariableID*)(newDataPtr+diffedObjectOffset) = variableID; // copy over the variableID
+          diffedObjectOffset += sizeof(VariableID);
+          memcpy( newDataPtr+diffedObjectOffset, origDataPtr+objectOffset, varSize );
+          diffedObjectOffset += varSize;
+          objectOffset += varSize;
+        }
+        else
+        {
+          objectOffset += varSize;
+        }
+      }
+
+      ++variableID;
+      ++sizes;
+    }
+    
+    // if there are variables from this object with 0 size left in sizes
+    if( Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() != variableID )
+      sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() - variableID;
+    
+    newObjectHeader.setDiffed(true);
+    newObjectHeader.setDataSize(diffedObjectOffset-SynchronisableHeaderLight::getSize());
+    assert(objectOffset == objectHeader.getDataSize()+SynchronisableHeader::getSize());
+    assert(newObjectHeader.getDataSize()>0);
+    
+    origDataPtr += objectOffset;
+    baseDataPtr += objectOffset;
+    newDataPtr += diffedObjectOffset;
+  }
+}
+
+inline void /*Gamestate::*/copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes )
+{
+  //       COUT(4) << "docopy" << endl;
+  // Just copy over the whole Object
+  memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() );
+  SynchronisableHeader(newData).setDiffed(false);
+  
+  newData += objectHeader.getDataSize()+SynchronisableHeader::getSize();
+  origData += objectHeader.getDataSize()+SynchronisableHeader::getSize();
+//   SynchronisableHeader baseHeader( baseData );
+//   baseData += baseHeader.getDataSize()+SynchronisableHeader::getSize();
+  //       COUT(4) << "copy " << h.getObjectID() << endl;
+  //       COUT(4) << "copy " << h.getObjectID() << ":";
+  sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables();
+//   for( unsigned int i = 0; i < Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); ++i )
+//   {
+//     //         COUT(4) << " " << *sizes;
+//     ++sizes;
+//   }
+    //       COUT(4) << endl;
+}
+
+inline bool findObject(uint8_t*& dataPtr, uint8_t* endPtr, SynchronisableHeader& objectHeader)
+{
+  // Some assertions to make sure the dataPtr is valid (pointing to a SynchronisableHeader)
+  {
+    SynchronisableHeader htemp2(dataPtr);
+    assert(htemp2.getClassID()<500);
+    assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
+    assert(htemp2.isDiffed()==false);
+  }
+  uint32_t objectID = objectHeader.getObjectID();
+  while ( dataPtr < endPtr )
+  {
+    SynchronisableHeader htemp(dataPtr);
+    assert( htemp.getDataSize()!=0 );
+    if ( htemp.getObjectID() == objectID )
+    {
+      assert( objectHeader.getClassID() == htemp.getClassID() );
+      assert( objectHeader.getCreatorID() == htemp.getCreatorID() );
+      return true;
+    }
+    {
+      if( dataPtr+htemp.getDataSize()+SynchronisableHeader::getSize() < endPtr )
+      {
+        SynchronisableHeader htemp2(dataPtr+htemp.getDataSize()+SynchronisableHeader::getSize());
+        assert(htemp2.getClassID()<500);
+        assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
+        assert(htemp2.isDiffed()==false);
+      }
+    }
+    dataPtr += htemp.getDataSize()+SynchronisableHeader::getSize();
+    
+  }
+  assert(dataPtr == endPtr);
+  
+  return false;
+}
+
 Gamestate* Gamestate::diffVariables(Gamestate *base)
 {
   assert(this && base); assert(data_ && base->data_);
-  assert(!header_->isCompressed() && !base->header_->isCompressed());
-  assert(!header_->isDiffed());
+  assert(!header_.isCompressed() && !base->header_.isCompressed());
+  assert(!header_.isDiffed());
+  assert( header_.getDataSize() && base->header_.getDataSize() );
 
 
   // *** first do a raw diff of the two gamestates
 
-  uint8_t *baseData = GAMESTATE_START(base->data_);
-  uint8_t *origData = GAMESTATE_START(this->data_);
-  uint32_t origLength = header_->getDataSize();
-  uint32_t baseLength = base->header_->getDataSize();
+  uint8_t *baseDataPtr = GAMESTATE_START(base->data_);
+  uint8_t *origDataPtr = GAMESTATE_START(this->data_);
+  uint8_t *origDataEnd = origDataPtr + header_.getDataSize();
+  uint8_t *baseDataEnd = baseDataPtr + base->header_.getDataSize();
+//   uint32_t origLength = header_.getDataSize();
+//   uint32_t baseLength = base->header_.getDataSize();
 
-  assert( origLength && baseLength );
+  // Allocate new space for diffed gamestate
+  uint32_t newDataSize = header_.getDataSize() + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_;
+  uint8_t *newData = new uint8_t[newDataSize]; // this is the maximum size needed in the worst case
+  uint8_t *destDataPtr = GAMESTATE_START(newData);
 
-  uint8_t *nData = new uint8_t[origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_]; // this is the maximum size needed in the worst case
-  uint8_t *dest = GAMESTATE_START(nData);
+  std::vector<uint32_t>::iterator sizesIt = this->sizes_.begin();
 
-  uint32_t baseOffset = 0; //offset in the diffed stream
-  uint32_t origOffset = 0; //offset in the new stream with removed 0's
-  std::vector<uint32_t>::iterator sizes = this->sizes_.begin();
-
-  while( origOffset < origLength )
+  while( origDataPtr < origDataEnd )
   {
     //iterate through all objects
 
-    SynchronisableHeader h(origData+origOffset);
+    SynchronisableHeader origHeader(origDataPtr);
 
     // Find (if possible) the current object in the datastream of the old gamestate
     // Start at the current offset position
-    if(baseOffset >= baseLength)
-      baseOffset = 0;
-    uint8_t* temp = baseData + baseOffset;
-    uint32_t objectID = h.getObjectID();
-    assert(temp < baseData+baseLength);
-    assert(dest < nData + origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_);
-    assert(sizes != this->sizes_.end());
-    while ( temp < baseData+baseLength )
+    if(baseDataPtr == baseDataEnd)
+      baseDataPtr = GAMESTATE_START(base->data_);
+    uint8_t* oldBaseDataPtr = baseDataPtr;
+    
+    assert(baseDataPtr < baseDataEnd);
+    assert(destDataPtr < newData + newDataSize);
+    assert(sizesIt != this->sizes_.end());
+    
+    assert(Synchronisable::getSynchronisable(origHeader.getObjectID()));
+    assert(ClassByID(origHeader.getClassID()));
+    assert(origHeader.getDataSize() < 500);
+    
+    bool diffedObject = false;
+    if( findObject(baseDataPtr, baseDataEnd, origHeader) )
     {
-      SynchronisableHeader htemp(temp);
-      assert( htemp.getDataSize()!=0 );
-      if ( htemp.getObjectID() == objectID )
+      SynchronisableHeader baseHeader(baseDataPtr);
+      assert(Synchronisable::getSynchronisable(baseHeader.getObjectID()));
+      assert(ClassByID(baseHeader.getClassID()));
+      assert(baseHeader.getDataSize() < 500);
+      if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() )
       {
-        assert( h.getClassID() == htemp.getClassID() );
-        goto DODIFF;
+//         COUT(4) << "diffing object in order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+        diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+        diffedObject = true;
       }
-//       {
-//         SynchronisableHeader htemp2(temp+htemp.getDataSize()+SynchronisableHeader::getSize());
-//         if( temp+htemp.getDataSize()+SynchronisableHeader::getSize() < baseData+baseLength )
-//         {
-//           assert(htemp2.getClassID()<500);
-//           assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
-//           assert(htemp2.isDiffed()==false);
-//         }
-//       }
-      temp += htemp.getDataSize()+SynchronisableHeader::getSize();
-        
-    }
-    // If not found start looking at the beginning
-    assert( temp==baseData+baseLength );
-    temp = baseData;
-//     {
-//       SynchronisableHeader htemp2(temp);
-//       if( temp < baseData+baseLength )
-//       {
-//         assert(htemp2.getClassID()<500);
-//         assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
-//         assert(htemp2.isDiffed()==false);
-//       }
-//     }
-    while ( temp < baseData+baseOffset )
-    {
-      SynchronisableHeader htemp(temp);
-      if ( htemp.getObjectID() == objectID )
+      else
       {
-        assert( h.getClassID() == htemp.getClassID() );
-        goto DODIFF;
+//         COUT(4) << "copy object because of different data sizes (1): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+        copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+        assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd);
       }
-//       {
-//         SynchronisableHeader htemp2(temp+htemp.getDataSize()+SynchronisableHeader::getSize());
-//         if( temp+htemp.getDataSize()+SynchronisableHeader::getSize() < baseData+baseLength )
-//         {
-//           assert(htemp2.getClassID()<500);
-//           assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
-//           assert(htemp2.isDiffed()==false);
-//         }
-//       }
-      temp += htemp.getDataSize()+SynchronisableHeader::getSize();
+        
     }
-    // Object is new, thus never transmitted -> just copy over
-    goto DOCOPY;
-
-
-DODIFF:
+    else
     {
-//       COUT(4) << "dodiff" << endl;
-//       if(baseOffset==0)
-//       {
-//         assert(origOffset==0);
-//       }
-      uint32_t objectOffset = SynchronisableHeader::getSize(); // offset inside the object in the origData and baseData
-      // Check whether the whole object stayed the same
-      if( memcmp( origData+origOffset+objectOffset, temp+objectOffset, h.getDataSize()) == 0 )
+      assert( baseDataPtr == baseDataEnd );
+      baseDataPtr = GAMESTATE_START(base->data_);
+      if( findObject(baseDataPtr, oldBaseDataPtr, origHeader) )
       {
-//         COUT(4) << "skip object" << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;
-        origOffset += objectOffset+ h.getDataSize(); // skip the whole object
-        baseOffset = temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData;
-        sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables();
-      }
-      else
-      {
-//         if( Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() == "Bot" )
-//           COUT(0) << "blub" << endl;
-//         COUT(4) << "object diff: " << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;
-//         COUT(4) << "diff " << h.getObjectID() << ":";
-        // Now start to diff the Object
-        SynchronisableHeaderLight h2(dest);
-        h2 = h; // copy over the objectheader
-        VariableID variableID = 0;
-        uint32_t newObjectOffset = SynchronisableHeaderLight::getSize();
-        // iterate through all variables
-        while( objectOffset < h.getDataSize()+SynchronisableHeader::getSize() )
+        SynchronisableHeader baseHeader(baseDataPtr);
+        assert(Synchronisable::getSynchronisable(baseHeader.getObjectID()));
+        assert(ClassByID(baseHeader.getClassID()));
+        assert(baseHeader.getDataSize() < 500);
+        if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() )
         {
-          // check whether variable changed and write id and copy over variable to the new stream
-          // otherwise skip variable
-          assert(sizes != this->sizes_.end());
-          uint32_t varSize = *sizes;
-          assert( varSize == Synchronisable::getSynchronisable(h.getObjectID())->getVarSize(variableID) );
-          if ( varSize != 0 )
-          {
-            if ( memcmp(origData+origOffset+objectOffset, temp+objectOffset, varSize) != 0 )
-            {
-//               COUT(4) << "copy variable" << endl;
-              *(VariableID*)(dest+newObjectOffset) = variableID; // copy over the variableID
-              newObjectOffset += sizeof(VariableID);
-              memcpy( dest+newObjectOffset, origData+origOffset+objectOffset, varSize );
-              newObjectOffset += varSize;
-              objectOffset += varSize;
-            }
-            else
-            {
-//               COUT(4) << "skip variable" << endl;
-              objectOffset += varSize;
-            }
-          }
-//           else
-//             COUT(4) << "varsize 0" << endl;
-
-          ++variableID;
-          ++sizes;
+//           COUT(4) << "diffing object out of order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+          diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+          diffedObject = true;
         }
-        
-        if( Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() != variableID )
-          sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() - variableID;
-//         COUT(4) << endl;
-        h2.setDiffed(true);
-        h2.setDataSize(newObjectOffset-SynchronisableHeaderLight::getSize());
-        assert(objectOffset == h.getDataSize()+SynchronisableHeader::getSize());
-        origOffset += objectOffset;
-//         baseOffset += temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData;
-        //baseOffset += objectOffset;
-//         SynchronisableHeader htemp(temp);
-//         baseOffset += SynchronisableHeader::getSize() + htemp.getDataSize();
-//         {
-//           SynchronisableHeader htemp2( baseData+(temp-baseData+objectOffset) );
-//           if( baseData+(temp-baseData+objectOffset) < baseData+baseLength )
-//           {
-//             assert(htemp2.getClassID()<500);
-//             assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
-//             assert(htemp2.isDiffed()==false);
-//           }
-//         }
-        baseOffset = temp-baseData + objectOffset;
-        dest += newObjectOffset;
+        else
+        {
+//           COUT(4) << "copy object because of different data sizes (2): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+          copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+          assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd);
+        }
       }
-
-      continue;
-    }
-
-DOCOPY:
-    {
-//       COUT(4) << "docopy" << endl;
-      // Just copy over the whole Object
-      memcpy( dest, origData+origOffset, h.getDataSize()+SynchronisableHeader::getSize() );
-      dest += h.getDataSize()+SynchronisableHeader::getSize();
-      origOffset += h.getDataSize()+SynchronisableHeader::getSize();
-      assert( Synchronisable::getSynchronisable(h.getObjectID()) );
-//       COUT(4) << "copy " << h.getObjectID() << endl;
-//       COUT(4) << "copy " << h.getObjectID() << ":";
-      //sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables();
-      for( unsigned int i = 0; i < Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables(); ++i )
+      else
       {
-//         COUT(4) << " " << *sizes;
-        ++sizes;
+//         COUT(4) << "copy object: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+        assert(baseDataPtr == oldBaseDataPtr);
+        copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
+        assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd);
       }
-//       COUT(4) << endl;
-      assert(sizes != this->sizes_.end() || origOffset>=origLength);
-      continue;
     }
   }
+  assert(sizesIt==this->sizes_.end());
 
 
-  Gamestate *g = new Gamestate(nData, getClientID());
-  assert(g->header_);
-  *(g->header_) = *header_;
-  g->header_->setBaseID( base->getID() );
-  g->header_->setDataSize(dest - nData - GamestateHeader::getSize());
+  Gamestate *g = new Gamestate(newData, getPeerID());
+  (g->header_) = header_;
+  g->header_.setBaseID( base->getID() );
+  g->header_.setDataSize(destDataPtr - newData - GamestateHeader::getSize());
   g->flags_=flags_;
   g->packetDirection_ = packetDirection_;
   assert(!g->isCompressed());
@@ -578,15 +597,15 @@
 }
 
 
-Gamestate* Gamestate::diffData(Gamestate *base)
+/*Gamestate* Gamestate::diffData(Gamestate *base)
 {
   assert(this && base); assert(data_ && base->data_);
-  assert(!header_->isCompressed() && !base->header_->isCompressed());
-  assert(!header_->isDiffed());
+  assert(!header_.isCompressed() && !base->header_.isCompressed());
+  assert(!header_.isDiffed());
 
   uint8_t *basep = GAMESTATE_START(base->data_);
   uint8_t *gs = GAMESTATE_START(this->data_);
-  uint32_t dest_length = header_->getDataSize();
+  uint32_t dest_length = header_.getDataSize();
 
   if(dest_length==0)
     return NULL;
@@ -594,10 +613,10 @@
   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
   uint8_t *dest = GAMESTATE_START(ndata);
 
-  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
+  rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );
 #ifndef NDEBUG
   uint8_t *dest2 = new uint8_t[dest_length];
-  rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() );
+  rawDiff( dest2, dest, basep, header_.getDataSize(), base->header_.getDataSize() );
   assert( memcmp( dest2, gs, dest_length) == 0 );
   delete dest2;
 #endif
@@ -605,8 +624,8 @@
   Gamestate *g = new Gamestate(ndata, getClientID());
   assert(g->header_);
   *(g->header_) = *header_;
-  g->header_->setDiffed( true );
-  g->header_->setBaseID( base->getID() );
+  g->header_.setDiffed( true );
+  g->header_.setBaseID( base->getID() );
   g->flags_=flags_;
   g->packetDirection_ = packetDirection_;
   assert(g->isDiffed());
@@ -618,12 +637,12 @@
 Gamestate* Gamestate::undiff(Gamestate *base)
 {
   assert(this && base); assert(data_ && base->data_);
-  assert(!header_->isCompressed() && !base->header_->isCompressed());
-  assert(header_->isDiffed());
+  assert(!header_.isCompressed() && !base->header_.isCompressed());
+  assert(header_.isDiffed());
 
   uint8_t *basep = GAMESTATE_START(base->data_);
   uint8_t *gs = GAMESTATE_START(this->data_);
-  uint32_t dest_length = header_->getDataSize();
+  uint32_t dest_length = header_.getDataSize();
 
   if(dest_length==0)
     return NULL;
@@ -631,12 +650,12 @@
   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
   uint8_t *dest = ndata + GamestateHeader::getSize();
 
-  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
+  rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );
 
   Gamestate *g = new Gamestate(ndata, getClientID());
   assert(g->header_);
   *(g->header_) = *header_;
-  g->header_->setDiffed( false );
+  g->header_.setDiffed( false );
   g->flags_=flags_;
   g->packetDirection_ = packetDirection_;
   assert(!g->isDiffed());
@@ -669,15 +688,15 @@
       *(newdata+j) = *(data+j); // just copy
   }
   assert(j==datalength);
-}
+}*/
 
 
-Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
+/*Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
   assert(data_);
   std::list<obj>::iterator it;
 
   // allocate memory for new data
-  uint8_t *gdata = new uint8_t[header_->getDataSize()+GamestateHeader::getSize()];
+  uint8_t *gdata = new uint8_t[header_.getDataSize()+GamestateHeader::getSize()];
   // create a gamestate out of it
   Gamestate *gs = new Gamestate(gdata);
   uint8_t *newdata = gdata + GamestateHeader::getSize();
@@ -693,7 +712,7 @@
   //Synchronisable *object;
 
   //call TrafficControl
-  TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), dataVector_ );
+  TrafficControl::getInstance()->processObjectList( clientID, header_.getID(), dataVector_ );
 
   //copy in the zeros
 //   std::list<obj>::iterator itt;
@@ -724,22 +743,22 @@
   }
 #ifndef NDEBUG
   uint32_t origsize = destsize;
-  while ( origsize < header_->getDataSize() )
+  while ( origsize < header_.getDataSize() )
   {
     SynchronisableHeader oldobjectheader(origdata);
     objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();
     origdata += objectsize;
     origsize += objectsize;
   }
-  assert(origsize==header_->getDataSize());
+  assert(origsize==header_.getDataSize());
   assert(destsize!=0);
 #endif
-  gs->header_->setDataSize( destsize );
+  gs->header_.setDataSize( destsize );
   return gs;
-}
+}*/
 
 
-uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
+uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode)
 {
   uint32_t size = 0;
   uint32_t nrOfVariables = 0;

Modified: code/branches/presentation2/src/libraries/network/packet/Gamestate.h
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/Gamestate.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/Gamestate.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -41,32 +41,42 @@
 #include "network/TrafficControl.h"
 #include "Packet.h"
 
-namespace orxonox {
+namespace orxonox
+{
 
-namespace packet {
+namespace packet
+{
+    
+static const uint8_t GAMESTATE_MODE_SERVER = 0x1;
+static const uint8_t GAMESTATE_MODE_CLIENT = 0x2;
 
-class _NetworkExport GamestateHeader{
+class _NetworkExport GamestateHeader
+{
   public:
-    GamestateHeader(uint8_t *data){ assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
-    GamestateHeader(uint8_t *data, GamestateHeader* h)
-    { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }
+    GamestateHeader(){ data_=0; }
+    GamestateHeader(uint8_t* data)
+      { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
+    /*GamestateHeader(uint8_t* data, GamestateHeader* h)
+      { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/
+    void setData(uint8_t* data)
+      { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
     static inline uint32_t getSize()
-    { return 21; }
+      { return 21; }
 
-    inline int32_t getID() const
-    { assert(data_); return *(int32_t*)(data_+4); }
-    inline void setID(int32_t id)
-    { assert(data_); *(int32_t*)(data_+4) = id; }
+    inline uint32_t getID() const
+      { assert(data_); return *(uint32_t*)(data_+4); }
+    inline void setID(uint32_t id)
+      { assert(data_); *(uint32_t*)(data_+4) = id; }
 
-    inline int32_t getBaseID() const
-    { assert(data_); return *(int32_t*)(data_+8); }
-    inline void setBaseID(int32_t id)
-    { assert(data_); *(int32_t*)(data_+8) = id; }
+    inline uint32_t getBaseID() const
+      { assert(data_); return *(uint32_t*)(data_+8); }
+    inline void setBaseID(uint32_t id)
+      { assert(data_); *(uint32_t*)(data_+8) = id; }
 
     inline uint32_t getDataSize() const
-    { assert(data_); return *(uint32_t*)(data_+12); }
+      { assert(data_); return *(uint32_t*)(data_+12); }
     inline void setDataSize(uint32_t size)
-    { assert(data_); *(uint32_t*)(data_+12) = size; }
+      { assert(data_); *(uint32_t*)(data_+12) = size; }
 
     inline uint32_t getCompSize() const
     { assert(data_); return *(uint32_t*)(data_+16); }
@@ -74,31 +84,32 @@
     { assert(data_); *(uint32_t*)(data_+16) = size; }
 
     inline bool isDiffed() const
-    { assert(data_); return *(int8_t*)(data_+20) & 0x1; }
+      { assert(data_); return *(int8_t*)(data_+20) & 0x1; }
     inline void setDiffed(bool b)
-    { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
+      { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
 
     inline bool isComplete() const
-    { assert(data_); return *(int8_t*)(data_+20) & 0x2; }
+      { assert(data_); return *(int8_t*)(data_+20) & 0x2; }
     inline void setComplete(bool b)
-    { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
+      { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
 
     inline bool isCompressed() const
-    { assert(data_); return *(int8_t*)(data_+20) & 0x4; }
+      { assert(data_); return *(int8_t*)(data_+20) & 0x4; }
     inline void setCompressed(bool b)
-    { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
+      { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
 
     inline void operator=(GamestateHeader& h)
-    { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }
+      { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }
   private:
-    uint8_t *data_;
+    uint8_t* data_;
 
 };
 
 /**
     @author Oliver Scheuss
 */
-class _NetworkExport Gamestate: public Packet{
+class _NetworkExport Gamestate: public Packet
+{
   public:
     Gamestate();
     Gamestate(uint8_t *data, unsigned int clientID);
@@ -109,29 +120,31 @@
 
     bool collectData(int id, uint8_t mode=0x0);
     bool spreadData( uint8_t mode=0x0);
-    inline int32_t getID() const { return header_->getID(); }
-    inline bool isDiffed() const { return header_->isDiffed(); }
-    inline bool isCompressed() const { return header_->isCompressed(); }
-    inline int32_t getBaseID() const { return header_->getBaseID(); }
-    inline uint32_t getDataSize() const { return header_->getDataSize(); }
+    inline uint32_t getID() const { return header_.getID(); }
+    inline bool isDiffed() const { return header_.isDiffed(); }
+    inline bool isCompressed() const { return header_.isCompressed(); }
+    inline int32_t getBaseID() const { return header_.getBaseID(); }
+    inline uint32_t getDataSize() const { return header_.getDataSize(); }
     Gamestate* diffVariables(Gamestate *base);
-    Gamestate* diffData(Gamestate *base);
-    Gamestate *undiff(Gamestate *base);
-    Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
+//     Gamestate* diffData(Gamestate *base);
+//     Gamestate *undiff(Gamestate *base);
+//     Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
     bool compressData();
     bool decompressData();
     bool operator ==(packet::Gamestate gs);
 
     // Packet functions
   private:
-    void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
-    inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );
+//     void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
+//     inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );
     virtual uint32_t getSize() const;
-    virtual inline bool process();
-    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
+    virtual bool process(orxonox::Host* host);
+    uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0);
+//     inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
+//     inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
     
     std::list<obj>          dataVector_;
-    GamestateHeader*        header_;
+    GamestateHeader         header_;
     std::vector<uint32_t>   sizes_;
     uint32_t                nrOfVariables_;
 };

Modified: code/branches/presentation2/src/libraries/network/packet/Packet.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/Packet.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/Packet.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -34,6 +34,7 @@
 #define WIN32_LEAN_AND_MEAN
 #include <enet/enet.h>
 #include <boost/static_assert.hpp>
+#include <boost/thread/mutex.hpp>
 
 #include "util/Debug.h"
 #include "Acknowledgement.h"
@@ -52,30 +53,31 @@
 namespace packet{
 
 // Make sure we assume the right values
-BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable)   == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));
-BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequence) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));
-BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate) == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable)    == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequenced) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate)  == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));
 
 #define PACKET_FLAG_DEFAULT PacketFlag::NoAllocate
 #define _PACKETID           0
 
 std::map<size_t, Packet *> Packet::packetMap_;
+boost::mutex Packet::packetMapMutex_;
 
 Packet::Packet()
 {
   flags_ = PACKET_FLAG_DEFAULT;
   packetDirection_ = Direction::Outgoing;
-  clientID_=0;
+  peerID_=0;
   data_=0;
   enetPacket_=0;
   bDataENetAllocated_ = false;
 }
 
-Packet::Packet(uint8_t *data, unsigned int clientID)
+Packet::Packet(uint8_t *data, unsigned int peerID)
 {
   flags_ = PACKET_FLAG_DEFAULT;
   packetDirection_ = Direction::Incoming;
-  clientID_=clientID;
+  peerID_=peerID;
   data_=data;
   enetPacket_=0;
   bDataENetAllocated_ = false;
@@ -86,7 +88,7 @@
   enetPacket_=p.enetPacket_;
   flags_=p.flags_;
   packetDirection_ = p.packetDirection_;
-  clientID_ = p.clientID_;
+  peerID_ = p.peerID_;
   if(p.data_){
     data_ = new uint8_t[p.getSize()];
     memcpy(data_, p.data_, p.getSize());
@@ -122,7 +124,7 @@
   }
 }
 
-bool Packet::send(){
+bool Packet::send(orxonox::Host* host){
   if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){
     assert(0);
     return false;
@@ -141,7 +143,9 @@
     {
       // Assures we don't create a packet and destroy it right after in another thread
       // without having a reference in the packetMap_
+      Packet::packetMapMutex_.lock();
       packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;
+      Packet::packetMapMutex_.unlock();
     }
   }
 #ifndef NDEBUG
@@ -163,54 +167,58 @@
 #endif
 //  ENetPacket *temp = enetPacket_;
 //  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
-  if(!Host::addPacket( enetPacket_, clientID_))
-    enet_packet_destroy(this->enetPacket_); // if we could not add the packet to the enet queue delete it manually
+  if( this->flags_ & PacketFlag::Reliable )
+    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT);
+  else
+    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE);
   return true;
 }
 
 Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){
   uint8_t *data = packet->data;
   assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
-  unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
+  unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
+  // HACK
+  if( peerID==static_cast<unsigned int>(-2))
+    peerID = NETWORK_PEER_ID_SERVER;
   Packet *p = 0;
-  COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
+//   COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
   switch( *(Type::Value *)(data + _PACKETID) )
   {
     case Type::Acknowledgement:
-      COUT(5) << "ack" << std::endl;
-      p = new Acknowledgement( data, clientID );
+//       COUT(5) << "ack" << std::endl;
+    p = new Acknowledgement( data, peerID );
       break;
     case Type::Chat:
-      COUT(5) << "chat" << std::endl;
-      p = new Chat( data, clientID );
+//       COUT(5) << "chat" << std::endl;
+      p = new Chat( data, peerID );
       break;
     case Type::ClassID:
-      COUT(5) << "classid" << std::endl;
-      p = new ClassID( data, clientID );
+//       COUT(5) << "classid" << std::endl;
+      p = new ClassID( data, peerID );
       break;
     case Type::Gamestate:
-      COUT(5) << "gamestate" << std::endl;
-      // TODO: remove brackets
-      p = new Gamestate( data, clientID );
+//       COUT(5) << "gamestate" << std::endl;
+      p = new Gamestate( data, peerID );
       break;
     case Type::Welcome:
-      COUT(5) << "welcome" << std::endl;
-      p = new Welcome( data, clientID );
+//       COUT(5) << "welcome" << std::endl;
+      p = new Welcome( data, peerID );
       break;
     case Type::DeleteObjects:
-      COUT(5) << "deleteobjects" << std::endl;
-      p = new DeleteObjects( data, clientID );
+//       COUT(5) << "deleteobjects" << std::endl;
+      p = new DeleteObjects( data, peerID );
       break;
     case Type::FunctionCalls:
-      COUT(5) << "functionCalls" << std::endl;
-      p = new FunctionCalls( data, clientID );
+//       COUT(5) << "functionCalls" << std::endl;
+      p = new FunctionCalls( data, peerID );
       break;
     case Type::FunctionIDs:
-      COUT(5) << "functionIDs" << std::endl;
-      p = new FunctionIDs( data, clientID );
+//       COUT(5) << "functionIDs" << std::endl;
+      p = new FunctionIDs( data, peerID );
       break;
     default:
-      assert(0); //TODO: repair this
+      assert(0);
       break;
   }
 
@@ -228,13 +236,15 @@
 */
 void Packet::deletePacket(ENetPacket *enetPacket){
   // Get our Packet from a global map with all Packets created in the send() method of Packet.
+  Packet::packetMapMutex_.lock();
   std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket));
   assert(it != packetMap_.end());
   // Make sure we don't delete it again in the destructor
   it->second->enetPacket_ = 0;
   delete it->second;
   packetMap_.erase(it);
-  COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
+  Packet::packetMapMutex_.unlock();
+//   COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
 }
 
 } // namespace packet

Modified: code/branches/presentation2/src/libraries/network/packet/Packet.h
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/Packet.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/Packet.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -67,24 +67,29 @@
 
     virtual unsigned char *getData(){ return data_; };
     virtual unsigned int getSize() const =0;
-    virtual bool process()=0;
+    virtual bool process(orxonox::Host* host)=0;
     inline uint32_t getFlags()
       { return flags_; }
-    inline int getClientID()
-      { return clientID_; }
-    inline void setClientID( int id )
-      { clientID_ = id; }
+    inline int getPeerID()
+      { return peerID_; }
+    inline void setPeerID( int id )
+      { peerID_ = id; }
+    inline bool isReliable()
+      { return this->flags_ & PacketFlag::Reliable; }
+    inline uint32_t getRequiredGamestateID()
+      { return this->requiredGamestateID_; }
 
-    virtual bool send();
+    virtual bool send(orxonox::Host* host);
   protected:
     Packet();
-    Packet(uint8_t *data, unsigned int clientID);
+    Packet(uint8_t *data, unsigned int peerID);
 //    Packet(ENetPacket *packet, ENetPeer *peer);
     inline bool isDataENetAllocated() const
       { return bDataENetAllocated_; }
 
     uint32_t flags_;
-    unsigned int clientID_;
+    unsigned int peerID_;
+    uint32_t requiredGamestateID_;
     Direction::Value packetDirection_;
     /** Pointer to the data. Be careful when deleting it because it might
         point to a location that was allocated by ENet.
@@ -95,6 +100,7 @@
     bool bDataENetAllocated_;
   private:
     static std::map<size_t, Packet *> packetMap_;
+    static boost::mutex               packetMapMutex_;
     ENetPacket *enetPacket_;
 };
 

Modified: code/branches/presentation2/src/libraries/network/packet/Welcome.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/Welcome.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/Welcome.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -72,11 +72,11 @@
   return sizeof(packet::Type::Value) + 2*sizeof(uint32_t);
 }
 
-bool Welcome::process(){
+bool Welcome::process(orxonox::Host* host){
   uint32_t clientID;
   clientID = *(uint32_t *)(data_ + _CLIENTID );
   assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321);
-  Host::setClientID(clientID);
+  host->setClientID(clientID);
   COUT(3) << "Welcome set clientId: " << clientID << endl;
   Synchronisable::setClient(true);
   delete this;

Modified: code/branches/presentation2/src/libraries/network/packet/Welcome.h
===================================================================
--- code/branches/presentation2/src/libraries/network/packet/Welcome.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/packet/Welcome.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -46,7 +46,7 @@
 
   uint8_t *getData();
   inline unsigned int getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
 };

Modified: code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.cc
===================================================================
--- code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -122,7 +122,12 @@
   Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode)
   {
     SynchronisableHeader header(mem);
-    assert( !header.isDiffed() );
+    if( header.isDiffed() )
+    {
+      mem += header.getDataSize() + header.getSize();
+      return 0;
+    }
+//     assert( !header.isDiffed() );
 
     COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl;
 
@@ -216,11 +221,11 @@
    * |totalsize,objectID_,classID_,var1,var2,string1_length,string1,var3,...|
    * length of varx: size saved int syncvarlist
    * @param mem pointer to allocated memory with enough size
-   * @param sizes FIXME - add doc!
+   * @param sizes vector containing sizes of all objects in gamestate (to be appended)
    * @param id gamestateid of the gamestate to be saved (important for priorities)
    * @param mode defines the direction in which the data will be send/received
    *             0x1: server->client
-   *             0x2: client->server (not recommended)
+   *             0x2: client->server
    *             0x3: bidirectional
    * @return true: if !doSync or if everything was successfully saved
    */
@@ -264,6 +269,7 @@
       ++test;
       //tempsize += (*i)->getSize( mode );
     }
+    assert(tempsize!=0);  // if this happens an empty object (with no variables) would be transmitted
 //     COUT(4) << endl;
 
     header.setObjectID( this->objectID_ );
@@ -315,7 +321,7 @@
       assert( this->getCreatorID() == syncHeader2.getCreatorID() );
       mem += SynchronisableHeader::getSize();
       std::vector<SynchronisableVariableBase *>::iterator i;
-      for(i=syncList_.begin(); i!=syncList_.end(); i++)
+      for(i=syncList_.begin(); i!=syncList_.end(); ++i)
       {
         assert( mem <= data+syncHeader2.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream
         (*i)->putData( mem, mode, forceCallback );

Modified: code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h
===================================================================
--- code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -64,33 +64,29 @@
       VeryLow     = 100
     };
   }
-  
-  typedef uint8_t VariableID;
 
-  /**
-   * @brief: stores information about a Synchronisable
+    /**
+   * @brief: stores information about a Synchronisable (light version)
    *
-   * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)
+   * This class stores the information about a Synchronisable (objectID_, dataSize)
    * in an emulated bitset.
    * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
    * Bit 32 is a bool and defines whether the variables are stored in diff mode
    * Byte 5 to 8: objectID_
-   * Byte 9 to 12: classID_
-   * Byte 13 to 16: creatorID_
    */
-  class _NetworkExport SynchronisableHeader{
-    friend class SynchronisableHeaderLight;
-    private:
+  class _NetworkExport SynchronisableHeaderLight
+  {
+    protected:
       uint8_t* data_;
     public:
-      SynchronisableHeader(uint8_t* data)
+      SynchronisableHeaderLight(uint8_t* data)
         { data_ = data; }
       inline static uint32_t getSize()
-        { return 14; }
+        { return 6; }
       inline uint16_t getDataSize() const
-        { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 15 bits
+        { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 31 bits
       inline void setDataSize(uint16_t size)
-        { *(uint16_t*)(data_) = (size & 0x7FFF) | (*(uint16_t*)(data_) & 0x8000 ); }
+        { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); }
       inline bool isDiffed() const
         { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }
       inline void setDiffed( bool b)
@@ -99,50 +95,46 @@
         { return *(uint32_t*)(data_+2); }
       inline void setObjectID(uint32_t objectID_)
         { *(uint32_t*)(data_+2) = objectID_; }
-      inline uint32_t getClassID() const
-        { return *(uint32_t*)(data_+6); }
-      inline void setClassID(uint32_t classID_)
-        { *(uint32_t*)(data_+6) = classID_; }
-      inline uint32_t getCreatorID() const
-        { return *(uint32_t*)(data_+10); }
-      inline void setCreatorID(uint32_t creatorID_)
-        { *(uint32_t*)(data_+10) = creatorID_; }
-      inline void operator=(SynchronisableHeader& h)
-        { memcpy(data_, h.data_, getSize()); }
+      inline void operator=(SynchronisableHeaderLight& h)
+        { memcpy(data_, h.data_, SynchronisableHeaderLight::getSize()); }
   };
-
-    /**
-   * @brief: stores information about a Synchronisable (light version)
+  
+  typedef uint8_t VariableID;
+  
+  /**
+   * @brief: stores information about a Synchronisable
    *
-   * This class stores the information about a Synchronisable (objectID_, dataSize)
+   * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)
    * in an emulated bitset.
    * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
    * Bit 32 is a bool and defines whether the variables are stored in diff mode
    * Byte 5 to 8: objectID_
+   * Byte 9 to 12: classID_
+   * Byte 13 to 16: creatorID_
    */
-  class _NetworkExport SynchronisableHeaderLight{
-    private:
-      uint8_t* data_;
+  class _NetworkExport SynchronisableHeader: public SynchronisableHeaderLight
+  {
     public:
-      SynchronisableHeaderLight(uint8_t* data)
-        { data_ = data; }
+      SynchronisableHeader(uint8_t* data): SynchronisableHeaderLight(data)
+        {}
       inline static uint32_t getSize()
-        { return 6; }
-      inline uint16_t getDataSize() const
-        { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 31 bits
-      inline void setDataSize(uint16_t size)
-        { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); }
-      inline bool isDiffed() const
-        { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }
-      inline void setDiffed( bool b)
-        { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); }
-      inline uint32_t getObjectID() const
-        { return *(uint32_t*)(data_+2); }
-      inline void setObjectID(uint32_t objectID_)
-        { *(uint32_t*)(data_+2) = objectID_; }
+        { return SynchronisableHeaderLight::getSize()+8; }
+      inline uint32_t getClassID() const
+        { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()); }
+      inline void setClassID(uint32_t classID_)
+        { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()) = classID_; }
+      inline uint32_t getCreatorID() const
+        { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4); }
+      inline void setCreatorID(uint32_t creatorID_)
+        { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4) = creatorID_; }
       inline void operator=(SynchronisableHeader& h)
         { memcpy(data_, h.data_, getSize()); }
   };
+  
+//   inline void operator=(SynchronisableHeaderLight& h1, SynchronisableHeader& h2)
+//   {
+//     memcpy(h1.data_, h2.data_, h1.getSize());
+//   }
 
   /**
   * This class is the base class of all the Objects in the universe that need to be synchronised over the network

Modified: code/branches/presentation2/src/libraries/util/SignalHandler.cc
===================================================================
--- code/branches/presentation2/src/libraries/util/SignalHandler.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/libraries/util/SignalHandler.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -50,6 +50,7 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/keysym.h>
+#include <sys/prctl.h>
 
 namespace orxonox
 {
@@ -136,10 +137,52 @@
 
       COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Try to write backtrace to file orxonox_crash.log" << std::endl;
 
+      
+      // First start GDB which will be attached to this process later on
+      
+      int gdbIn[2];
+      int gdbOut[2];
+      int gdbErr[2];
+      
+      if ( pipe(gdbIn) == -1 || pipe(gdbOut) == -1 || pipe(gdbErr) == -1 )
+      {
+        perror("pipe failed!\n");
+        exit(EXIT_FAILURE);
+      }
+      
+      int gdbPid = fork();
+      // this process will run gdb
+      
+      if ( gdbPid == -1 )
+      {
+        perror("fork failed\n");
+        exit(EXIT_FAILURE);
+      }
+      
+      if ( gdbPid == 0 )
+      {
+        // start gdb
+        
+        close(gdbIn[1]);
+        close(gdbOut[0]);
+        close(gdbErr[0]);
+        
+        dup2( gdbIn[0], STDIN_FILENO );
+        dup2( gdbOut[1], STDOUT_FILENO );
+        dup2( gdbErr[1], STDERR_FILENO );
+        
+        execlp( "sh", "sh", "-c", "gdb", static_cast<void*>(NULL));
+      }
+      
+      
+      // Now start a fork of this process on which GDB will be attached on
+      
       int sigPipe[2];
       if ( pipe(sigPipe) == -1 )
       {
         perror("pipe failed!\n");
+        kill( gdbPid, SIGTERM );
+        waitpid( gdbPid, NULL, 0 );
         exit(EXIT_FAILURE);
       }
 
@@ -148,6 +191,8 @@
       if ( sigPid == -1 )
       {
         perror("fork failed!\n");
+        kill( gdbPid, SIGTERM );
+        waitpid( gdbPid, NULL, 0 );
         exit(EXIT_FAILURE);
       }
 
@@ -155,10 +200,18 @@
       if ( sigPid == 0 )
       {
         getInstance().dontCatch();
+        
+        // make sure gdb is allowed to attach to our PID even if there are some system restrictions
+#ifdef PR_SET_PTRACER
+        if( prctl(PR_SET_PTRACER, gdbPid, 0, 0, 0) == -1 )
+          COUT(0) << "could not set proper permissions for GDB to attach to process..." << endl;
+#endif
+        
         // wait for message from parent when it has attached gdb
         int someData;
 
-        read( sigPipe[0], &someData, sizeof(someData) );
+        if( read( sigPipe[0], &someData, sizeof(someData) ) != sizeof(someData) )
+          COUT(0) << "something went wrong :(" << std::endl;
 
         if ( someData != 0x12345678 )
         {
@@ -168,44 +221,6 @@
         return;
       }
 
-      int gdbIn[2];
-      int gdbOut[2];
-      int gdbErr[2];
-
-      if ( pipe(gdbIn) == -1 || pipe(gdbOut) == -1 || pipe(gdbErr) == -1 )
-      {
-        perror("pipe failed!\n");
-        kill( sigPid, SIGTERM );
-        waitpid( sigPid, NULL, 0 );
-        exit(EXIT_FAILURE);
-      }
-
-      int gdbPid = fork();
-      // this process will run gdb
-
-      if ( gdbPid == -1 )
-      {
-        perror("fork failed\n");
-        kill( sigPid, SIGTERM );
-        waitpid( sigPid, NULL, 0 );
-        exit(EXIT_FAILURE);
-      }
-
-      if ( gdbPid == 0 )
-      {
-        // start gdb
-
-        close(gdbIn[1]);
-        close(gdbOut[0]);
-        close(gdbErr[0]);
-
-        dup2( gdbIn[0], STDIN_FILENO );
-        dup2( gdbOut[1], STDOUT_FILENO );
-        dup2( gdbErr[1], STDERR_FILENO );
-
-        execlp( "sh", "sh", "-c", "gdb", static_cast<void*>(NULL));
-      }
-
       char cmd[256];
       snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance().appName.c_str(), sigPid );
       write( gdbIn[1], cmd, strlen(cmd) );

Modified: code/branches/presentation2/src/modules/weapons/MuzzleFlash.cc
===================================================================
--- code/branches/presentation2/src/modules/weapons/MuzzleFlash.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/modules/weapons/MuzzleFlash.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -41,6 +41,7 @@
         RegisterObject(MuzzleFlash);
         this->setScale(0.1f);
 
-        this->delayTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&MuzzleFlash::destroy, this)));
+        if( GameMode::isMaster() )
+          this->delayTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&MuzzleFlash::destroy, this)));
     }
 }

Modified: code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -374,7 +374,7 @@
         for (itr = result.begin(); itr != result.end(); ++itr)
         {
 //             CCOUT(0) << "testing object as target" << endl;
-            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" /*&& itr->distance > 500*/)
+            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 200)
             {
                 // Try to cast the user pointer
                 WorldEntity* wePtr;

Modified: code/branches/presentation2/src/orxonox/gametypes/Gametype.cc
===================================================================
--- code/branches/presentation2/src/orxonox/gametypes/Gametype.cc	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/orxonox/gametypes/Gametype.cc	2010-12-21 17:09:09 UTC (rev 7788)
@@ -78,6 +78,11 @@
         }
         else
             this->scoreboard_ = 0;
+
+        /* HACK HACK HACK */
+        this->dedicatedAddBots_ = createConsoleCommand( "dedicatedAddBots", createExecutor( createFunctor(&Gametype::addBots, this) ) );
+        this->dedicatedKillBots_ = createConsoleCommand( "dedicatedKillBots", createExecutor( createFunctor(&Gametype::killBots, this) ) );
+        /* HACK HACK HACK */
     }
 
     Gametype::~Gametype()
@@ -85,6 +90,10 @@
         if (this->isInitialized())
         {
             this->gtinfo_->destroy();
+            if( this->dedicatedAddBots_ )
+                delete this->dedicatedAddBots_;
+            if( this->dedicatedKillBots_ )
+                delete this->dedicatedKillBots_;
         }
     }
 

Modified: code/branches/presentation2/src/orxonox/gametypes/Gametype.h
===================================================================
--- code/branches/presentation2/src/orxonox/gametypes/Gametype.h	2010-12-21 17:04:36 UTC (rev 7787)
+++ code/branches/presentation2/src/orxonox/gametypes/Gametype.h	2010-12-21 17:09:09 UTC (rev 7788)
@@ -183,6 +183,11 @@
 
             // Config Values
             std::string scoreboardTemplate_;
+
+            /* HACK HACK HACK */
+            ConsoleCommand* dedicatedAddBots_;
+            ConsoleCommand* dedicatedKillBots_;
+            /* HACK HACK HACK */
     };
 }
 




More information about the Orxonox-commit mailing list