Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mergeFS18/src/libraries/network/packet/Gamestate.h @ 12068

Last change on this file since 12068 was 12027, checked in by merholzl, 6 years ago

Merged Masterserver, refresh button had to be removed

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