Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/packet/Gamestate.h @ 3198

Last change on this file since 3198 was 3198, checked in by scheusso, 15 years ago

merged netp4 back to trunk

  • Property svn:eol-style set to native
File size: 4.3 KB
RevLine 
[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
30#ifndef NETWORK_PACKETGAMESTATE_H
31#define NETWORK_PACKETGAMESTATE_H
32
[2662]33#include "network/NetworkPrereqs.h"
[2087]34
[1710]35#include "Packet.h"
[2662]36#include "network/TrafficControl.h"
[2896]37#include <string.h>
[1907]38#include <map>
[3084]39#include <vector>
[2896]40#include <cassert>
[1751]41#ifndef NDEBUG
42#include "util/CRC32.h"
43#endif
[1701]44
[2171]45namespace orxonox {
[1701]46
47namespace packet {
[1747]48
[2662]49class _NetworkExport GamestateHeader{
50  public:
51    GamestateHeader(uint8_t *data){ assert(data); data_ = data; *(uint32_t*)data_ = ENUM::Gamestate; }
52    GamestateHeader(uint8_t *data, GamestateHeader* h)
53    { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }
54    static inline uint32_t getSize()
55    { return 21; }
56
57    inline int32_t getID() const
58    { assert(data_); return *(int32_t*)(data_+4); }
59    inline void setID(int32_t id)
60    { assert(data_); *(int32_t*)(data_+4) = id; }
61
62    inline int32_t getBaseID() const
63    { assert(data_); return *(int32_t*)(data_+8); }
64    inline void setBaseID(int32_t id)
65    { assert(data_); *(int32_t*)(data_+8) = id; }
66
67    inline uint32_t getDataSize() const
68    { assert(data_); return *(uint32_t*)(data_+12); }
69    inline void setDataSize(uint32_t size)
70    { assert(data_); *(uint32_t*)(data_+12) = size; }
71
72    inline uint32_t getCompSize() const
73    { assert(data_); return *(uint32_t*)(data_+16); }
74    inline void setCompSize(uint32_t size)
75    { assert(data_); *(uint32_t*)(data_+16) = size; }
76
77    inline bool isDiffed() const
78    { assert(data_); return *(int8_t*)(data_+20) & 0x1; }
79    inline void setDiffed(bool b)
80    { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
81
82    inline bool isComplete() const
83    { assert(data_); return *(int8_t*)(data_+20) & 0x2; }
84    inline void setComplete(bool b)
85    { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
86
87    inline bool isCompressed() const
88    { assert(data_); return *(int8_t*)(data_+20) & 0x4; }
89    inline void setCompressed(bool b)
90    { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
91
92    inline void operator=(GamestateHeader& h)
93    { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }
94  private:
95    uint8_t *data_;
96
[1701]97};
98
99/**
[1907]100        @author Oliver Scheuss
[1701]101*/
[2087]102class _NetworkExport Gamestate: public Packet{
[1701]103  public:
104    Gamestate();
[1907]105    Gamestate(uint8_t *data, unsigned int clientID);
106    Gamestate(uint8_t *data);
[2662]107    Gamestate(const Gamestate& g);
[1747]108
[1701]109    ~Gamestate();
[1747]110
[2171]111    bool collectData(int id, uint8_t mode=0x0);
112    bool spreadData( uint8_t mode=0x0);
[2662]113    inline int32_t getID() const { return header_->getID(); }
114    inline bool isDiffed() const { return header_->isDiffed(); }
115    inline bool isCompressed() const { return header_->isCompressed(); }
116    inline int32_t getBaseID() const { return header_->getBaseID(); }
[1705]117    Gamestate *diff(Gamestate *base);
118    Gamestate *undiff(Gamestate *base);
[2662]119    Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
[1705]120    bool compressData();
121    bool decompressData();
[3084]122    bool operator ==(packet::Gamestate gs);
[1747]123
[1711]124    // Packet functions
[1907]125  private:
[3198]126    void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
[2662]127    virtual uint32_t getSize() const;
128    virtual inline bool process();
[1701]129
130  private:
[2662]131    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
[3084]132    std::list<obj> dataVector_;
[2662]133    GamestateHeader* header_;
[1701]134};
135
136}
137
138}
139
140#endif
Note: See TracBrowser for help on using the repository browser.