[1701] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Oliver Scheuss, (C) 2008 |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[2087] | 29 | |
---|
| 30 | #ifndef NETWORK_PACKETGAMESTATE_H |
---|
| 31 | #define NETWORK_PACKETGAMESTATE_H |
---|
| 32 | |
---|
[2371] | 33 | #include "network/NetworkPrereqs.h" |
---|
[2087] | 34 | |
---|
[1710] | 35 | #include "Packet.h" |
---|
[2371] | 36 | #include "network/TrafficControl.h" |
---|
| 37 | #include "core/CoreIncludes.h" |
---|
[1907] | 38 | #include <map> |
---|
[2371] | 39 | #include <list> |
---|
[1751] | 40 | #ifndef NDEBUG |
---|
| 41 | #include "util/CRC32.h" |
---|
| 42 | #endif |
---|
[1701] | 43 | |
---|
[2171] | 44 | namespace orxonox { |
---|
[1701] | 45 | |
---|
| 46 | namespace packet { |
---|
[1747] | 47 | |
---|
[2655] | 48 | class _NetworkExport GamestateHeader{ |
---|
| 49 | public: |
---|
| 50 | GamestateHeader(uint8_t *data){ data_ = data; *(uint32_t*)data_ = ENUM::Gamestate; } |
---|
| 51 | GamestateHeader(uint8_t *data, GamestateHeader* h) |
---|
| 52 | { data_=data; memcpy(data_, h->data_, getSize()); } |
---|
| 53 | static inline uint32_t getSize() |
---|
| 54 | { return 21; } |
---|
[2575] | 55 | |
---|
[2655] | 56 | inline int32_t getID() const |
---|
| 57 | { return *(int32_t*)(data_+4); } |
---|
| 58 | inline void setID(int32_t id) |
---|
| 59 | { *(int32_t*)(data_+4) = id; } |
---|
| 60 | |
---|
| 61 | inline int32_t getBaseID() const |
---|
| 62 | { return *(int32_t*)(data_+8); } |
---|
| 63 | inline void setBaseID(int32_t id) |
---|
| 64 | { *(int32_t*)(data_+8) = id; } |
---|
| 65 | |
---|
| 66 | inline uint32_t getDataSize() const |
---|
| 67 | { return *(uint32_t*)(data_+12); } |
---|
| 68 | inline void setDataSize(uint32_t size) |
---|
| 69 | { *(uint32_t*)(data_+12) = size; } |
---|
| 70 | |
---|
| 71 | inline uint32_t getCompSize() const |
---|
| 72 | { return *(uint32_t*)(data_+16); } |
---|
| 73 | inline void setCompSize(uint32_t size) |
---|
| 74 | { *(uint32_t*)(data_+16) = size; } |
---|
| 75 | |
---|
| 76 | inline bool isDiffed() const |
---|
| 77 | { return *(int8_t*)(data_+20) & 0x1; } |
---|
| 78 | inline void setDiffed(bool b) |
---|
| 79 | { *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); } |
---|
| 80 | |
---|
| 81 | inline bool isComplete() const |
---|
| 82 | { return *(int8_t*)(data_+20) & 0x2; } |
---|
| 83 | inline void setComplete(bool b) |
---|
| 84 | { *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); } |
---|
| 85 | |
---|
| 86 | inline bool isCompressed() const |
---|
| 87 | { return *(int8_t*)(data_+20) & 0x4; } |
---|
| 88 | inline void setCompressed(bool b) |
---|
| 89 | { *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); } |
---|
| 90 | |
---|
| 91 | inline void operator=(GamestateHeader& h) |
---|
| 92 | { memcpy( data_, h.data_, getSize()); } |
---|
| 93 | private: |
---|
| 94 | uint8_t *data_; |
---|
| 95 | //#define GAMESTATE_START(data) (data + sizeof(GamestateHeader)) |
---|
| 96 | //#define GAMESTATE_HEADER(data) ((GamestateHeader *)data) |
---|
| 97 | //#define HEADER GAMESTATE_HEADER(data_) |
---|
| 98 | |
---|
[1701] | 99 | }; |
---|
| 100 | |
---|
| 101 | /** |
---|
[1907] | 102 | @author Oliver Scheuss |
---|
[1701] | 103 | */ |
---|
[2087] | 104 | class _NetworkExport Gamestate: public Packet{ |
---|
[1701] | 105 | public: |
---|
| 106 | Gamestate(); |
---|
[1907] | 107 | Gamestate(uint8_t *data, unsigned int clientID); |
---|
| 108 | Gamestate(uint8_t *data); |
---|
[1747] | 109 | |
---|
[1701] | 110 | ~Gamestate(); |
---|
[1747] | 111 | |
---|
[2171] | 112 | bool collectData(int id, uint8_t mode=0x0); |
---|
| 113 | bool spreadData( uint8_t mode=0x0); |
---|
[2655] | 114 | inline int32_t getID() const { return header_->getID(); } |
---|
| 115 | inline bool isDiffed() const { return header_->isDiffed(); } |
---|
| 116 | inline bool isCompressed() const { return header_->isCompressed(); } |
---|
| 117 | inline int32_t getBaseID() const { return header_->getBaseID(); } |
---|
[1705] | 118 | Gamestate *diff(Gamestate *base); |
---|
| 119 | Gamestate *undiff(Gamestate *base); |
---|
[2371] | 120 | Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); |
---|
[1705] | 121 | bool compressData(); |
---|
| 122 | bool decompressData(); |
---|
[1747] | 123 | |
---|
[1711] | 124 | // Packet functions |
---|
[1907] | 125 | private: |
---|
[2371] | 126 | virtual uint32_t getSize() const; |
---|
[2575] | 127 | virtual inline bool process(); |
---|
[1701] | 128 | |
---|
[1751] | 129 | bool operator ==(packet::Gamestate gs); |
---|
[1701] | 130 | private: |
---|
[2371] | 131 | uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0); |
---|
| 132 | std::list<obj> dataMap_; |
---|
[2655] | 133 | GamestateHeader* header_; |
---|
[1701] | 134 | }; |
---|
| 135 | |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | #endif |
---|