[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 | // |
---|
[673] | 12 | #ifndef _GameStateManager_H__ |
---|
| 13 | #define _GameStateManager_H__ |
---|
[247] | 14 | |
---|
[436] | 15 | #include <map> |
---|
[413] | 16 | |
---|
[777] | 17 | #include "NetworkPrereqs.h" |
---|
[415] | 18 | #include "PacketTypes.h" |
---|
[332] | 19 | |
---|
[777] | 20 | namespace network |
---|
| 21 | { |
---|
[247] | 22 | |
---|
[436] | 23 | #define KEEP_GAMESTATES 20 |
---|
[247] | 24 | |
---|
[777] | 25 | /** |
---|
| 26 | * This Class implements a manager for gamestates: |
---|
| 27 | * - creating snapshots of gamestates |
---|
| 28 | * - writing gamestates to universe |
---|
| 29 | * - diffing gamestates ? |
---|
| 30 | * |
---|
| 31 | * EN/DECODATION: |
---|
| 32 | * a: last Gamestate a client has received |
---|
| 33 | * b: new Gamestate |
---|
| 34 | * x: diffed and compressed gamestate |
---|
| 35 | * x=(a^b) |
---|
| 36 | * b=(a^x) |
---|
| 37 | * diff(a,diff(a,x))=x (hope this is correct) |
---|
| 38 | * @author Oliver Scheuss |
---|
| 39 | */ |
---|
| 40 | class GameStateManager{ |
---|
| 41 | public: |
---|
| 42 | GameStateManager(ClientInformation *head); |
---|
| 43 | ~GameStateManager(); |
---|
| 44 | void update(); |
---|
| 45 | GameStateCompressed popGameState(int clientID); |
---|
| 46 | void ackGameState(int clientID, int gamestateID); |
---|
| 47 | int id; |
---|
| 48 | private: |
---|
| 49 | GameState *getSnapshot(int id); |
---|
| 50 | GameStateCompressed encode(GameState *a, GameState *b); |
---|
| 51 | GameStateCompressed encode(GameState *a); |
---|
| 52 | GameState diff(GameState *a, GameState *b); |
---|
| 53 | GameStateCompressed compress_(GameState *a); |
---|
| 54 | bool deleteUnusedGameState(int gamestateID); |
---|
[247] | 55 | |
---|
[777] | 56 | std::map<int, GameState*> gameStateMap; //map gsID to gamestate* |
---|
| 57 | std::map<int, int> gameStateUsed; // save the number of clients, that use the specific gamestate |
---|
| 58 | GameState *reference; |
---|
| 59 | ClientInformation *head_; |
---|
| 60 | }; |
---|
| 61 | |
---|
[247] | 62 | } |
---|
| 63 | |
---|
[673] | 64 | #endif /* _GameStateManager_H__ */ |
---|