Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/network/packet/Gamestate.h @ 2575

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

-performance/memory optimisations in gamestate and synchronisable
-enhancement of portability (gcc↔msvc)

  • Property svn:eol-style set to native
File size: 2.7 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:
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]44namespace orxonox {
[1701]45
46namespace packet {
[1747]47
[2575]48#define GAMESTATE_START(data) (data + sizeof(GamestateHeader))
49#define GAMESTATE_HEADER(data) ((GamestateHeader *)data)
50#define HEADER GAMESTATE_HEADER(data_)
51
[2087]52struct _NetworkExport GamestateHeader{
[1710]53  ENUM::Type packetType;
[1907]54  int32_t id; // id of the gamestate
55  uint32_t compsize;
56  uint32_t datasize;
57  int32_t base_id; // id of the base-gamestate diffed from
58  bool diffed:1; // wheter diffed or not
59  bool complete:1; // wheter it is a complete gamestate or only partial
60  bool compressed:1;
[1701]61};
62
63/**
[1907]64        @author Oliver Scheuss
[1701]65*/
[2087]66class _NetworkExport Gamestate: public Packet{
[1701]67  public:
68    Gamestate();
[1907]69    Gamestate(uint8_t *data, unsigned int clientID);
70    Gamestate(uint8_t *data);
[1747]71
[1701]72    ~Gamestate();
[1747]73
[2171]74    bool collectData(int id, uint8_t mode=0x0);
75    bool spreadData( uint8_t mode=0x0);
[2575]76    inline int32_t getID() const { return HEADER->id; }
77    inline bool isDiffed() const { return HEADER->diffed; }
78    inline bool isCompressed() const { return HEADER->compressed; }
79    inline int32_t getBaseID() const { return HEADER->base_id; }
[1705]80    Gamestate *diff(Gamestate *base);
81    Gamestate *undiff(Gamestate *base);
[2371]82    Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
[1705]83    bool compressData();
84    bool decompressData();
[1747]85
[1711]86    // Packet functions
[1907]87  private:
[2371]88    virtual uint32_t getSize() const;
[2575]89    virtual inline bool process();
[1701]90
[1751]91    bool operator ==(packet::Gamestate gs);
[1701]92  private:
[2371]93    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
94    std::list<obj> dataMap_;
[1701]95};
96
97}
98
99}
100
101#endif
Note: See TracBrowser for help on using the repository browser.