| [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 | |
|---|
| 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); |
|---|
| [624] | 51 | int id; |
|---|
| [247] | 52 | private: |
|---|
| [422] | 53 | GameState *getSnapshot(int id); |
|---|
| [413] | 54 | GameStateCompressed encode(GameState *a, GameState *b); |
|---|
| [436] | 55 | GameStateCompressed encode(GameState *a); |
|---|
| [413] | 56 | GameState diff(GameState *a, GameState *b); |
|---|
| [436] | 57 | GameStateCompressed compress_(GameState *a); |
|---|
| 58 | bool deleteUnusedGameState(int gamestateID); |
|---|
| [413] | 59 | |
|---|
| [436] | 60 | std::map<int, GameState*> gameStateMap; //map gsID to gamestate* |
|---|
| 61 | std::map<int, int> gameStateUsed; // save the number of clients, that use the specific gamestate |
|---|
| [422] | 62 | GameState *reference; |
|---|
| [436] | 63 | ClientInformation *head_; |
|---|
| [247] | 64 | }; |
|---|
| 65 | |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| [673] | 68 | #endif /* _GameStateManager_H__ */ |
|---|