[247] | 1 | // |
---|
| 2 | // C++ Interface: GameStateManager |
---|
| 3 | // |
---|
| 4 | // Description: |
---|
| 5 | // |
---|
| 6 | // |
---|
| 7 | // Author: Oliver Scheuss, (C) 2007 |
---|
| 8 | // |
---|
| 9 | // Copyright: See COPYING file that comes with this distribution |
---|
| 10 | // |
---|
| 11 | // |
---|
| 12 | #ifndef NETWORK_GAMESTATEMANAGER_H |
---|
| 13 | #define NETWORK_GAMESTATEMANAGER_H |
---|
| 14 | |
---|
[436] | 15 | #include <map> |
---|
[413] | 16 | |
---|
| 17 | #include "zlib.h" |
---|
| 18 | |
---|
[436] | 19 | #include "ClientInformation.h" |
---|
[332] | 20 | #include "Synchronisable.h" |
---|
[496] | 21 | #include "orxonox/core/CoreIncludes.h" |
---|
[332] | 22 | #include "orxonox/core/Iterator.h" |
---|
[415] | 23 | #include "PacketTypes.h" |
---|
[332] | 24 | |
---|
[247] | 25 | namespace network { |
---|
| 26 | |
---|
[436] | 27 | #define KEEP_GAMESTATES 20 |
---|
[247] | 28 | |
---|
[403] | 29 | /** |
---|
[247] | 30 | * This Class implements a manager for gamestates: |
---|
| 31 | * - creating snapshots of gamestates |
---|
| 32 | * - writing gamestates to universe |
---|
| 33 | * - diffing gamestates ? |
---|
[385] | 34 | * |
---|
| 35 | * EN/DECODATION: |
---|
| 36 | * a: last Gamestate a client has received |
---|
| 37 | * b: new Gamestate |
---|
| 38 | * x: diffed and compressed gamestate |
---|
| 39 | * x=(a^b) |
---|
| 40 | * b=(a^x) |
---|
| 41 | * diff(a,diff(a,x))=x (hope this is correct) |
---|
[247] | 42 | * @author Oliver Scheuss |
---|
| 43 | */ |
---|
| 44 | class GameStateManager{ |
---|
| 45 | public: |
---|
[436] | 46 | GameStateManager(ClientInformation *head); |
---|
[247] | 47 | ~GameStateManager(); |
---|
[413] | 48 | void update(); |
---|
| 49 | GameStateCompressed popGameState(int clientID); |
---|
[422] | 50 | void ackGameState(int clientID, int gamestateID); |
---|
[247] | 51 | private: |
---|
[422] | 52 | GameState *getSnapshot(int id); |
---|
[413] | 53 | GameStateCompressed encode(GameState *a, GameState *b); |
---|
[436] | 54 | GameStateCompressed encode(GameState *a); |
---|
[413] | 55 | GameState diff(GameState *a, GameState *b); |
---|
[436] | 56 | GameStateCompressed compress_(GameState *a); |
---|
| 57 | bool deleteUnusedGameState(int gamestateID); |
---|
[413] | 58 | |
---|
[436] | 59 | std::map<int, GameState*> gameStateMap; //map gsID to gamestate* |
---|
| 60 | std::map<int, int> gameStateUsed; // save the number of clients, that use the specific gamestate |
---|
[422] | 61 | GameState *reference; |
---|
[413] | 62 | int id; |
---|
[436] | 63 | ClientInformation *head_; |
---|
[247] | 64 | }; |
---|
| 65 | |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | #endif |
---|