Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Masterserver_FS18/src/libraries/network/FunctionCallManager.cc @ 11880

Last change on this file since 11880 was 11842, checked in by mdedial, 6 years ago

Clean up some code, add lots of comments

  • Property svn:eol-style set to native
File size: 3.5 KB
RevLine 
[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"
[7801]32#include "GamestateHandler.h"
[8403]33#include "Host.h"
34#include "util/OrxAssert.h"
[2937]35
36namespace orxonox {
[6417]37
[7801]38std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sPeerMap_;
[11071]39std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t>>> FunctionCallManager::sIncomingFunctionCallBuffer_;
[2937]40
[2949]41
[10624]42void 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)
[6417]43{
[11842]44  // If the peerID doesn't exist yet in the map...
45  if(sPeerMap_.find(peerID) == sPeerMap_.end())
[2937]46  {
[11842]47    // ... add a new FunctionCalls packet for the peer
[7801]48    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
49    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
[6417]50  }
[11842]51
52  // Add a new function call to the peer
[10624]53  FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, mt1, mt2, mt3, mt4, mt5);
[2937]54}
55
[11842]56/**
57 * Send all function calls in sPeerMap_ to a given host, then clear sPeerMap_
58 * @param host The host to send the function calls to
59 */
[7801]60void FunctionCallManager::sendCalls(orxonox::Host* host)
[2937]61{
[11071]62  for (const auto& mapEntry : FunctionCallManager::sPeerMap_ )
[2944]63  {
[11842]64    // TODO: This seems rather pointless, as it wouldn't be called anyways if the map was empty.
[7801]65    assert(!FunctionCallManager::sPeerMap_.empty());
[11071]66    mapEntry.second->send(host);
[2944]67  }
[11842]68  // TODO: Why is the map cleared here?
[7801]69  FunctionCallManager::sPeerMap_.clear();
[2937]70}
71
[11842]72/**
73 * Place an incoming function call in the queue for processing.
74 */
[7801]75void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID)
[7495]76{
[11071]77  FunctionCallManager::sIncomingFunctionCallBuffer_.emplace_back(fctCall, std::make_pair(minGamestateID, peerID));
[7495]78}
[2937]79
[11842]80/**
81 * Process queue of incoming function calls.
82 */
[7495]83void FunctionCallManager::processBufferedFunctionCalls()
84{
[11071]85  std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t>>>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
[11842]86  while( it != FunctionCallManager::sIncomingFunctionCallBuffer_.end() )
[7495]87  {
[8403]88    OrxAssert( Host::getActiveInstance(), "No Host class existing" );
89    if( it->second.first <= Host::getActiveInstance()->getLastReceivedGamestateID(it->second.second) && it->first.execute() )
[11784]90      FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it++);
[7495]91    else
[7801]92    {
[7495]93      ++it;
[7801]94    }
[7495]95  }
96}
97
98
[2937]99} //namespace orxonox
Note: See TracBrowser for help on using the repository browser.