Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/network/GamestateManager.h @ 11740

Last change on this file since 11740 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
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
50namespace orxonox
51{
52
53  const int KEEP_GAMESTATES = 10;
54
55  /**
56  * This Class implements a manager for gamestates:
57  * - creating snapshots of gamestates
58  * - writing gamestates to universe
59  * - diffing gamestates
60  * EN/DECODATION:
61  * a: last Gamestate a client has received
62  * b: new Gamestate
63  * x: diffed and compressed gamestate
64  * x=(a^b)
65  * b=(a^x)
66  * diff(a,diff(a,x))=x (hope this is correct)
67  * @author Oliver Scheuss
68  */
69  class _NetworkExport GamestateManager: public GamestateHandler
70  {
71    struct peerInfo
72    {
73      uint32_t  peerID;
74      uint32_t  lastReceivedGamestateID;  //!< id of the last gamestate which was received (and processed) from the peer
75      uint32_t  lastAckedGamestateID;     //!< id of the last gamestate on which we received an ack from the peer
76      bool      isSynched;
77      std::map< uint32_t, packet::Gamestate* > gamestates;
78    };
79
80  public:
81
82    GamestateManager();
83    ~GamestateManager();
84
85    virtual bool      addGamestate(packet::Gamestate *gs, unsigned int peerID) override;
86    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int peerID) override;
87    virtual uint32_t  getLastReceivedGamestateID( unsigned int peerID ) override;
88    virtual uint32_t  getCurrentGamestateID() override{ if( currentGamestate_) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; }
89
90    bool processGamestates();
91    bool sendAck(unsigned int gamestateID, uint32_t peerID);
92    bool update();
93    std::vector<packet::Gamestate*> getGamestates();
94    void finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
95
96    bool getSnapshot();
97
98    void addPeer( uint32_t peerID );
99    void setSynched( uint32_t peerID )
100      { assert(peerMap_.find(peerID)!=peerMap_.end()); peerMap_[peerID].isSynched = true; }
101    void removePeer( uint32_t peerID );
102    bool hasPeers(){ return this->peerMap_.size()!=0; }
103//     void removeClient(ClientInformation *client);
104  protected:
105    virtual bool sendPacket( packet::Packet* packet ) = 0;
106  private:
107    bool processGamestate(packet::Gamestate *gs);
108
109//     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*>> gamestateMap_;
110    std::map<unsigned int, packet::Gamestate*> gamestateQueue;
111//     std::map<unsigned int, uint32_t> lastProcessedGamestateID_;
112    std::map<uint32_t, peerInfo> peerMap_;
113    packet::Gamestate* currentGamestate_;
114//     TrafficControl *trafficControl_;
115    unsigned int id_;
116//     boost::mutex* threadMutex_;
117    ThreadPool*   /*thread*/Pool_;
118  };
119
120}
121
122#endif /* _GameStateManager_H__ */
Note: See TracBrowser for help on using the repository browser.