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