| [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(); |
|---|
| [984] | 44 | //#### ADDED FOR TESTING PURPOSE #### |
|---|
| 45 | GameStateCompressed* testCompress( GameState* g ); |
|---|
| 46 | GameState* testDiff( GameState* a, GameState* b ); |
|---|
| 47 | //#### END TESTING PURPOSE #### |
|---|
| [777] | 48 | void update(); |
|---|
| [894] | 49 | GameStateCompressed *popGameState(int clientID); |
|---|
| [777] | 50 | void ackGameState(int clientID, int gamestateID); |
|---|
| 51 | int id; |
|---|
| 52 | private: |
|---|
| [1007] | 53 | void cleanup(); // "garbage handler" |
|---|
| [777] | 54 | GameState *getSnapshot(int id); |
|---|
| [891] | 55 | GameStateCompressed *encode(GameState *a, GameState *b); |
|---|
| 56 | GameStateCompressed *encode(GameState *a); |
|---|
| 57 | GameState *diff(GameState *a, GameState *b); |
|---|
| 58 | GameStateCompressed *compress_(GameState *a); |
|---|
| [777] | 59 | bool deleteUnusedGameState(int gamestateID); |
|---|
| [247] | 60 | |
|---|
| [777] | 61 | std::map<int, GameState*> gameStateMap; //map gsID to gamestate* |
|---|
| 62 | std::map<int, int> gameStateUsed; // save the number of clients, that use the specific gamestate |
|---|
| 63 | GameState *reference; |
|---|
| 64 | ClientInformation *head_; |
|---|
| 65 | }; |
|---|
| 66 | |
|---|
| [247] | 67 | } |
|---|
| 68 | |
|---|
| [673] | 69 | #endif /* _GameStateManager_H__ */ |
|---|