[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 | |
---|
[413] | 15 | #include <vector> |
---|
| 16 | |
---|
| 17 | #include "zlib.h" |
---|
| 18 | |
---|
[332] | 19 | #include "Synchronisable.h" |
---|
| 20 | #include "orxonox/core/IdentifierIncludes.h" |
---|
| 21 | #include "orxonox/core/Iterator.h" |
---|
[413] | 22 | #include "PacketManager.h" |
---|
[332] | 23 | |
---|
[247] | 24 | namespace network { |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * This struct defines a gamestate: |
---|
| 28 | * size: total size of the data in *data |
---|
| 29 | * data: pointer to the data allocated in the memory |
---|
| 30 | */ |
---|
[332] | 31 | struct GameState{ |
---|
| 32 | int id; |
---|
[247] | 33 | int size; |
---|
| 34 | unsigned char *data; |
---|
| 35 | }; |
---|
| 36 | |
---|
| 37 | /** |
---|
[403] | 38 | * this struct defines a gamestate: |
---|
| 39 | * compsize is the size of the compressed data |
---|
| 40 | * normsize is the size of the uncompressed data |
---|
| 41 | * data are the gamestates |
---|
| 42 | */ |
---|
| 43 | struct GameStateCompressed{ |
---|
| 44 | int id; |
---|
| 45 | int compsize; |
---|
| 46 | int normsize; |
---|
| 47 | unsigned char *data; |
---|
| 48 | }; |
---|
| 49 | |
---|
| 50 | /** |
---|
[247] | 51 | * This Class implements a manager for gamestates: |
---|
| 52 | * - creating snapshots of gamestates |
---|
| 53 | * - writing gamestates to universe |
---|
| 54 | * - diffing gamestates ? |
---|
[385] | 55 | * |
---|
| 56 | * EN/DECODATION: |
---|
| 57 | * a: last Gamestate a client has received |
---|
| 58 | * b: new Gamestate |
---|
| 59 | * x: diffed and compressed gamestate |
---|
| 60 | * x=(a^b) |
---|
| 61 | * b=(a^x) |
---|
| 62 | * diff(a,diff(a,x))=x (hope this is correct) |
---|
[247] | 63 | * @author Oliver Scheuss |
---|
| 64 | */ |
---|
| 65 | class GameStateManager{ |
---|
| 66 | public: |
---|
| 67 | GameStateManager(); |
---|
| 68 | ~GameStateManager(); |
---|
[413] | 69 | void update(); |
---|
| 70 | GameStateCompressed popGameState(int clientID); |
---|
[247] | 71 | private: |
---|
[413] | 72 | GameState getSnapshot(int id); |
---|
| 73 | GameStateCompressed encode(GameState *a, GameState *b); |
---|
| 74 | GameState diff(GameState *a, GameState *b); |
---|
| 75 | GameStateCompressed compress_(GameState a); |
---|
| 76 | |
---|
| 77 | std::vector<GameState *> clientGameState; |
---|
| 78 | GameState reference; |
---|
| 79 | int id; |
---|
[247] | 80 | }; |
---|
| 81 | |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | #endif |
---|