Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/network/FunctionCallManager.cc @ 8572

Last change on this file since 8572 was 8403, checked in by scheusso, 14 years ago

fixing possible bug with packet ordering

  • Property svn:eol-style set to native
File size: 7.6 KB
RevLine 
[2937]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "FunctionCallManager.h"
30#include "packet/FunctionCalls.h"
[7495]31#include "core/GameMode.h"
[7801]32#include "GamestateHandler.h"
[8403]33#include "Host.h"
34#include "util/OrxAssert.h"
[2937]35
36namespace orxonox {
[6417]37
[7801]38std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sPeerMap_;
39std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > > FunctionCallManager::sIncomingFunctionCallBuffer_;
[2937]40
[2949]41// Static calls
42
[7801]43void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID)
[6417]44{
[7801]45  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2937]46  {
[7801]47    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
48    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]49  }
[7801]50  FunctionCallManager::sPeerMap_[peerID]->addCallStatic(functionID);
[2937]51}
[7801]52void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1)
[6417]53{
[7801]54  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]55  {
[7801]56    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
57    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]58  }
[7801]59  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1);
[2949]60}
[7801]61void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
[6417]62{
[7801]63  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]64  {
[7801]65    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
66    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]67  }
[7801]68  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2);
[2949]69}
[7801]70void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
[6417]71{
[7801]72  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]73  {
[7801]74    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
75    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]76  }
[7801]77  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
[2949]78}
[7801]79void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
[6417]80{
[7801]81  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]82  {
[7801]83    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
84    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]85  }
[7801]86  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
[2949]87}
[7801]88void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
[6417]89{
[7801]90  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]91  {
[7801]92    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
93    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]94  }
[7801]95  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
[2949]96}
[2937]97
[2949]98
99// MemberCalls
100
[7801]101void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID)
[6417]102{
[7801]103  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2937]104  {
[7801]105    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
106    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]107  }
[7801]108  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID);
[2937]109}
[7801]110void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1)
[6417]111{
[7801]112  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]113  {
[7801]114    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
115    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]116  }
[7801]117  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1);
[2949]118}
[7801]119void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
[6417]120{
[7801]121  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]122  {
[7801]123    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
124    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]125  }
[7801]126  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2);
[2949]127}
[7801]128void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
[6417]129{
[7801]130  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]131  {
[7801]132    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
133    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]134  }
[7801]135  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
[2949]136}
[7801]137void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
[6417]138{
[7801]139  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]140  {
[7801]141    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
142    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]143  }
[7801]144  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
[2949]145}
[7801]146void 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)
[6417]147{
[7801]148  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]149  {
[7801]150    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
151    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]152  }
[7801]153  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
[2949]154}
[2937]155
[2949]156// Send calls
157
[7801]158void FunctionCallManager::sendCalls(orxonox::Host* host)
[2937]159{
160  std::map<uint32_t, packet::FunctionCalls*>::iterator it;
[7801]161  for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it )
[2944]162  {
[7801]163    assert(!FunctionCallManager::sPeerMap_.empty());
164    it->second->send(host);
[2944]165  }
[7801]166  FunctionCallManager::sPeerMap_.clear();
[2937]167}
168
[7801]169void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID)
[7495]170{
[7801]171  FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, peerID)));
[7495]172}
[2937]173
[7495]174void FunctionCallManager::processBufferedFunctionCalls()
175{
[7801]176  std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > >::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
[7495]177  while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() )
178  {
[8403]179    OrxAssert( Host::getActiveInstance(), "No Host class existing" );
180    if( it->second.first <= Host::getActiveInstance()->getLastReceivedGamestateID(it->second.second) && it->first.execute() )
[7495]181      FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it);
182    else
[7801]183    {
[7495]184      ++it;
[7801]185    }
[7495]186  }
187}
188
189
[2937]190} //namespace orxonox
Note: See TracBrowser for help on using the repository browser.