Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7596 was 7495, checked in by scheusso, 14 years ago

buffering incoming function calls for non-existing objects works now

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