/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Oliver Scheuss , (C) 2008 * Co-authors: * ... * */ #include "FunctionCallManager.h" #include "packet/FunctionCalls.h" #include "core/GameMode.h" #include "GamestateHandler.h" #include "Host.h" #include "util/OrxAssert.h" namespace orxonox { std::map FunctionCallManager::sPeerMap_; std::vector>> FunctionCallManager::sIncomingFunctionCallBuffer_; 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) { // If the peerID doesn't exist yet in the map... if(sPeerMap_.find(peerID) == sPeerMap_.end()) { // ... add a new FunctionCalls packet for the peer FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); } // Add a new function call to the peer FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, mt1, mt2, mt3, mt4, mt5); } /** * Send all function calls in sPeerMap_ to a given host, then clear sPeerMap_ * @param host The host to send the function calls to */ void FunctionCallManager::sendCalls(orxonox::Host* host) { for (const auto& mapEntry : FunctionCallManager::sPeerMap_ ) { assert(!FunctionCallManager::sPeerMap_.empty()); mapEntry.second->send(host); } FunctionCallManager::sPeerMap_.clear(); } /** * Place an incoming function call in the queue for processing. */ void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID) { FunctionCallManager::sIncomingFunctionCallBuffer_.emplace_back(fctCall, std::make_pair(minGamestateID, peerID)); } /** * Process queue of incoming function calls. */ void FunctionCallManager::processBufferedFunctionCalls() { std::vector>>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin(); while( it != FunctionCallManager::sIncomingFunctionCallBuffer_.end() ) { OrxAssert( Host::getActiveInstance(), "No Host class existing" ); if( it->second.first <= Host::getActiveInstance()->getLastReceivedGamestateID(it->second.second) && it->first.execute() ) FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it++); else { ++it; } } } } //namespace orxonox