[1705] | 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: |
---|
[3084] | 23 | * Oliver Scheuss |
---|
[1705] | 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" |
---|
[3214] | 44 | |
---|
| 45 | #include <map> |
---|
[1705] | 46 | #include "GamestateHandler.h" |
---|
[3304] | 47 | #include "core/CorePrereqs.h" |
---|
[7801] | 48 | #include "packet/Gamestate.h" |
---|
| 49 | #include <boost/concept_check.hpp> |
---|
[1705] | 50 | |
---|
[2171] | 51 | namespace orxonox |
---|
[1705] | 52 | { |
---|
| 53 | |
---|
[3214] | 54 | const int KEEP_GAMESTATES = 10; |
---|
[1705] | 55 | |
---|
| 56 | /** |
---|
| 57 | * This Class implements a manager for gamestates: |
---|
| 58 | * - creating snapshots of gamestates |
---|
| 59 | * - writing gamestates to universe |
---|
| 60 | * - diffing gamestates |
---|
| 61 | * EN/DECODATION: |
---|
| 62 | * a: last Gamestate a client has received |
---|
| 63 | * b: new Gamestate |
---|
| 64 | * x: diffed and compressed gamestate |
---|
| 65 | * x=(a^b) |
---|
| 66 | * b=(a^x) |
---|
| 67 | * diff(a,diff(a,x))=x (hope this is correct) |
---|
| 68 | * @author Oliver Scheuss |
---|
| 69 | */ |
---|
[7801] | 70 | class _NetworkExport GamestateManager: public GamestateHandler |
---|
| 71 | { |
---|
| 72 | struct peerInfo |
---|
| 73 | { |
---|
| 74 | uint32_t peerID; |
---|
| 75 | uint32_t lastProcessedGamestateID; |
---|
| 76 | uint32_t lastAckedGamestateID; |
---|
| 77 | bool isSynched; |
---|
| 78 | std::map< uint32_t, packet::Gamestate* > gamestates; |
---|
| 79 | }; |
---|
| 80 | |
---|
[1705] | 81 | public: |
---|
[7801] | 82 | |
---|
[1705] | 83 | GamestateManager(); |
---|
| 84 | ~GamestateManager(); |
---|
[1740] | 85 | |
---|
[7801] | 86 | virtual bool addGamestate(packet::Gamestate *gs, unsigned int peerID); |
---|
| 87 | virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID); |
---|
| 88 | virtual uint32_t getLastProcessedGamestateID( unsigned int peerID ); |
---|
| 89 | virtual uint32_t getCurrentGamestateID(){ return currentGamestate_->getID(); } |
---|
| 90 | |
---|
[1705] | 91 | bool processGamestates(); |
---|
[7801] | 92 | bool sendAck(unsigned int gamestateID, uint32_t peerID); |
---|
[1705] | 93 | bool update(); |
---|
[7801] | 94 | std::vector<packet::Gamestate*> getGamestates(); |
---|
| 95 | void finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ); |
---|
[1705] | 96 | |
---|
| 97 | bool getSnapshot(); |
---|
[1740] | 98 | |
---|
[7801] | 99 | void addPeer( uint32_t peerID ); |
---|
| 100 | void setSynched( uint32_t peerID ) |
---|
| 101 | { assert(peerMap_.find(peerID)!=peerMap_.end()); peerMap_[peerID].isSynched = true; } |
---|
| 102 | void removePeer( uint32_t peerID ); |
---|
| 103 | // void removeClient(ClientInformation *client); |
---|
| 104 | protected: |
---|
| 105 | virtual bool sendPacket( packet::Packet* packet ) = 0; |
---|
[3304] | 106 | private: |
---|
[1712] | 107 | bool processGamestate(packet::Gamestate *gs); |
---|
[1740] | 108 | |
---|
[7801] | 109 | // std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_; |
---|
[2087] | 110 | std::map<unsigned int, packet::Gamestate*> gamestateQueue; |
---|
[7801] | 111 | // std::map<unsigned int, uint32_t> lastProcessedGamestateID_; |
---|
| 112 | std::map<uint32_t, peerInfo> peerMap_; |
---|
| 113 | packet::Gamestate* currentGamestate_; |
---|
| 114 | // TrafficControl *trafficControl_; |
---|
[2087] | 115 | unsigned int id_; |
---|
[3304] | 116 | // boost::mutex* threadMutex_; |
---|
| 117 | ThreadPool* /*thread*/Pool_; |
---|
[1705] | 118 | }; |
---|
| 119 | |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | #endif /* _GameStateManager_H__ */ |
---|