Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8324 was 7801, checked in by dafrick, 14 years ago

Merging presentation2 branch back to trunk.

  • Property svn:eol-style set to native
File size: 7.4 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"
[2937]33
34namespace orxonox {
[6417]35
[7801]36std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sPeerMap_;
37std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > > FunctionCallManager::sIncomingFunctionCallBuffer_;
[2937]38
[2949]39// Static calls
40
[7801]41void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID)
[6417]42{
[7801]43  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2937]44  {
[7801]45    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
46    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]47  }
[7801]48  FunctionCallManager::sPeerMap_[peerID]->addCallStatic(functionID);
[2937]49}
[7801]50void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1)
[6417]51{
[7801]52  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]53  {
[7801]54    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
55    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]56  }
[7801]57  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1);
[2949]58}
[7801]59void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
[6417]60{
[7801]61  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]62  {
[7801]63    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
64    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]65  }
[7801]66  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2);
[2949]67}
[7801]68void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
[6417]69{
[7801]70  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]71  {
[7801]72    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
73    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]74  }
[7801]75  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
[2949]76}
[7801]77void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
[6417]78{
[7801]79  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]80  {
[7801]81    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
82    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]83  }
[7801]84  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
[2949]85}
[7801]86void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
[6417]87{
[7801]88  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]89  {
[7801]90    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
91    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]92  }
[7801]93  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
[2949]94}
[2937]95
[2949]96
97// MemberCalls
98
[7801]99void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID)
[6417]100{
[7801]101  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2937]102  {
[7801]103    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
104    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]105  }
[7801]106  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID);
[2937]107}
[7801]108void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1)
[6417]109{
[7801]110  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]111  {
[7801]112    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
113    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]114  }
[7801]115  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1);
[2949]116}
[7801]117void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
[6417]118{
[7801]119  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]120  {
[7801]121    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
122    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]123  }
[7801]124  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2);
[2949]125}
[7801]126void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
[6417]127{
[7801]128  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]129  {
[7801]130    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
131    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]132  }
[7801]133  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
[2949]134}
[7801]135void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
[6417]136{
[7801]137  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]138  {
[7801]139    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
140    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]141  }
[7801]142  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
[2949]143}
[7801]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)
[6417]145{
[7801]146  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]147  {
[7801]148    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
149    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]150  }
[7801]151  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
[2949]152}
[2937]153
[2949]154// Send calls
155
[7801]156void FunctionCallManager::sendCalls(orxonox::Host* host)
[2937]157{
158  std::map<uint32_t, packet::FunctionCalls*>::iterator it;
[7801]159  for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it )
[2944]160  {
[7801]161    assert(!FunctionCallManager::sPeerMap_.empty());
162    it->second->send(host);
[2944]163  }
[7801]164  FunctionCallManager::sPeerMap_.clear();
[2937]165}
166
[7801]167void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID)
[7495]168{
[7801]169  FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, peerID)));
[7495]170}
[2937]171
[7495]172void FunctionCallManager::processBufferedFunctionCalls()
173{
[7801]174  std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > >::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
[7495]175  while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() )
176  {
[7801]177    if( it->first.execute() )
[7495]178      FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it);
179    else
[7801]180    {
[7495]181      ++it;
[7801]182    }
[7495]183  }
184}
185
186
[2937]187} //namespace orxonox
Note: See TracBrowser for help on using the repository browser.