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 | |
---|
42 | void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) |
---|
43 | { |
---|
44 | if(sPeerMap_.find(peerID)==sPeerMap_.end()) |
---|
45 | { |
---|
46 | FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; |
---|
47 | FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); |
---|
48 | } |
---|
49 | FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, mt1, mt2, mt3, mt4, mt5); |
---|
50 | } |
---|
51 | |
---|
52 | // Send calls |
---|
53 | |
---|
54 | void FunctionCallManager::sendCalls(orxonox::Host* host) |
---|
55 | { |
---|
56 | for (const auto& mapEntry : FunctionCallManager::sPeerMap_ ) |
---|
57 | { |
---|
58 | assert(!FunctionCallManager::sPeerMap_.empty()); |
---|
59 | mapEntry.second->send(host); |
---|
60 | } |
---|
61 | FunctionCallManager::sPeerMap_.clear(); |
---|
62 | } |
---|
63 | |
---|
64 | void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID) |
---|
65 | { |
---|
66 | FunctionCallManager::sIncomingFunctionCallBuffer_.emplace_back(fctCall, std::make_pair(minGamestateID, peerID)); |
---|
67 | } |
---|
68 | |
---|
69 | void FunctionCallManager::processBufferedFunctionCalls() |
---|
70 | { |
---|
71 | std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t>>>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin(); |
---|
72 | while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() ) |
---|
73 | { |
---|
74 | OrxAssert( Host::getActiveInstance(), "No Host class existing" ); |
---|
75 | if( it->second.first <= Host::getActiveInstance()->getLastReceivedGamestateID(it->second.second) && it->first.execute() ) |
---|
76 | FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it++); |
---|
77 | else |
---|
78 | { |
---|
79 | ++it; |
---|
80 | } |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | } //namespace orxonox |
---|