Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mac_osx/src/libraries/network/FunctionCallManager.cc @ 7902

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