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