Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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