| 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 | |
|---|
| 15 | #include "Synchronisable.h" |
|---|
| 16 | #include "orxonox/core/IdentifierIncludes.h" |
|---|
| 17 | #include "orxonox/core/Iterator.h" |
|---|
| 18 | |
|---|
| 19 | namespace network { |
|---|
| 20 | |
|---|
| 21 | /** |
|---|
| 22 | * This struct defines a gamestate: |
|---|
| 23 | * size: total size of the data in *data |
|---|
| 24 | * data: pointer to the data allocated in the memory |
|---|
| 25 | */ |
|---|
| 26 | struct GameState{ |
|---|
| 27 | int id; |
|---|
| 28 | int size; |
|---|
| 29 | unsigned char *data; |
|---|
| 30 | }; |
|---|
| 31 | |
|---|
| 32 | /** |
|---|
| 33 | * This Class implements a manager for gamestates: |
|---|
| 34 | * - creating snapshots of gamestates |
|---|
| 35 | * - writing gamestates to universe |
|---|
| 36 | * - diffing gamestates ? |
|---|
| 37 | * |
|---|
| 38 | * EN/DECODATION: |
|---|
| 39 | * a: last Gamestate a client has received |
|---|
| 40 | * b: new Gamestate |
|---|
| 41 | * x: diffed and compressed gamestate |
|---|
| 42 | * x=(a^b) |
|---|
| 43 | * b=(a^x) |
|---|
| 44 | * diff(a,diff(a,x))=x (hope this is correct) |
|---|
| 45 | * @author Oliver Scheuss |
|---|
| 46 | */ |
|---|
| 47 | class GameStateManager{ |
|---|
| 48 | public: |
|---|
| 49 | GameStateManager(); |
|---|
| 50 | ~GameStateManager(); |
|---|
| 51 | GameState getSnapshot(int id); |
|---|
| 52 | bool loadSnapshot(GameState state); |
|---|
| 53 | GameState encode(GameState a, GameState b); |
|---|
| 54 | GameState decode(GameState a, GameState x); |
|---|
| 55 | private: |
|---|
| 56 | void removeObject(orxonox::Iterator<Synchronisable> &it); |
|---|
| 57 | GameState diff(GameState a, GameState b); |
|---|
| 58 | GameState compress(GameState a); |
|---|
| 59 | GameState decompress(GameState a); |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | #endif |
|---|