Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/libraries/network/FunctionCallManager.cc @ 10475

Last change on this file since 10475 was 10473, checked in by landauf, 9 years ago

bugfix and continuation of the last commit:

  • FunctionCall::execute() now returns the correct value (was inverted accidentally)
  • FunctionCall::setCall() new calculates the correct callsize (still included the 8bits for isStatic that was removed in the previous commit)
  • static and member network functions are now treated equally throughout the whole system (only the macros make a difference)
  • Property svn:eol-style set to native
File size: 5.1 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
[10473]42void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID)
[6417]43{
[7801]44  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2937]45  {
[7801]46    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
47    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]48  }
[10473]49  FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID);
[2937]50}
[10473]51void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1)
[6417]52{
[7801]53  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]54  {
[7801]55    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
56    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]57  }
[10473]58  FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, &mt1);
[2949]59}
[10473]60void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
[6417]61{
[7801]62  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]63  {
[7801]64    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
65    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]66  }
[10473]67  FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, &mt1, &mt2);
[2949]68}
[10473]69void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
[6417]70{
[7801]71  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]72  {
[7801]73    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
74    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]75  }
[10473]76  FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, &mt1, &mt2, &mt3);
[2949]77}
[10473]78void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
[6417]79{
[7801]80  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]81  {
[7801]82    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
83    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]84  }
[10473]85  FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
[2949]86}
[10473]87void FunctionCallManager::addCall(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]88{
[7801]89  if(sPeerMap_.find(peerID)==sPeerMap_.end())
[2949]90  {
[7801]91    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
92    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]93  }
[10473]94  FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
[2949]95}
[2937]96
[2949]97// Send calls
98
[7801]99void FunctionCallManager::sendCalls(orxonox::Host* host)
[2937]100{
101  std::map<uint32_t, packet::FunctionCalls*>::iterator it;
[7801]102  for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it )
[2944]103  {
[7801]104    assert(!FunctionCallManager::sPeerMap_.empty());
105    it->second->send(host);
[2944]106  }
[7801]107  FunctionCallManager::sPeerMap_.clear();
[2937]108}
109
[7801]110void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID)
[7495]111{
[7801]112  FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, peerID)));
[7495]113}
[2937]114
[7495]115void FunctionCallManager::processBufferedFunctionCalls()
116{
[7801]117  std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > >::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
[7495]118  while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() )
119  {
[8403]120    OrxAssert( Host::getActiveInstance(), "No Host class existing" );
121    if( it->second.first <= Host::getActiveInstance()->getLastReceivedGamestateID(it->second.second) && it->first.execute() )
[7495]122      FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it);
123    else
[7801]124    {
[7495]125      ++it;
[7801]126    }
[7495]127  }
128}
129
130
[2937]131} //namespace orxonox
Note: See TracBrowser for help on using the repository browser.