Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7219 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

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