Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7777


Ignore:
Timestamp:
Dec 19, 2010, 2:27:06 PM (13 years ago)
Author:
scheusso
Message:

some () structural changes
some functional changes (GamestateClient replaced through GamestateManager on client)
reliable packets get buffered until a recent gamestate arrived and got processed

Location:
code/branches/network5/src
Files:
42 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network5/src/libraries/network/CMakeLists.txt

    r7739 r7777  
    2828  FunctionCallManager.cc
    2929  GamestateManager.cc
    30   GamestateClient.cc
     30  #GamestateClient.cc
    3131  GamestateHandler.cc
    3232  LANDiscoverable.cc
     
    5353  FunctionCall.h
    5454  FunctionCallManager.h
    55   GamestateClient.h
     55  #GamestateClient.h
    5656  GamestateHandler.h
    5757  GamestateManager.h
  • code/branches/network5/src/libraries/network/Client.cc

    r7772 r7777  
    6464  */
    6565  Client::Client():
    66       gamestate(0),
    6766      isSynched_(false),
    6867      gameStateFailure_(false),
     
    8584  {
    8685    Synchronisable::setClient(true);
    87     this->gamestate = new GamestateClient();
    8886    if( ClientConnection::establishConnection() )
    8987    {
    9088      Host::setActive(true);
     89      GamestateManager::addPeer(NETWORK_PEER_ID_SERVER);
    9190      return true;
    9291    }
     
    101100  bool Client::closeConnection()
    102101  {
    103     assert(this->gamestate);
    104     delete this->gamestate;
    105     this->gamestate = 0;
    106102    Host::setActive(false);
     103    GamestateManager::removePeer(NETWORK_PEER_ID_SERVER);
    107104    return ClientConnection::closeConnection();
    108105  }
     
    138135  {
    139136    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
    140     return m->send();
     137    return m->send(static_cast<Host*>(this));
    141138  }
    142139
     
    157154      {
    158155        COUT(4) << "popping partial gamestate: " << std::endl;
    159         packet::Gamestate *gs = gamestate->getGamestate();
     156//         packet::Gamestate *gs = GamestateClient::getGamestate();
     157        GamestateManager::update();
     158        std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
     159        std::vector<packet::Gamestate*>::iterator it;
     160        for( it = gamestates.begin(); it != gamestates.end(); ++it )
     161        {
     162          (*it)->send( static_cast<Host*>(this) );
     163        }
    160164        //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
    161         if(gs){
    162           COUT(4) << "client tick: sending gs " << gs << std::endl;
    163           if( !gs->send() )
    164             COUT(2) << "Problem adding partial gamestate to queue" << std::endl;
    165         // gs gets automatically deleted by enet callback
    166         }
    167         FunctionCallManager::sendCalls();
     165//         if(gs){
     166//           COUT(4) << "client tick: sending gs " << gs << std::endl;
     167//           if( !gs->send() )
     168//             COUT(2) << "Problem adding partial gamestate to queue" << std::endl;
     169//         // gs gets automatically deleted by enet callback
     170//         }
     171        FunctionCallManager::sendCalls(static_cast<Host*>(this));
    168172      }
    169173    }
     
    171175
    172176    Connection::processQueue();
    173     if(gamestate->processGamestates())
     177    if(GamestateManager::processGamestates())
    174178    {
    175179      FunctionCallManager::processBufferedFunctionCalls();
     
    177181        isSynched_=true;
    178182    }
    179     gamestate->cleanup();
     183//     GamestateManager::cleanup();;
    180184//     Connection::sendPackets();
    181185
     
    198202    Game::getInstance().popState();
    199203  }
     204 
     205  void Client::processPacket(packet::Packet* packet)
     206  {
     207    if( packet->isReliable() )
     208    {
     209      if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
     210        packet->process(static_cast<Host*>(this));
     211      else
     212        this->packetQueue_.push_back(packet);
     213    }
     214    else
     215      packet->process(static_cast<Host*>(this));
     216  }
     217
    200218
    201219
  • code/branches/network5/src/libraries/network/Client.h

    r7772 r7777  
    4545
    4646#include <string>
     47#include <deque>
    4748
    4849#include "util/UtilPrereqs.h"
    4950#include "util/Singleton.h"
    5051#include "ClientConnection.h"
    51 #include "GamestateClient.h"
     52// #include "GamestateClient.h"
    5253#include "Host.h"
    5354#include "LANDiscovery.h"
     
    9091    Client(const Client& copy); // not used
    9192    virtual bool isServer_(){return false;}
     93    void processPacket(packet::Packet* packet);
    9294
    9395    static Client* singletonPtr_s;
    94     GamestateClient* gamestate;
    9596    bool isSynched_;
     97    std::deque<packet::Packet*> packetQueue_;
    9698
    9799    bool gameStateFailure_;
  • code/branches/network5/src/libraries/network/ClientConnection.h

    r7772 r7777  
    4444    void setPort( unsigned int port );
    4545
    46     ENetEvent *getEvent();
     46//     ENetEvent *getEvent();
    4747    // check wheter the packet queue is empty
    48     bool queueEmpty();
     48//     bool queueEmpty();
    4949    // create a new listener thread
    5050    virtual bool establishConnection();
  • code/branches/network5/src/libraries/network/ClientInformation.cc

    r7459 r7777  
    5656    preve=0;
    5757    nexte=0;
    58     partialGamestateID_=GAMESTATEID_INITIAL-1;
    5958    synched_=false;
    6059  }
     
    133132  }
    134133
    135   bool ClientInformation::setPartialGamestateID(int id){
    136     if(!this)
    137       return false;
    138     partialGamestateID_=id;
    139     return true;
    140   }
    141 
    142134  unsigned int ClientInformation::getID() {
    143135    if(!this)
     
    154146  }
    155147
    156   int ClientInformation::getFailures(){
    157     return failures_;
    158   }
    159   void ClientInformation::addFailure(){
    160     failures_++;
    161   }
    162   void ClientInformation::resetFailures(){
    163     failures_=0;
    164   }
    165 
    166148  uint32_t ClientInformation::getRTT(){
    167149    return this->peer_->roundTripTime;
     
    175157    if(this)
    176158      return gamestateID_;
    177     else
    178       return static_cast<unsigned int>(-1);
    179   }
    180 
    181   unsigned int ClientInformation::getPartialGamestateID() {
    182     if(this)
    183       return partialGamestateID_;
    184159    else
    185160      return static_cast<unsigned int>(-1);
  • code/branches/network5/src/libraries/network/ClientInformation.h

    r5781 r7777  
    6666    bool setPeer(ENetPeer *peer);
    6767    bool setGamestateID(int id);
    68     bool setPartialGamestateID(int id);
    6968    inline void setShipID(unsigned int id){ShipID_=id;}
    7069
     
    7372    unsigned int getID();
    7473    unsigned int getGamestateID();
    75     unsigned int getPartialGamestateID();
    7674    ENetPeer *getPeer();
    7775
    78     int getFailures();
    79     void addFailure();
    80     void resetFailures();
    8176    uint32_t getRTT();
    8277    double getPacketLoss();
     
    106101    unsigned int clientID_;
    107102    unsigned int gamestateID_;
    108     unsigned int partialGamestateID_;
    109103    unsigned int ShipID_;   // this is the unique objectID
    110104    bool synched_;
    111     unsigned short failures_;
    112105
    113106  };
  • code/branches/network5/src/libraries/network/Connection.cc

    r7774 r7777  
    177177    while( incomingEventsCount > 0 )
    178178    {
     179      packet::Packet* p;
    179180      this->incomingEventsMutex_->lock();
    180181      event = this->incomingEvents_.front();
     
    193194        case ENET_EVENT_TYPE_RECEIVE:
    194195//           COUT(0) << "ENET_EVENT_TYPE_RECEIVE" << endl;
    195           processPacket( &event );
     196          p = createPacket( &event );
     197          processPacket(p);
    196198          break;
    197199        case ENET_EVENT_TYPE_NONE:
     
    205207  }
    206208
    207   bool Connection::processPacket(ENetEvent* event)
     209  packet::Packet* Connection::createPacket(ENetEvent* event)
    208210  {
    209211    packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer);
    210     return p->process();
     212    return p;
     213//     return p->process();
    211214  }
    212215 
  • code/branches/network5/src/libraries/network/Connection.h

    r7774 r7777  
    8484    void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
    8585    void broadcastPacket(ENetPacket* packet, uint8_t channelID);
    86     ENetHost* getHost(){ return this->host_; }
     86//     ENetHost* getHost(){ return this->host_; }
    8787
    8888  protected:
     
    101101    virtual void addPeer(ENetEvent* event)=0;
    102102    virtual void removePeer(ENetEvent* event)=0;
    103     virtual bool processPacket(ENetEvent* event);
     103    virtual void processPacket( packet::Packet* packet)=0;
     104    virtual packet::Packet* createPacket(ENetEvent* event);
    104105
    105106    ENetHost*                   host_;
    106     boost::mutex*               incomingEventsMutex_;
    107     boost::mutex*               outgoingEventsMutex_;
    108107  private:
    109108    boost::thread*              communicationThread_;
     
    112111    std::deque<ENetEvent>       incomingEvents_;
    113112    std::deque<outgoingEvent>   outgoingEvents_;
     113    boost::mutex*               incomingEventsMutex_;
     114    boost::mutex*               outgoingEventsMutex_;
    114115
    115116//     static Connection *instance_;
  • code/branches/network5/src/libraries/network/FunctionCallManager.cc

    r7759 r7777  
    3434namespace orxonox {
    3535
    36 std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sClientMap_;
     36std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sPeerMap_;
    3737std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > > FunctionCallManager::sIncomingFunctionCallBuffer_;
    3838
    3939// Static calls
    4040
    41 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID)
     41void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID)
    4242{
    43   if(sClientMap_.find(clientID)==sClientMap_.end())
     43  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    4444  {
    45     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    46     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     45    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     46    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    4747  }
    48   FunctionCallManager::sClientMap_[clientID]->addCallStatic(functionID);
     48  FunctionCallManager::sPeerMap_[peerID]->addCallStatic(functionID);
    4949}
    50 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1)
     50void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1)
    5151{
    52   if(sClientMap_.find(clientID)==sClientMap_.end())
     52  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    5353  {
    54     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    55     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     54    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     55    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    5656  }
    57   FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1);
     57  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1);
    5858}
    59 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
     59void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
    6060{
    61   if(sClientMap_.find(clientID)==sClientMap_.end())
     61  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    6262  {
    63     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    64     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     63    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     64    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    6565  }
    66   FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2);
     66  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2);
    6767}
    68 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
     68void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
    6969{
    70   if(sClientMap_.find(clientID)==sClientMap_.end())
     70  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    7171  {
    72     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    73     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     72    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     73    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    7474  }
    75   FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
     75  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
    7676}
    77 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
     77void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
    7878{
    79   if(sClientMap_.find(clientID)==sClientMap_.end())
     79  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    8080  {
    81     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    82     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     81    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     82    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    8383  }
    84   FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
     84  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
    8585}
    86 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
     86void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
    8787{
    88   if(sClientMap_.find(clientID)==sClientMap_.end())
     88  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    8989  {
    90     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    91     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     90    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     91    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    9292  }
    93   FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
     93  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
    9494}
    9595
     
    9797// MemberCalls
    9898
    99 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID)
     99void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID)
    100100{
    101   if(sClientMap_.find(clientID)==sClientMap_.end())
     101  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    102102  {
    103     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    104     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     103    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     104    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    105105  }
    106   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID);
     106  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID);
    107107}
    108 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1)
     108void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1)
    109109{
    110   if(sClientMap_.find(clientID)==sClientMap_.end())
     110  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    111111  {
    112     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    113     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     112    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     113    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    114114  }
    115   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1);
     115  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1);
    116116}
    117 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
     117void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
    118118{
    119   if(sClientMap_.find(clientID)==sClientMap_.end())
     119  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    120120  {
    121     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    122     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     121    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     122    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    123123  }
    124   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2);
     124  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2);
    125125}
    126 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
     126void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
    127127{
    128   if(sClientMap_.find(clientID)==sClientMap_.end())
     128  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    129129  {
    130     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    131     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     130    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     131    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    132132  }
    133   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
     133  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
    134134}
    135 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
     135void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
    136136{
    137   if(sClientMap_.find(clientID)==sClientMap_.end())
     137  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    138138  {
    139     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    140     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     139    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     140    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    141141  }
    142   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
     142  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
    143143}
    144 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)
     144void 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)
    145145{
    146   if(sClientMap_.find(clientID)==sClientMap_.end())
     146  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    147147  {
    148     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    149     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     148    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     149    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    150150  }
    151   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
     151  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
    152152}
    153153
    154154// Send calls
    155155
    156 void FunctionCallManager::sendCalls()
     156void FunctionCallManager::sendCalls(orxonox::Host* host)
    157157{
    158158  std::map<uint32_t, packet::FunctionCalls*>::iterator it;
    159   for (it = FunctionCallManager::sClientMap_.begin(); it != FunctionCallManager::sClientMap_.end(); ++it )
     159  for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it )
    160160  {
    161     assert(!FunctionCallManager::sClientMap_.empty());
    162     it->second->send();
     161    assert(!FunctionCallManager::sPeerMap_.empty());
     162    it->second->send(host);
    163163  }
    164   FunctionCallManager::sClientMap_.clear();
     164  FunctionCallManager::sPeerMap_.clear();
    165165}
    166166
    167 void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t clientID)
     167void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID)
    168168{
    169   FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, clientID)));
     169  FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, peerID)));
    170170}
    171171
     
    175175  while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() )
    176176  {
    177     uint32_t minGamestateID = it->second.first;
    178     uint32_t clientID       = it->second.second;
    179     if( minGamestateID <= GamestateHandler::getInstance()->getLastProcessedGamestateID(clientID) && it->first.execute() )
     177    if( it->first.execute() )
    180178      FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it);
    181179    else
  • code/branches/network5/src/libraries/network/FunctionCallManager.h

    r7759 r7777  
    4646{
    4747public:
    48   static void addCallStatic(uint32_t functionID, uint32_t clientID);
    49   static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1);
    50   static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);
    51   static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
    52   static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
    53   static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
     48  static void addCallStatic(uint32_t functionID, uint32_t peerID);
     49  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1);
     50  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2);
     51  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
     52  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
     53  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
    5454
    55   static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID);
    56   static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1);
    57   static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);
    58   static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
    59   static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
    60   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);
     55  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID);
     56  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1);
     57  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2);
     58  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
     59  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
     60  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);
    6161
    62   static void sendCalls();
     62  static void sendCalls(orxonox::Host* host);
    6363 
    64   static void bufferIncomingFunctionCall( const FunctionCall& fctCall, uint32_t minGamestateID, uint32_t clientID );
     64  static void bufferIncomingFunctionCall( const FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID );
    6565  static void processBufferedFunctionCalls();
    6666
    67   static std::map<uint32_t, packet::FunctionCalls*>                           sClientMap_;
     67  static std::map<uint32_t, packet::FunctionCalls*>                           sPeerMap_;
    6868  static std::vector<std::pair<FunctionCall,std::pair<uint32_t, uint32_t> > > sIncomingFunctionCallBuffer_;
    6969protected:
  • code/branches/network5/src/libraries/network/GamestateClient.cc

    r7759 r7777  
    6262  }
    6363
    64   bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID)
     64  bool GamestateClient::ackGamestate(unsigned int gamestateID, unsigned int clientID)
    6565  {
    6666    return true;
    6767  }
    6868
    69   bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID)
     69  bool GamestateClient::addGamestate(packet::Gamestate *gs, unsigned int clientID)
    7070  {
    7171    if(tempGamestate_!=NULL)
  • code/branches/network5/src/libraries/network/GamestateClient.h

    r7759 r7777  
    5757    ~GamestateClient();
    5858
    59     virtual bool      add(packet::Gamestate *gs, unsigned int clientID);
    60     virtual bool      ack(unsigned int gamestateID, unsigned int clientID);
    61     virtual uint32_t  getLastProcessedGamestateID(unsigned int clientID) { return this->lastProcessedGamestateID_; }
     59    virtual bool      addGamestate(packet::Gamestate *gs, unsigned int clientID);
     60    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int clientID);
     61    virtual uint32_t  getLastProcessedGamestateID(unsigned int clientID=0) { return this->lastProcessedGamestateID_; }
    6262    virtual uint32_t  getCurrentGamestateID(){ return this->lastProcessedGamestateID_; }
    6363
  • code/branches/network5/src/libraries/network/GamestateHandler.cc

    r6417 r7777  
    3232namespace orxonox {
    3333
    34 GamestateHandler *GamestateHandler::instance_=0;
     34// GamestateHandler *GamestateHandler::instance_=0;
    3535
    3636GamestateHandler::GamestateHandler()
    3737{
    38   assert(instance_==0);
    39   instance_=this;
    4038}
    4139
     
    4341GamestateHandler::~GamestateHandler()
    4442{
    45   instance_=0;
    4643}
    4744
  • code/branches/network5/src/libraries/network/GamestateHandler.h

    r7759 r7777  
    3939    @author Oliver Scheuss
    4040*/
    41 class _NetworkExport GamestateHandler{
     41class _NetworkExport GamestateHandler
     42{
    4243  private:
    43     virtual bool      add(packet::Gamestate *gs, unsigned int clientID)=0;
    44     virtual bool      ack(unsigned int gamestateID, unsigned int clientID)=0;
    45 
    46     static GamestateHandler* instance_;
    4744
    4845
     
    5249
    5350  public:
    54     static bool     addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); }
    55     static bool     ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); }
    56     static GamestateHandler* getInstance(){ assert(instance_); return instance_; }
    57    
     51    virtual bool      addGamestate(packet::Gamestate* gs, unsigned int clientID) = 0;
     52    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int clientID) = 0;
    5853    virtual uint32_t  getLastProcessedGamestateID( unsigned int clientID )=0;
    5954    virtual uint32_t  getCurrentGamestateID()=0;
  • code/branches/network5/src/libraries/network/GamestateManager.cc

    r7773 r7777  
    4343#include <cassert>
    4444#include <queue>
    45 #include "util/Clock.h"
    4645// #include <boost/thread/mutex.hpp>
    4746
    48 #include "util/Debug.h"
    49 #include "core/ThreadPool.h"
    50 #include "core/command/Executor.h"
    51 #include "ClientInformation.h"
    5247#include "packet/Acknowledgement.h"
    5348#include "packet/Gamestate.h"
    5449#include "synchronisable/NetworkCallbackManager.h"
    55 #include "TrafficControl.h"
     50
     51#include "core/ThreadPool.h"
     52#include "core/command/Executor.h"
     53#include "core/GameMode.h"
     54#include "util/Debug.h"
     55#include "util/Clock.h"
     56// #include "TrafficControl.h"
    5657
    5758namespace orxonox
    5859{
    5960  GamestateManager::GamestateManager() :
    60   reference(0), id_(0)
    61   {
    62     trafficControl_ = new TrafficControl();
     61  currentGamestate_(0), id_(0)
     62  {
     63//     trafficControl_ = new TrafficControl();
    6364//     threadMutex_ = new boost::mutex();
    6465//     threadPool_ = new ThreadPool();
     
    6768  GamestateManager::~GamestateManager()
    6869  {
    69     if( this->reference )
    70         delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it;
     70    if( this->currentGamestate_ )
     71        delete this->currentGamestate_;std::map<unsigned int, packet::Gamestate*>::iterator it;
    7172    for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
    7273      delete it->second;
    73     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1;
    74     std::map<unsigned int, packet::Gamestate*>::iterator it2;
    75     for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1 )
    76     {
    77       for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
    78         delete it2->second;
    79     }
    80     this->trafficControl_->destroy();
     74    std::map<uint32_t, peerInfo>::iterator peerIt;
     75    std::map<uint32_t, packet::Gamestate*>::iterator gamestateIt;
     76    for( peerIt = peerMap_.begin(); peerIt != peerMap_.end(); ++peerIt )
     77    {
     78      for( gamestateIt = peerIt->second.gamestates.begin(); gamestateIt != peerIt->second.gamestates.end(); ++gamestateIt )
     79        delete gamestateIt->second;
     80    }
     81//     this->trafficControl_->destroy();
    8182//     delete this->threadMutex_;
    8283//     delete this->threadPool_;
     
    8889  }
    8990
    90   bool GamestateManager::add(packet::Gamestate *gs, unsigned int clientID){
     91  bool GamestateManager::addGamestate(packet::Gamestate *gs, unsigned int clientID)
     92  {
    9193    assert(gs);
    9294    std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID);
     
    99101  }
    100102
    101   bool GamestateManager::processGamestates(){
     103  bool GamestateManager::processGamestates()
     104  {
    102105    if( this->gamestateQueue.empty() )
    103106        return true;
     
    118121
    119122  bool GamestateManager::getSnapshot(){
    120     if ( reference != 0 )
    121       delete reference;
    122     reference = new packet::Gamestate();
    123     if(!reference->collectData(++id_, 0x1)){ //we have no data to send
    124       delete reference;
    125       reference=0;
     123    if ( currentGamestate_ != 0 )
     124      delete currentGamestate_;
     125    currentGamestate_ = new packet::Gamestate();
     126    uint8_t gsMode;
     127    if( GameMode::isMaster() )
     128      gsMode = packet::GAMESTATE_MODE_SERVER;
     129    else
     130      gsMode = packet::GAMESTATE_MODE_CLIENT;
     131    uint32_t newID;
     132    if( GameMode::isMaster() )
     133      newID = ++id_;
     134    else
     135      newID = peerMap_[NETWORK_PEER_ID_SERVER].lastProcessedGamestateID;
     136   
     137    if(!currentGamestate_->collectData(newID, gsMode)){ //we have no data to send
     138      delete currentGamestate_;
     139      currentGamestate_=0;
    126140    }
    127141    return true;
    128142  }
    129143
    130   void GamestateManager::sendGamestates()
    131   {
    132     ClientInformation *temp = ClientInformation::getBegin();
    133     std::queue<packet::Gamestate*> clientGamestates;
    134     while(temp != NULL){
    135       if( !(temp->getSynched()) ){
     144  std::vector<packet::Gamestate*> GamestateManager::getGamestates()
     145  {
     146    if(!currentGamestate_)
     147      return std::vector<packet::Gamestate*>();
     148    std::vector<packet::Gamestate*> peerGamestates;
     149   
     150    std::map<uint32_t, peerInfo>::iterator peerIt;
     151    for( peerIt=peerMap_.begin(); peerIt!=peerMap_.end(); ++peerIt )
     152    {
     153      if( !peerIt->second.isSynched )
     154      {
    136155        COUT(5) << "Server: not sending gamestate" << std::endl;
    137         temp=temp->next();
    138         if(!temp)
    139           break;
    140156        continue;
    141157      }
    142       COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
     158      COUT(4) << "client id: " << peerIt->first << std::endl;
    143159      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
    144       int cid = temp->getID(); //get client id
    145 
    146       unsigned int gID = temp->getGamestateID();
    147       if(!reference)
    148         return;
    149 
    150       packet::Gamestate *client=0;
    151       if(gID != GAMESTATEID_INITIAL){
    152         assert(gamestateMap_.find(cid)!=gamestateMap_.end());
    153         std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID);
    154         if(it!=gamestateMap_[cid].end())
    155         {
    156           client = it->second;
    157         }
    158       }
    159 
    160       clientGamestates.push(0);
    161       finishGamestate( cid, clientGamestates.back(), client, reference );
     160      int peerID = peerIt->first; //get client id
     161
     162      unsigned int lastAckedGamestateID = peerIt->second.lastAckedGamestateID;
     163
     164      packet::Gamestate* baseGamestate=0;
     165      if(lastAckedGamestateID != GAMESTATEID_INITIAL)
     166      {
     167        assert(peerMap_.find(peerID)!=peerMap_.end());
     168        std::map<uint32_t, packet::Gamestate*>::iterator it = peerMap_[peerID].gamestates.find(lastAckedGamestateID);
     169        assert(it!=peerMap_[peerID].gamestates.end());
     170        baseGamestate = it->second;
     171      }
     172
     173      peerGamestates.push_back(0);  // insert an empty gamestate* to change
     174      finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ );
    162175      //FunctorMember<GamestateManager>* functor =
    163176//       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) );
    164 //       executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
     177//       executor->setDefaultValues( cid, &clientGamestates.back(), client, currentGamestate_ );
    165178//       (*static_cast<Executor*>(executor))();
    166179//       this->threadPool_->passFunction( executor, true );
    167 //       (*functor)( cid, &(clientGamestates.back()), client, reference );
    168 
    169       temp = temp->next();
     180//       (*functor)( cid, &(clientGamestates.back()), client, currentGamestate_ );
    170181    }
    171182
    172183//     threadPool_->synchronise();
    173184
    174     while( !clientGamestates.empty() )
    175     {
    176       if(clientGamestates.front())
    177         clientGamestates.front()->send();
    178       clientGamestates.pop();
    179     }
    180   }
    181 
    182 
    183   void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
     185    return peerGamestates;
     186  }
     187
     188
     189  void GamestateManager::finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
    184190    //why are we searching the same client's gamestate id as we searched in
    185191    //Server::sendGameState?
     
    194200//     gs->collectData( id_, 0x1 );
    195201//     this->threadMutex_->lock();
    196     gamestateMap_[clientID][gamestate->getID()]=gs;
     202    peerMap_[peerID].gamestates[gamestate->getID()]=gs;
    197203//     this->threadMutex_->unlock();
    198       Clock clock;
    199       clock.capture();
     204    Clock clock;
     205    clock.capture();
    200206
    201207    if(base)
     
    218224//     bool b = gs->compressData();
    219225//     assert(b);
    220       clock.capture();
    221       COUT(4) << "diff and compress time: " << clock.getDeltaTime() << endl;
     226    clock.capture();
     227    COUT(4) << "diff and compress time: " << clock.getDeltaTime() << endl;
    222228//     COUT(5) << "sending gamestate with id " << gs->getID();
    223229//     if(gamestate->isDiffed())
     
    225231//     else
    226232//       COUT(5) << endl;
    227     gs->setClientID(clientID);
     233    gs->setPeerID(peerID);
    228234    destgamestate = gs;
    229235  }
    230236
    231237
    232   bool GamestateManager::ack(unsigned int gamestateID, unsigned int clientID) {
    233     ClientInformation *temp = ClientInformation::findClient(clientID);
    234     assert(temp);
    235     unsigned int curid = temp->getGamestateID();
     238  bool GamestateManager::ackGamestate(unsigned int gamestateID, unsigned int peerID) {
     239//     ClientInformation *temp = ClientInformation::findClient(peerID);
     240//     assert(temp);
     241    std::map<uint32_t, peerInfo>::iterator it = this->peerMap_.find(peerID);
     242    assert(it!=this->peerMap_.end());
     243    unsigned int curid = it->second.lastAckedGamestateID;
    236244
    237245    if(gamestateID == ACKID_NACK){
    238       temp->setGamestateID(GAMESTATEID_INITIAL);
     246      it->second.lastAckedGamestateID = GAMESTATEID_INITIAL;
     247//       temp->setGamestateID(GAMESTATEID_INITIAL);
    239248      // now delete all saved gamestates for this client
    240       std::map<unsigned int, packet::Gamestate*>::iterator it;
    241       for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){
    242         delete it->second;
    243 
    244         gamestateMap_[clientID].erase(it++);
    245       }
     249      std::map<uint32_t, packet::Gamestate*>::iterator it2;
     250      for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){
     251        delete it2->second;
     252      }
     253      it->second.gamestates.clear();
    246254      return true;
    247255    }
    248256
    249257    assert(curid==GAMESTATEID_INITIAL || curid<gamestateID);
    250     COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
    251     std::map<unsigned int, packet::Gamestate*>::iterator it;
    252     for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){
    253       delete it->second;
    254       gamestateMap_[clientID].erase(it++);
    255     }
    256     temp->setGamestateID(gamestateID);
    257     TrafficControl::processAck(clientID, gamestateID);
     258    COUT(5) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl;
     259    std::map<uint32_t, packet::Gamestate*>::iterator it2;
     260    for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); )
     261    {
     262      if( it2->second->getID() < gamestateID )
     263      {
     264        delete it2->second;
     265        it->second.gamestates.erase(it2++);
     266      }
     267      else
     268        ++it2;
     269    }
     270   
     271//     std::map<unsigned int, packet::Gamestate*>::iterator it;
     272//     for(it = gamestateMap_[peerID].begin(); it!=gamestateMap_[peerID].end() && it->first<gamestateID; ){
     273//       delete it->second;
     274//       gamestateMap_[peerID].erase(it++);
     275//     }
     276    it->second.lastAckedGamestateID = gamestateID;
     277//     temp->setGamestateID(gamestateID);
     278//     TrafficControl::processAck(peerID, gamestateID);
    258279    return true;
    259280  }
    260281 
    261   uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int clientID)
    262   {
    263     assert( this->lastProcessedGamestateID_.find(clientID) != this->lastProcessedGamestateID_.end() );
    264     if( this->lastProcessedGamestateID_.find(clientID) != this->lastProcessedGamestateID_.end() )
    265       return this->lastProcessedGamestateID_[clientID];
     282  uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int peerID)
     283  {
     284    assert( this->peerMap_.find(peerID)!=this->peerMap_.end() );
     285    if( this->peerMap_.find(peerID) != this->peerMap_.end() )
     286      return this->peerMap_[peerID].lastProcessedGamestateID;
    266287    else
    267288      return GAMESTATEID_INITIAL;
    268289  }
    269 
    270   void GamestateManager::removeClient(ClientInformation* client){
    271     assert(client);
    272     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
    273     // first delete all remained gamestates
    274     std::map<unsigned int, packet::Gamestate*>::iterator it;
    275     for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++)
    276       delete it->second;
    277     // now delete the clients gamestatemap
    278     gamestateMap_.erase(clientMap);
    279   }
    280 
    281   bool GamestateManager::processGamestate(packet::Gamestate *gs){
     290 
     291 
     292  void GamestateManager::addPeer(uint32_t peerID)
     293  {
     294    assert(peerMap_.find(peerID)==peerMap_.end());
     295    peerMap_[peerID].peerID = peerID;
     296    peerMap_[peerID].lastProcessedGamestateID = GAMESTATEID_INITIAL;
     297    peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL;
     298    if( GameMode::isMaster() )
     299      peerMap_[peerID].isSynched = false;
     300    else
     301      peerMap_[peerID].isSynched = true;
     302  }
     303
     304  void GamestateManager::removePeer(uint32_t peerID)
     305  {
     306    assert(peerMap_.find(peerID)!=peerMap_.end());
     307    std::map<uint32_t, packet::Gamestate*>::iterator peerIt;
     308    for( peerIt = peerMap_[peerID].gamestates.begin(); peerIt!=peerMap_[peerID].gamestates.end(); ++peerIt )
     309    {
     310      delete peerIt->second;
     311    }
     312    peerMap_.erase(peerMap_.find(peerID));
     313  }
     314
     315
     316//   void GamestateManager::removeClient(ClientInformation* client){
     317//     assert(client);
     318//     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
     319//     // first delete all remained gamestates
     320//     std::map<unsigned int, packet::Gamestate*>::iterator it;
     321//     for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++)
     322//       delete it->second;
     323//     // now delete the clients gamestatemap
     324//     gamestateMap_.erase(clientMap);
     325//   }
     326
     327  bool GamestateManager::processGamestate(packet::Gamestate *gs)
     328  {
    282329    if(gs->isCompressed())
    283330    {
     
    286333    }
    287334    assert(!gs->isDiffed());
    288     if( gs->spreadData(0x1) )
    289     {
    290       this->lastProcessedGamestateID_[gs->getClientID()] = gs->getID();
     335    uint8_t gsMode;
     336    if( GameMode::isMaster() )
     337      gsMode = packet::GAMESTATE_MODE_SERVER;
     338    else
     339      gsMode = packet::GAMESTATE_MODE_CLIENT;
     340    if( gs->spreadData(gsMode) )
     341    {
     342      this->peerMap_[gs->getPeerID()].lastProcessedGamestateID = gs->getID();
    291343      return true;
    292344    }
  • code/branches/network5/src/libraries/network/GamestateManager.h

    r7759 r7777  
    4747#include "core/CorePrereqs.h"
    4848#include "packet/Gamestate.h"
     49#include <boost/concept_check.hpp>
    4950
    5051namespace orxonox
     
    6768  * @author Oliver Scheuss
    6869  */
    69   class _NetworkExport GamestateManager: public GamestateHandler{
     70  class _NetworkExport GamestateManager: public GamestateHandler
     71  {
     72    struct peerInfo
     73    {
     74      uint32_t  peerID;
     75      uint32_t  lastProcessedGamestateID;
     76      uint32_t  lastAckedGamestateID;
     77      bool      isSynched;
     78      std::map< uint32_t, packet::Gamestate* > gamestates;
     79    };
     80   
    7081  public:
     82   
    7183    GamestateManager();
    7284    ~GamestateManager();
    7385
    74     virtual bool      add(packet::Gamestate *gs, unsigned int clientID);
    75     virtual bool      ack(unsigned int gamestateID, unsigned int clientID);
    76     virtual uint32_t  getLastProcessedGamestateID( unsigned int clientID );
    77     virtual uint32_t  getCurrentGamestateID(){ return reference->getID(); }
     86    virtual bool      addGamestate(packet::Gamestate *gs, unsigned int peerID);
     87    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int peerID);
     88    virtual uint32_t  getLastProcessedGamestateID( unsigned int peerID );
     89    virtual uint32_t  getCurrentGamestateID(){ return currentGamestate_->getID(); }
    7890   
    7991    bool processGamestates();
    8092    bool update();
    81     void sendGamestates();
    82 //     packet::Gamestate *popGameState(unsigned int clientID);
    83     void finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
     93    std::vector<packet::Gamestate*> getGamestates();
     94    void finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
    8495
    8596    bool getSnapshot();
    8697
    87     void removeClient(ClientInformation *client);
     98    void addPeer( uint32_t peerID );
     99    void setSynched( uint32_t peerID )
     100      { assert(peerMap_.find(peerID)!=peerMap_.end()); peerMap_[peerID].isSynched = true; }
     101    void removePeer( uint32_t peerID );
     102//     void removeClient(ClientInformation *client);
    88103  private:
    89104    bool processGamestate(packet::Gamestate *gs);
    90105
    91     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
     106//     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
    92107    std::map<unsigned int, packet::Gamestate*> gamestateQueue;
    93     std::map<unsigned int, uint32_t> lastProcessedGamestateID_;
    94     packet::Gamestate *reference;
    95     TrafficControl *trafficControl_;
     108//     std::map<unsigned int, uint32_t> lastProcessedGamestateID_;
     109    std::map<uint32_t, peerInfo> peerMap_;
     110    packet::Gamestate* currentGamestate_;
     111//     TrafficControl *trafficControl_;
    96112    unsigned int id_;
    97113//     boost::mutex* threadMutex_;
  • code/branches/network5/src/libraries/network/Host.cc

    r7772 r7777  
    4545  // Host*               Host::instance_=0;
    4646  uint32_t            Host::clientID_s=0;
    47   uint32_t            Host::shipID_s=-1;
     47//   uint32_t            Host::shipID_s=-1;
    4848  std::vector<Host*>  Host::instances_s;
    4949
  • code/branches/network5/src/libraries/network/Host.h

    r7772 r7777  
    3131
    3232#include "NetworkPrereqs.h"
     33#include "GamestateManager.h"
    3334#include "core/CorePrereqs.h"
    3435
     
    4950*       @author Oliver Scheuss
    5051*/
    51 class _NetworkExport Host{
     52class _NetworkExport Host: public GamestateManager
     53{
    5254  private:
    5355    //TODO add these functions or adequate
     
    7577//     static bool receiveChat(packet::Chat *message, unsigned int clientID);
    7678    static unsigned int getPlayerID(){ return clientID_s; }
    77     static unsigned int getShipID(){return shipID_s;}
    7879    static void setClientID(unsigned int id){ clientID_s = id; }
    79     static void setShipID(unsigned int id){ shipID_s = id; }
    8080    static bool isServer();
    8181    static void Chat(const std::string& message);
     
    8686  private:
    8787    static uint32_t clientID_s;
    88     static uint32_t shipID_s;
    8988    static std::vector<Host*> instances_s;
    9089    bool bIsActive_;
  • code/branches/network5/src/libraries/network/Server.cc

    r7773 r7777  
    162162    while(temp){
    163163      chat = new packet::Chat(message, playerID);
    164       chat->setClientID(temp->getID());
    165       if(!chat->send())
     164      chat->setPeerID(temp->getID());
     165      if(!chat->send( static_cast<Host*>(this) ))
    166166        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
    167167      temp = temp->next();
     
    220220
    221221      // send function calls to clients
    222       FunctionCallManager::sendCalls();
     222      FunctionCallManager::sendCalls( static_cast<Host*>(this) );
    223223
    224224      //this steers our network frequency
     
    271271      return;
    272272    GamestateManager::update();
    273     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
     273//     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
    274274    //std::cout << "updated gamestate, sending it" << std::endl;
    275275    //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
    276     sendGameState();
     276    sendGameStates();
    277277    sendObjectDeletes();
    278     COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
     278//     COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
    279279    //std::cout << "sent gamestate" << std::endl;
    280280  }
    281281
    282   bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){
    283     packet::Packet *p = packet::Packet::createPacket(packet, peer);
    284     return p->process();
    285   }
    286 
    287   /**
    288   * sends the gamestate
    289   */
    290   bool Server::sendGameState()
    291   {
    292 //     COUT(5) << "Server: starting function sendGameState" << std::endl;
    293 //     ClientInformation *temp = ClientInformation::getBegin();
    294 //     bool added=false;
    295 //     while(temp != NULL){
    296 //       if( !(temp->getSynched()) ){
    297 //         COUT(5) << "Server: not sending gamestate" << std::endl;
    298 //         temp=temp->next();
    299 //         if(!temp)
    300 //           break;
    301 //         continue;
    302 //       }
    303 //       COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
    304 //       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
    305 //       int cid = temp->getID(); //get client id
    306 //       packet::Gamestate *gs = GamestateManager::popGameState(cid);
    307 //       if(gs==NULL){
    308 //         COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
    309 //         temp = temp->next();
    310 //         continue;
    311 //       }
    312 //       //std::cout << "adding gamestate" << std::endl;
    313 //       gs->setClientID(cid);
    314 //       if ( !gs->send() ){
    315 //         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
    316 //         temp->addFailure();
    317 //       }else
    318 //         temp->resetFailures();
    319 //       added=true;
    320 //       temp=temp->next();
    321 //       // gs gets automatically deleted by enet callback
    322 //     }
    323     GamestateManager::sendGamestates();
     282  /**
     283  * sends the current gamestate to all peers
     284  */
     285  bool Server::sendGameStates()
     286  {
     287    std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
     288    std::vector<packet::Gamestate*>::iterator it;
     289    for( it = gamestates.begin(); it != gamestates.end(); ++it )
     290    {
     291      (*it)->send(static_cast<Host*>(this));
     292    }
    324293    return true;
    325294  }
     295
    326296
    327297  bool Server::sendObjectDeletes()
     
    348318      packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
    349319      assert(cd);
    350       cd->setClientID(cid);
    351       if ( !cd->send() )
    352         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
     320      cd->setPeerID(cid);
     321      if ( !cd->send( static_cast<Host*>(this) ) )
     322        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl;
    353323      temp=temp->next();
    354324      // gs gets automatically deleted by enet callback
     
    374344    // inform all the listeners
    375345    ClientConnectionListener::broadcastClientConnected(newid);
     346    GamestateManager::addPeer(newid);
    376347
    377348    ++newid;
     
    394365    }
    395366  }
     367 
     368  void Server::processPacket(packet::Packet* packet)
     369  {
     370    if( packet->isReliable() )
     371    {
     372      if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
     373        packet->process(static_cast<Host*>(this));
     374      else
     375        this->packetQueue_.push_back(packet);
     376    }
     377    else
     378      packet->process(static_cast<Host*>(this));
     379  }
     380
    396381
    397382  bool Server::createClient(int clientID)
     
    403388      return false;
    404389    }
    405     COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl;
     390    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
    406391
    407392    // synchronise class ids
     
    410395    // now synchronise functionIDs
    411396    packet::FunctionIDs *fIDs = new packet::FunctionIDs();
    412     fIDs->setClientID(clientID);
    413     bool b = fIDs->send();
     397    fIDs->setPeerID(clientID);
     398    bool b = fIDs->send( static_cast<Host*>(this) );
    414399    assert(b);
    415400
    416401    temp->setSynched(true);
     402    GamestateManager::setSynched(clientID);
     403   
    417404    COUT(4) << "sending welcome" << std::endl;
    418405    packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
    419     w->setClientID(temp->getID());
    420     b = w->send();
     406    w->setPeerID(temp->getID());
     407    b = w->send( static_cast<Host*>(this) );
    421408    assert(b);
    422409    packet::Gamestate *g = new packet::Gamestate();
    423     g->setClientID(temp->getID());
    424     b = g->collectData(0,0x1);
     410    g->setPeerID(temp->getID());
     411    b = g->collectData(0,packet::GAMESTATE_MODE_SERVER);
     412    assert(b);
    425413    if(!b)
    426414      return false; //no data for the client
    427415//     b = g->compressData();
    428416//     assert(b);
    429     b = g->send();
     417    b = g->send( static_cast<Host*>(this) );
    430418    assert(b);
    431419    return true;
     
    435423  {
    436424    ServerConnection::disconnectClient( client );
    437     GamestateManager::removeClient(client);
     425    GamestateManager::removePeer(client->getID());
    438426    // inform all the listeners
    439427    // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
     
    457445    {
    458446      chat = new packet::Chat(message, clientID);
    459       chat->setClientID(temp->getID());
    460       if(!chat->send())
     447      chat->setPeerID(temp->getID());
     448      if(!chat->send( static_cast<Host*>(this) ))
    461449        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
    462450      temp = temp->next();
     
    473461    int failures=0;
    474462    packet::ClassID *classid = new packet::ClassID();
    475     classid->setClientID(clientID);
    476     while(!classid->send() && failures < 10){
     463    classid->setPeerID(clientID);
     464    while(!classid->send( static_cast<Host*>(this) ) && failures < 10){
    477465      failures++;
    478466    }
  • code/branches/network5/src/libraries/network/Server.h

    r7772 r7777  
    3232#include "NetworkPrereqs.h"
    3333
     34#include <deque>
     35
    3436#include "util/UtilPrereqs.h"
    3537#include "core/CorePrereqs.h"
    3638#include "Host.h"
    37 #include "GamestateManager.h"
     39// #include "GamestateManager.h"
    3840#include "ServerConnection.h"
    3941#include "LANDiscoverable.h"
     
    4951  * It implements all functions necessary for a Server
    5052  */
    51   class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager, public LANDiscoverable{
     53  class _NetworkExport Server : public Host, public ServerConnection, public LANDiscoverable{
    5254  public:
    5355    Server();
     
    7375  private:
    7476    virtual bool isServer_(){return true;}
    75     unsigned int shipID(){return 0;}
    7677    unsigned int playerID(){return 0;}
    7778
    7879    void addPeer(ENetEvent *event);
    7980    void removePeer(ENetEvent *event);
     81    void processPacket(packet::Packet* packet);
    8082
    8183    bool createClient(int clientID);
    8284    void disconnectClient( ClientInformation *client);
    83     bool processPacket( ENetPacket *packet, ENetPeer *peer );
    84     bool sendGameState();
     85    bool sendGameStates();
    8586    bool sendObjectDeletes();
    8687    virtual bool chat(const std::string& message);
     
    9192    float timeSinceLastUpdate_;
    9293    MasterServerComm msc;
     94    std::deque<packet::Packet*> packetQueue_;
    9395  };
    9496
  • code/branches/network5/src/libraries/network/packet/Acknowledgement.cc

    r6417 r7777  
    3131#include "util/Debug.h"
    3232#include "network/GamestateHandler.h"
     33#include "network/Host.h"
    3334
    3435namespace orxonox {
     
    3940#define _ACKID              _PACKETID + sizeof(packet::Type::Value)
    4041
    41 Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
     42Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID )
    4243 : Packet()
    4344{
     
    4647  *(Type::Value *)(data_ + _PACKETID ) = Type::Acknowledgement;
    4748  *(uint32_t *)(data_ + _ACKID ) = id;
    48   clientID_=clientID;
     49  peerID_=peerID;
    4950}
    5051
    51 Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID )
    52   : Packet(data, clientID)
     52Acknowledgement::Acknowledgement( uint8_t *data, unsigned int peerID )
     53  : Packet(data, peerID)
    5354{
    5455}
     
    6263}
    6364
    64 bool Acknowledgement::process(){
     65bool Acknowledgement::process(orxonox::Host* host){
    6566  COUT(5) << "processing ACK with ID: " << getAckID() << endl;
    66   bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);
     67  bool b = host->ackGamestate(getAckID(), peerID_);
    6768  delete this;
    6869  return b;
  • code/branches/network5/src/libraries/network/packet/Acknowledgement.h

    r6073 r7777  
    4242{
    4343public:
    44   Acknowledgement( unsigned int id, unsigned int clientID );
    45   Acknowledgement( uint8_t* data, unsigned int clientID );
     44  Acknowledgement( unsigned int id, unsigned int peerID );
     45  Acknowledgement( uint8_t* data, unsigned int peerID );
    4646  ~Acknowledgement();
    4747
    4848  inline unsigned int getSize() const;
    49   bool process();
     49  virtual bool process(orxonox::Host* host);
    5050
    5151  unsigned int getAckID();
  • code/branches/network5/src/libraries/network/packet/Chat.cc

    r7163 r7777  
    8080}
    8181
    82 bool Chat::process(){
    83   bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
     82bool Chat::process(orxonox::Host* host){
     83  bool b = host->incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
    8484  delete this;
    8585  return b;
  • code/branches/network5/src/libraries/network/packet/Chat.h

    r7163 r7777  
    5252
    5353  /* process chat message packet and remove it afterwards */
    54   bool process();
     54  virtual bool process(orxonox::Host* host);
    5555
    5656  /* Get the length of the message (not the full size of the packet) */
  • code/branches/network5/src/libraries/network/packet/ClassID.cc

    r7163 r7777  
    120120
    121121
    122 bool ClassID::process(){
     122bool ClassID::process(orxonox::Host* host){
    123123  int nrOfClasses;
    124124  uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
  • code/branches/network5/src/libraries/network/packet/ClassID.h

    r6417 r7777  
    4848
    4949  uint32_t getSize() const;
    50   bool process();
     50  virtual bool process(orxonox::Host* host);
    5151
    5252private:
  • code/branches/network5/src/libraries/network/packet/DeleteObjects.cc

    r6417 r7777  
    5757}
    5858
    59 bool DeleteObjects::fetchIDs(){
     59bool DeleteObjects::fetchIDs()
     60{
    6061  unsigned int number = Synchronisable::getNumberOfDeletedObject();
    6162  if(number==0)
     
    7980}
    8081
    81 unsigned int DeleteObjects::getSize() const{
     82unsigned int DeleteObjects::getSize() const
     83{
    8284  assert(data_);
    8385  return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t);
    8486}
    8587
    86 bool DeleteObjects::process(){
    87   for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){
     88bool DeleteObjects::process(orxonox::Host* host)
     89{
     90  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++)
     91  {
    8892    COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;
    8993    Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
  • code/branches/network5/src/libraries/network/packet/DeleteObjects.h

    r6073 r7777  
    3232#include "Packet.h"
    3333
    34 namespace orxonox {
    35 namespace packet {
     34namespace orxonox
     35{
     36namespace packet
     37{
    3638/**
    3739    @author
     
    4749
    4850  inline unsigned int getSize() const;
    49   bool process();
     51  virtual bool process(orxonox::Host* host);
    5052
    5153private:
  • code/branches/network5/src/libraries/network/packet/FunctionCalls.cc

    r7759 r7777  
    5858
    5959
    60 bool FunctionCalls::process(){
     60bool FunctionCalls::process(orxonox::Host* host)
     61{
    6162  assert(isDataENetAllocated());
    6263 
     
    7071    FunctionCall fctCall;
    7172    fctCall.loadData(temp);
    72     if( this->minGamestateID_ > GamestateHandler::getInstance()->getLastProcessedGamestateID(this->getClientID()) || !fctCall.execute() )
     73    if( this->minGamestateID_ > host->getLastProcessedGamestateID(this->getPeerID()) || !fctCall.execute() )
    7374    {
    74       FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getClientID() );
     75      FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getPeerID() );
    7576    }
    7677  }
     
    8081}
    8182
    82 void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
     83void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5)
     84{
    8385  assert(!isDataENetAllocated());
    8486 
     
    8890}
    8991
    90 void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
     92void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5)
     93{
    9194  assert(!isDataENetAllocated());
    9295 
     
    9699}
    97100
    98 bool FunctionCalls::send()
     101bool FunctionCalls::send(orxonox::Host* host)
    99102{
    100   this->minGamestateID_ = GamestateHandler::getInstance()->getCurrentGamestateID();
     103  this->minGamestateID_ = host->getCurrentGamestateID();
    101104  assert(this->functionCalls_.size());
    102105  data_=new uint8_t[ currentSize_ ];
     
    114117  assert( temp==data_+currentSize_ );
    115118 
    116   Packet::send();
     119  Packet::send(host);
    117120  return true;
    118121}
  • code/branches/network5/src/libraries/network/packet/FunctionCalls.h

    r7759 r7777  
    5454  inline unsigned int getSize() const
    5555    { assert(!this->isDataENetAllocated()); return currentSize_; }
    56   bool process();
     56  virtual bool process(orxonox::Host* host);
    5757
    5858  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);
    5959  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);
    60   virtual bool send();
     60  virtual bool send(orxonox::Host* host);
    6161private:
    6262  std::queue<orxonox::FunctionCall> functionCalls_;
  • code/branches/network5/src/libraries/network/packet/FunctionIDs.cc

    r6417 r7777  
    4646
    4747
    48 FunctionIDs::FunctionIDs( ) : Packet(){
     48FunctionIDs::FunctionIDs( ) : Packet()
     49{
    4950  unsigned int nrOfFunctions=0;
    5051  unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nroffunctions
     
    5556  //calculate total needed size (for all strings and integers)
    5657  ObjectList<NetworkFunctionBase>::iterator it;
    57   for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it){
     58  for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it)
     59  {
    5860    const std::string& functionname = it->getName();
    5961    networkID = it->getNetworkID();
     
    7678  // now save all classids and classnames
    7779  std::pair<uint32_t, std::string> tempPair;
    78   while( !tempQueue.empty() ){
     80  while( !tempQueue.empty() )
     81  {
    7982    tempPair = tempQueue.front();
    8083    tempQueue.pop();
     
    98101}
    99102
    100 uint32_t FunctionIDs::getSize() const{
     103uint32_t FunctionIDs::getSize() const
     104{
    101105  assert(this->data_);
    102106  uint8_t *temp = data_+sizeof(uint32_t); // packet identification
     
    114118
    115119
    116 bool FunctionIDs::process(){
     120bool FunctionIDs::process(orxonox::Host* host)
     121{
    117122  int nrOfFunctions;
    118123  uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
     
    127132  temp += sizeof(uint32_t);
    128133
    129   for( int i=0; i<nrOfFunctions; i++){
     134  for( int i=0; i<nrOfFunctions; i++)
     135  {
    130136    networkID = *(uint32_t*)temp;
    131137    stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
  • code/branches/network5/src/libraries/network/packet/FunctionIDs.h

    r6417 r7777  
    4747  ~FunctionIDs();
    4848
    49   uint32_t getSize() const;
    50   bool process();
     49  virtual uint32_t getSize() const;
     50  virtual bool process(orxonox::Host* host);
    5151
    5252private:
  • code/branches/network5/src/libraries/network/packet/Gamestate.cc

    r7759 r7777  
    3636#include "network/synchronisable/Synchronisable.h"
    3737#include "network/GamestateHandler.h"
     38#include "network/Host.h"
    3839
    3940namespace orxonox {
     
    4445
    4546// #define PACKET_FLAG_GAMESTATE  PacketFlag::Unsequenced
    46 // #define PACKET_FLAG_GAMESTATE  0
    47 #define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
     47#define PACKET_FLAG_GAMESTATE  0
     48// #define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
    4849
    4950inline bool memzero( uint8_t* data, uint32_t datalength)
     
    138139      assert(0); // if we don't use multithreading this part shouldn't be neccessary
    139140      // start allocate additional memory
    140       COUT(3) << "G.St.Man: need additional memory" << std::endl;
     141      COUT(3) << "Gamestate: need additional memory" << std::endl;
    141142      ObjectList<Synchronisable>::iterator temp = it;
    142143      uint32_t addsize=tempsize;
     
    165166  //stop write gamestate header
    166167
    167   COUT(5) << "G.ST.Man: Gamestate size: " << currentsize << std::endl;
    168   COUT(5) << "G.ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
     168  COUT(5) << "Gamestate: Gamestate size: " << currentsize << std::endl;
     169  COUT(5) << "Gamestate: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
    169170  return true;
    170171}
     
    173174bool Gamestate::spreadData(uint8_t mode)
    174175{
    175   COUT(4) << "processing gamestate with id " << header_.getID() << endl;
     176  COUT(5) << "processing gamestate with id " << header_.getID() << endl;
    176177  assert(data_);
    177178  assert(!header_.isCompressed());
     
    204205    }
    205206  }
     207  assert(mem-data_ == GamestateHeader::getSize()+header_.getDataSize());
     208 
    206209   // In debug mode, check first, whether there are no duplicate objectIDs
    207210#ifndef NDEBUG
     
    269272
    270273
    271 bool Gamestate::process()
    272 {
    273   return GamestateHandler::addGamestate(this, getClientID());
     274bool Gamestate::process(orxonox::Host* host)
     275{
     276  return host->addGamestate(this, getPeerID());
    274277}
    275278
     
    585588
    586589
    587   Gamestate *g = new Gamestate(newData, getClientID());
     590  Gamestate *g = new Gamestate(newData, getPeerID());
    588591  (g->header_) = header_;
    589592  g->header_.setBaseID( base->getID() );
     
    757760
    758761
    759 uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
     762uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode)
    760763{
    761764  uint32_t size = 0;
  • code/branches/network5/src/libraries/network/packet/Gamestate.h

    r7758 r7777  
    4242#include "Packet.h"
    4343
    44 namespace orxonox {
     44namespace orxonox
     45{
    4546
    46 namespace packet {
     47namespace packet
     48{
     49   
     50static const uint8_t GAMESTATE_MODE_SERVER = 0x1;
     51static const uint8_t GAMESTATE_MODE_CLIENT = 0x2;
    4752
    48 class _NetworkExport GamestateHeader{
     53class _NetworkExport GamestateHeader
     54{
    4955  public:
    5056    GamestateHeader(){ data_=0; }
     
    5864      { return 21; }
    5965
    60     inline int32_t getID() const
    61       { assert(data_); return *(int32_t*)(data_+4); }
    62     inline void setID(int32_t id)
    63       { assert(data_); *(int32_t*)(data_+4) = id; }
     66    inline uint32_t getID() const
     67      { assert(data_); return *(uint32_t*)(data_+4); }
     68    inline void setID(uint32_t id)
     69      { assert(data_); *(uint32_t*)(data_+4) = id; }
    6470
    65     inline int32_t getBaseID() const
    66       { assert(data_); return *(int32_t*)(data_+8); }
    67     inline void setBaseID(int32_t id)
    68       { assert(data_); *(int32_t*)(data_+8) = id; }
     71    inline uint32_t getBaseID() const
     72      { assert(data_); return *(uint32_t*)(data_+8); }
     73    inline void setBaseID(uint32_t id)
     74      { assert(data_); *(uint32_t*)(data_+8) = id; }
    6975
    7076    inline uint32_t getDataSize() const
     
    103109    @author Oliver Scheuss
    104110*/
    105 class _NetworkExport Gamestate: public Packet{
     111class _NetworkExport Gamestate: public Packet
     112{
    106113  public:
    107114    Gamestate();
     
    114121    bool collectData(int id, uint8_t mode=0x0);
    115122    bool spreadData( uint8_t mode=0x0);
    116     inline int32_t getID() const { return header_.getID(); }
     123    inline uint32_t getID() const { return header_.getID(); }
    117124    inline bool isDiffed() const { return header_.isDiffed(); }
    118125    inline bool isCompressed() const { return header_.isCompressed(); }
     
    132139//     inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );
    133140    virtual uint32_t getSize() const;
    134     virtual inline bool process();
    135     uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
     141    virtual bool process(orxonox::Host* host);
     142    uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0);
    136143//     inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
    137144//     inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
  • code/branches/network5/src/libraries/network/packet/Packet.cc

    r7773 r7777  
    6868  flags_ = PACKET_FLAG_DEFAULT;
    6969  packetDirection_ = Direction::Outgoing;
    70   clientID_=0;
     70  peerID_=0;
    7171  data_=0;
    7272  enetPacket_=0;
     
    7474}
    7575
    76 Packet::Packet(uint8_t *data, unsigned int clientID)
     76Packet::Packet(uint8_t *data, unsigned int peerID)
    7777{
    7878  flags_ = PACKET_FLAG_DEFAULT;
    7979  packetDirection_ = Direction::Incoming;
    80   clientID_=clientID;
     80  peerID_=peerID;
    8181  data_=data;
    8282  enetPacket_=0;
     
    8989  flags_=p.flags_;
    9090  packetDirection_ = p.packetDirection_;
    91   clientID_ = p.clientID_;
     91  peerID_ = p.peerID_;
    9292  if(p.data_){
    9393    data_ = new uint8_t[p.getSize()];
     
    125125}
    126126
    127 bool Packet::send(){
     127bool Packet::send(orxonox::Host* host){
    128128  if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){
    129129    assert(0);
     
    169169//  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
    170170  if( this->flags_ & PacketFlag::Reliable )
    171     Host::addPacket( enetPacket_, clientID_, NETWORK_CHANNEL_DEFAULT);
     171    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT);
    172172  else
    173     Host::addPacket( enetPacket_, clientID_, NETWORK_CHANNEL_UNRELIABLE);
     173    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE);
    174174  return true;
    175175}
     
    178178  uint8_t *data = packet->data;
    179179  assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
    180   unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
     180  unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
    181181  Packet *p = 0;
    182182//   COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
     
    185185    case Type::Acknowledgement:
    186186//       COUT(5) << "ack" << std::endl;
    187       p = new Acknowledgement( data, clientID );
     187    p = new Acknowledgement( data, peerID );
    188188      break;
    189189    case Type::Chat:
    190190//       COUT(5) << "chat" << std::endl;
    191       p = new Chat( data, clientID );
     191      p = new Chat( data, peerID );
    192192      break;
    193193    case Type::ClassID:
    194194//       COUT(5) << "classid" << std::endl;
    195       p = new ClassID( data, clientID );
     195      p = new ClassID( data, peerID );
    196196      break;
    197197    case Type::Gamestate:
    198198//       COUT(5) << "gamestate" << std::endl;
    199       p = new Gamestate( data, clientID );
     199      p = new Gamestate( data, peerID );
    200200      break;
    201201    case Type::Welcome:
    202202//       COUT(5) << "welcome" << std::endl;
    203       p = new Welcome( data, clientID );
     203      p = new Welcome( data, peerID );
    204204      break;
    205205    case Type::DeleteObjects:
    206206//       COUT(5) << "deleteobjects" << std::endl;
    207       p = new DeleteObjects( data, clientID );
     207      p = new DeleteObjects( data, peerID );
    208208      break;
    209209    case Type::FunctionCalls:
    210210//       COUT(5) << "functionCalls" << std::endl;
    211       p = new FunctionCalls( data, clientID );
     211      p = new FunctionCalls( data, peerID );
    212212      break;
    213213    case Type::FunctionIDs:
    214214//       COUT(5) << "functionIDs" << std::endl;
    215       p = new FunctionIDs( data, clientID );
     215      p = new FunctionIDs( data, peerID );
    216216      break;
    217217    default:
  • code/branches/network5/src/libraries/network/packet/Packet.h

    r7772 r7777  
    6868    virtual unsigned char *getData(){ return data_; };
    6969    virtual unsigned int getSize() const =0;
    70     virtual bool process()=0;
     70    virtual bool process(orxonox::Host* host)=0;
    7171    inline uint32_t getFlags()
    7272      { return flags_; }
    73     inline int getClientID()
    74       { return clientID_; }
    75     inline void setClientID( int id )
    76       { clientID_ = id; }
     73    inline int getPeerID()
     74      { return peerID_; }
     75    inline void setPeerID( int id )
     76      { peerID_ = id; }
     77    inline bool isReliable()
     78      { return this->flags_ & PacketFlag::Reliable; }
     79    inline uint32_t getRequiredGamestateID()
     80      { return this->requiredGamestateID_; }
    7781
    78     virtual bool send();
     82    virtual bool send(orxonox::Host* host);
    7983  protected:
    8084    Packet();
    81     Packet(uint8_t *data, unsigned int clientID);
     85    Packet(uint8_t *data, unsigned int peerID);
    8286//    Packet(ENetPacket *packet, ENetPeer *peer);
    8387    inline bool isDataENetAllocated() const
     
    8589
    8690    uint32_t flags_;
    87     unsigned int clientID_;
     91    unsigned int peerID_;
     92    uint32_t requiredGamestateID_;
    8893    Direction::Value packetDirection_;
    8994    /** Pointer to the data. Be careful when deleting it because it might
  • code/branches/network5/src/libraries/network/packet/Welcome.cc

    r5781 r7777  
    7373}
    7474
    75 bool Welcome::process(){
     75bool Welcome::process(orxonox::Host* host){
    7676  uint32_t clientID;
    7777  clientID = *(uint32_t *)(data_ + _CLIENTID );
    7878  assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321);
    79   Host::setClientID(clientID);
     79  host->setClientID(clientID);
    8080  COUT(3) << "Welcome set clientId: " << clientID << endl;
    8181  Synchronisable::setClient(true);
  • code/branches/network5/src/libraries/network/packet/Welcome.h

    r6073 r7777  
    4747  uint8_t *getData();
    4848  inline unsigned int getSize() const;
    49   bool process();
     49  virtual bool process(orxonox::Host* host);
    5050
    5151private:
  • code/branches/network5/src/orxonox/PlayerManager.cc

    r7474 r7777  
    5454    void PlayerManager::clientConnected(unsigned int clientID)
    5555    {
     56      COUT(0) << "PlayerManager: client connected with id: " << clientID << endl;
    5657        if (GameMode::isMaster())
    5758        {
  • code/branches/network5/src/orxonox/gametypes/Gametype.cc

    r7758 r7777  
    171171    void Gametype::playerEntered(PlayerInfo* player)
    172172    {
     173      COUT(0) << "Gametype: playerentered" << endl;
    173174        this->players_[player].state_ = PlayerState::Joined;
    174175    }
     
    411412    void Gametype::spawnPlayer(PlayerInfo* player)
    412413    {
     414      COUT(0) << "Gametype: spawnPlayer" << endl;
    413415        SpawnPoint* spawnpoint = this->getBestSpawnPoint(player);
    414416        if (spawnpoint)
  • code/branches/network5/src/orxonox/infos/HumanPlayer.cc

    r6417 r7777  
    4545    HumanPlayer::HumanPlayer(BaseObject* creator) : PlayerInfo(creator)
    4646    {
     47      COUT(0) << "new HumanPlayer" << endl;
    4748        RegisterObject(HumanPlayer);
    4849
     
    133134    void HumanPlayer::networkcallback_client_initialized()
    134135    {
     136      COUT(0) << "networkcallback_client_initialized" << endl;
    135137        if (this->getGametype())
    136138            this->getGametype()->playerEntered(this);
  • code/branches/network5/src/orxonox/worldentities/pawns/Spectator.cc

    r6417 r7777  
    4343    Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator)
    4444    {
     45      COUT(0) << "creating specator" << endl;
    4546        RegisterObject(Spectator);
    4647
Note: See TracChangeset for help on using the changeset viewer.