[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: |
---|
[3084] | 23 | * Oliver Scheuss |
---|
[1701] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[2087] | 29 | |
---|
[3214] | 30 | #ifndef _Gamestate_H__ |
---|
| 31 | #define _Gamestate_H__ |
---|
[2087] | 32 | |
---|
[2662] | 33 | #include "network/NetworkPrereqs.h" |
---|
[2087] | 34 | |
---|
[2896] | 35 | #include <cassert> |
---|
[3214] | 36 | #include <cstring> |
---|
| 37 | #include <list> |
---|
[7163] | 38 | #include <vector> |
---|
[3214] | 39 | |
---|
[1751] | 40 | #include "util/CRC32.h" |
---|
[3214] | 41 | #include "network/TrafficControl.h" |
---|
| 42 | #include "Packet.h" |
---|
[1701] | 43 | |
---|
[2171] | 44 | namespace orxonox { |
---|
[1701] | 45 | |
---|
| 46 | namespace packet { |
---|
[1747] | 47 | |
---|
[2662] | 48 | class _NetworkExport GamestateHeader{ |
---|
| 49 | public: |
---|
[7758] | 50 | GamestateHeader(){ data_=0; } |
---|
| 51 | GamestateHeader(uint8_t* data) |
---|
| 52 | { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; } |
---|
| 53 | /*GamestateHeader(uint8_t* data, GamestateHeader* h) |
---|
| 54 | { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/ |
---|
| 55 | void setData(uint8_t* data) |
---|
| 56 | { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; } |
---|
[2662] | 57 | static inline uint32_t getSize() |
---|
[7758] | 58 | { return 21; } |
---|
[2662] | 59 | |
---|
| 60 | inline int32_t getID() const |
---|
[7758] | 61 | { assert(data_); return *(int32_t*)(data_+4); } |
---|
[2662] | 62 | inline void setID(int32_t id) |
---|
[7758] | 63 | { assert(data_); *(int32_t*)(data_+4) = id; } |
---|
[2662] | 64 | |
---|
| 65 | inline int32_t getBaseID() const |
---|
[7758] | 66 | { assert(data_); return *(int32_t*)(data_+8); } |
---|
[2662] | 67 | inline void setBaseID(int32_t id) |
---|
[7758] | 68 | { assert(data_); *(int32_t*)(data_+8) = id; } |
---|
[2662] | 69 | |
---|
| 70 | inline uint32_t getDataSize() const |
---|
[7758] | 71 | { assert(data_); return *(uint32_t*)(data_+12); } |
---|
[2662] | 72 | inline void setDataSize(uint32_t size) |
---|
[7758] | 73 | { assert(data_); *(uint32_t*)(data_+12) = size; } |
---|
[2662] | 74 | |
---|
| 75 | inline uint32_t getCompSize() const |
---|
| 76 | { assert(data_); return *(uint32_t*)(data_+16); } |
---|
| 77 | inline void setCompSize(uint32_t size) |
---|
| 78 | { assert(data_); *(uint32_t*)(data_+16) = size; } |
---|
| 79 | |
---|
| 80 | inline bool isDiffed() const |
---|
[7758] | 81 | { assert(data_); return *(int8_t*)(data_+20) & 0x1; } |
---|
[2662] | 82 | inline void setDiffed(bool b) |
---|
[7758] | 83 | { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); } |
---|
[2662] | 84 | |
---|
| 85 | inline bool isComplete() const |
---|
[7758] | 86 | { assert(data_); return *(int8_t*)(data_+20) & 0x2; } |
---|
[2662] | 87 | inline void setComplete(bool b) |
---|
[7758] | 88 | { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); } |
---|
[2662] | 89 | |
---|
| 90 | inline bool isCompressed() const |
---|
[7758] | 91 | { assert(data_); return *(int8_t*)(data_+20) & 0x4; } |
---|
[2662] | 92 | inline void setCompressed(bool b) |
---|
[7758] | 93 | { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); } |
---|
[2662] | 94 | |
---|
| 95 | inline void operator=(GamestateHeader& h) |
---|
[7758] | 96 | { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); } |
---|
[2662] | 97 | private: |
---|
[7758] | 98 | uint8_t* data_; |
---|
[2662] | 99 | |
---|
[1701] | 100 | }; |
---|
| 101 | |
---|
| 102 | /** |
---|
[6073] | 103 | @author Oliver Scheuss |
---|
[1701] | 104 | */ |
---|
[2087] | 105 | class _NetworkExport Gamestate: public Packet{ |
---|
[1701] | 106 | public: |
---|
| 107 | Gamestate(); |
---|
[1907] | 108 | Gamestate(uint8_t *data, unsigned int clientID); |
---|
| 109 | Gamestate(uint8_t *data); |
---|
[2662] | 110 | Gamestate(const Gamestate& g); |
---|
[1747] | 111 | |
---|
[1701] | 112 | ~Gamestate(); |
---|
[1747] | 113 | |
---|
[2171] | 114 | bool collectData(int id, uint8_t mode=0x0); |
---|
| 115 | bool spreadData( uint8_t mode=0x0); |
---|
[7758] | 116 | inline int32_t getID() const { return header_.getID(); } |
---|
| 117 | inline bool isDiffed() const { return header_.isDiffed(); } |
---|
| 118 | inline bool isCompressed() const { return header_.isCompressed(); } |
---|
| 119 | inline int32_t getBaseID() const { return header_.getBaseID(); } |
---|
| 120 | inline uint32_t getDataSize() const { return header_.getDataSize(); } |
---|
[7163] | 121 | Gamestate* diffVariables(Gamestate *base); |
---|
[7758] | 122 | // Gamestate* diffData(Gamestate *base); |
---|
| 123 | // Gamestate *undiff(Gamestate *base); |
---|
| 124 | // Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); |
---|
[1705] | 125 | bool compressData(); |
---|
| 126 | bool decompressData(); |
---|
[3084] | 127 | bool operator ==(packet::Gamestate gs); |
---|
[1747] | 128 | |
---|
[1711] | 129 | // Packet functions |
---|
[1907] | 130 | private: |
---|
[7758] | 131 | // void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength); |
---|
| 132 | // inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 ); |
---|
[2662] | 133 | virtual uint32_t getSize() const; |
---|
| 134 | virtual inline bool process(); |
---|
| 135 | uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0); |
---|
[7758] | 136 | // inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); |
---|
| 137 | // inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); |
---|
[7163] | 138 | |
---|
| 139 | std::list<obj> dataVector_; |
---|
[7758] | 140 | GamestateHeader header_; |
---|
[7163] | 141 | std::vector<uint32_t> sizes_; |
---|
| 142 | uint32_t nrOfVariables_; |
---|
[1701] | 143 | }; |
---|
| 144 | |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | } |
---|
| 148 | |
---|
[3214] | 149 | #endif /* _Gamestate_H__ */ |
---|