Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network5/src/libraries/network/FunctionCallManager.cc @ 7772

Last change on this file since 7772 was 7759, checked in by scheusso, 14 years ago

a lot of changes:

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