Orxonox  0.0.5 Codename: Arcturus
GamestateManager.h
Go to the documentation of this file.
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
24  * Co-authors:
25  * ...
26  *
27  */
28 
29 //
30 // C++ Interface: GamestateManager
31 //
32 // Description:
33 //
34 //
35 // Author: Oliver Scheuss, (C) 2007
36 //
37 // Copyright: See COPYING file that comes with this distribution
38 //
39 //
40 #ifndef _GamestateManager_H__
41 #define _GamestateManager_H__
42 
43 #include "NetworkPrereqs.h"
44 
45 #include <map>
46 #include "GamestateHandler.h"
47 #include "core/CorePrereqs.h"
48 #include "packet/Gamestate.h"
49 
50 namespace orxonox
51 {
52 
53  const int KEEP_GAMESTATES = 10;
54 
73  {
74  struct peerInfo
75  {
76  uint32_t peerID;
79  bool isSynched;
80  std::map<uint32_t, packet::Gamestate*> gamestates;
81  };
82 
83  public:
84 
87 
88  virtual bool addGamestate(packet::Gamestate *gs, unsigned int peerID) override;
89  virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID) override;
90  virtual uint32_t getLastReceivedGamestateID( unsigned int peerID ) override;
91  virtual uint32_t getCurrentGamestateID() override { if(currentGamestate_) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; }
92 
93  bool processGamestates();
94  bool sendAck(unsigned int gamestateID, uint32_t peerID);
95  bool update();
96  std::vector<packet::Gamestate*> getGamestates();
97  void finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
98 
99  bool getSnapshot();
100 
101  void addPeer( uint32_t peerID );
102  void setSynched( uint32_t peerID )
103  { assert(peerMap_.find(peerID) != peerMap_.end()); peerMap_[peerID].isSynched = true; }
104  void removePeer( uint32_t peerID );
105  bool hasPeers(){ return this->peerMap_.size() != 0; }
106 
107  protected:
108  virtual bool sendPacket( packet::Packet* packet ) = 0;
109 
110  private:
111  bool processGamestate(packet::Gamestate *gs);
112 
113  std::map<unsigned int, packet::Gamestate*> gamestateQueue;
114 
115  // Each peerID maps to a peerInfo struct
116  std::map<uint32_t, peerInfo> peerMap_;
117 
118  // always contains the latest gamestate
120  unsigned int id_;
122  };
123 
124 }
125 
126 #endif /* _GameStateManager_H__ */
Shared library macros, enums, constants and forward declarations for the network library ...
bool isSynched
Definition: GamestateManager.h:79
virtual uint32_t getCurrentGamestateID() override
Definition: GamestateManager.h:91
Shared library macros, enums, constants and forward declarations for the core library ...
uint32_t lastReceivedGamestateID
id of the last gamestate which was received (and processed) from the peer
Definition: GamestateManager.h:77
ThreadPool * Pool_
Definition: GamestateManager.h:121
Definition: GamestateManager.h:74
std::map< uint32_t, peerInfo > peerMap_
Definition: GamestateManager.h:116
This Class implements a manager for gamestates:
Definition: GamestateManager.h:72
Definition: Gamestate.h:109
std::map< unsigned int, packet::Gamestate * > gamestateQueue
Definition: GamestateManager.h:113
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
#define _NetworkExport
Definition: NetworkPrereqs.h:59
void setSynched(uint32_t peerID)
Definition: GamestateManager.h:102
Definition: Packet.h:61
const int KEEP_GAMESTATES
Definition: GamestateManager.h:53
uint32_t peerID
Definition: GamestateManager.h:76
Definition: ThreadPool.h:48
uint32_t lastAckedGamestateID
id of the last gamestate on which we received an ack from the peer
Definition: GamestateManager.h:78
bool hasPeers()
Definition: GamestateManager.h:105
An interface for any class that wants to handle gamestates.
Definition: GamestateHandler.h:42
packet::Gamestate * currentGamestate_
Definition: GamestateManager.h:119
static constexpr unsigned int GAMESTATEID_INITIAL
Definition: NetworkPrereqs.h:69
std::map< uint32_t, packet::Gamestate * > gamestates
Definition: GamestateManager.h:80
unsigned int id_
Definition: GamestateManager.h:120