Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 21, 2010, 6:09:09 PM (14 years ago)
Author:
scheusso
Message:

merged network5 into presentation2 branch (untested)

Location:
code/branches/presentation2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2

  • code/branches/presentation2/src/libraries/network/FunctionCallManager.cc

    r7495 r7788  
    3030#include "packet/FunctionCalls.h"
    3131#include "core/GameMode.h"
     32#include "GamestateHandler.h"
    3233
    3334namespace orxonox {
    3435
    35 std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sClientMap_;
    36 std::vector<FunctionCall> FunctionCallManager::sIncomingFunctionCallBuffer_;
     36std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sPeerMap_;
     37std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > > FunctionCallManager::sIncomingFunctionCallBuffer_;
    3738
    3839// Static calls
    3940
    40 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID)
     41void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID)
    4142{
    42   if(sClientMap_.find(clientID)==sClientMap_.end())
     43  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    4344  {
    44     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    45     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     45    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     46    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    4647  }
    47   FunctionCallManager::sClientMap_[clientID]->addCallStatic(functionID);
     48  FunctionCallManager::sPeerMap_[peerID]->addCallStatic(functionID);
    4849}
    49 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1)
     50void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1)
    5051{
    51   if(sClientMap_.find(clientID)==sClientMap_.end())
     52  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    5253  {
    53     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    54     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     54    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     55    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    5556  }
    56   FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1);
     57  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1);
    5758}
    58 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)
    5960{
    60   if(sClientMap_.find(clientID)==sClientMap_.end())
     61  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    6162  {
    62     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    63     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     63    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     64    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    6465  }
    65   FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2);
     66  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2);
    6667}
    67 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)
    6869{
    69   if(sClientMap_.find(clientID)==sClientMap_.end())
     70  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    7071  {
    71     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    72     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     72    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     73    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    7374  }
    74   FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
     75  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
    7576}
    76 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)
    7778{
    78   if(sClientMap_.find(clientID)==sClientMap_.end())
     79  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    7980  {
    80     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    81     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     81    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     82    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    8283  }
    83   FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
     84  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
    8485}
    85 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)
    8687{
    87   if(sClientMap_.find(clientID)==sClientMap_.end())
     88  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    8889  {
    89     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    90     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     90    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     91    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    9192  }
    92   FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
     93  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
    9394}
    9495
     
    9697// MemberCalls
    9798
    98 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID)
     99void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID)
    99100{
    100   if(sClientMap_.find(clientID)==sClientMap_.end())
     101  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    101102  {
    102     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    103     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     103    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     104    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    104105  }
    105   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID);
     106  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID);
    106107}
    107 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)
    108109{
    109   if(sClientMap_.find(clientID)==sClientMap_.end())
     110  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    110111  {
    111     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    112     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     112    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     113    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    113114  }
    114   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1);
     115  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1);
    115116}
    116 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)
    117118{
    118   if(sClientMap_.find(clientID)==sClientMap_.end())
     119  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    119120  {
    120     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    121     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     121    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     122    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    122123  }
    123   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2);
     124  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2);
    124125}
    125 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)
    126127{
    127   if(sClientMap_.find(clientID)==sClientMap_.end())
     128  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    128129  {
    129     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    130     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     130    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     131    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    131132  }
    132   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
     133  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
    133134}
    134 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)
    135136{
    136   if(sClientMap_.find(clientID)==sClientMap_.end())
     137  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    137138  {
    138     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    139     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     139    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     140    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    140141  }
    141   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
     142  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
    142143}
    143 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)
    144145{
    145   if(sClientMap_.find(clientID)==sClientMap_.end())
     146  if(sPeerMap_.find(peerID)==sPeerMap_.end())
    146147  {
    147     FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
    148     FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
     148    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
     149    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
    149150  }
    150   FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
     151  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
    151152}
    152153
    153154// Send calls
    154155
    155 void FunctionCallManager::sendCalls()
     156void FunctionCallManager::sendCalls(orxonox::Host* host)
    156157{
    157158  std::map<uint32_t, packet::FunctionCalls*>::iterator it;
    158   for (it = FunctionCallManager::sClientMap_.begin(); it != FunctionCallManager::sClientMap_.end(); ++it )
     159  for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it )
    159160  {
    160     assert(!FunctionCallManager::sClientMap_.empty());
    161     it->second->send();
     161    assert(!FunctionCallManager::sPeerMap_.empty());
     162    it->second->send(host);
    162163  }
    163   FunctionCallManager::sClientMap_.clear();
     164  FunctionCallManager::sPeerMap_.clear();
    164165}
    165166
    166 void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall)
     167void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID)
    167168{
    168   if( !GameMode::isMaster() )
    169     FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( fctCall );
     169  FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, peerID)));
    170170}
    171171
    172172void FunctionCallManager::processBufferedFunctionCalls()
    173173{
    174   std::vector<FunctionCall>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
     174  std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > >::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
    175175  while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() )
    176176  {
    177     if( it->execute() )
     177    if( it->first.execute() )
    178178      FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it);
    179179    else
     180    {
    180181      ++it;
     182    }
    181183  }
    182184}
Note: See TracChangeset for help on using the changeset viewer.