Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 13, 2009, 6:41:08 PM (15 years ago)
Author:
scheusso
Message:

finally got rid of these structs in our network datastream
this means we should now be able to play with gcc and msvc compiled versions together

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/network/packet/Gamestate.h

    r2575 r2655  
    4646namespace packet {
    4747
    48 #define GAMESTATE_START(data) (data + sizeof(GamestateHeader))
    49 #define GAMESTATE_HEADER(data) ((GamestateHeader *)data)
    50 #define HEADER GAMESTATE_HEADER(data_)
     48class _NetworkExport GamestateHeader{
     49  public:
     50    GamestateHeader(uint8_t *data){ data_ = data; *(uint32_t*)data_ = ENUM::Gamestate; }
     51    GamestateHeader(uint8_t *data, GamestateHeader* h)
     52      { data_=data; memcpy(data_, h->data_, getSize()); }
     53    static inline uint32_t getSize()
     54      { return 21; }
    5155
    52 struct _NetworkExport GamestateHeader{
    53   ENUM::Type packetType;
    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;
     56    inline int32_t getID() const
     57      { return *(int32_t*)(data_+4); }
     58    inline void setID(int32_t id)
     59      { *(int32_t*)(data_+4) = id; }
     60
     61    inline int32_t getBaseID() const
     62      { return *(int32_t*)(data_+8); }
     63    inline void setBaseID(int32_t id)
     64      { *(int32_t*)(data_+8) = id; }
     65
     66    inline uint32_t getDataSize() const
     67      { return *(uint32_t*)(data_+12); }
     68    inline void setDataSize(uint32_t size)
     69      { *(uint32_t*)(data_+12) = size; }
     70
     71    inline uint32_t getCompSize() const
     72      { return *(uint32_t*)(data_+16); }
     73    inline void setCompSize(uint32_t size)
     74      { *(uint32_t*)(data_+16) = size; }
     75
     76    inline bool isDiffed() const
     77      { return *(int8_t*)(data_+20) & 0x1; }
     78    inline void setDiffed(bool b)
     79      { *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
     80
     81    inline bool isComplete() const
     82      { return *(int8_t*)(data_+20) & 0x2; }
     83    inline void setComplete(bool b)
     84      { *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
     85
     86    inline bool isCompressed() const
     87      { return *(int8_t*)(data_+20) & 0x4; }
     88    inline void setCompressed(bool b)
     89      { *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
     90
     91    inline void operator=(GamestateHeader& h)
     92      { memcpy( data_, h.data_, getSize()); }
     93  private:
     94    uint8_t *data_;
     95//#define GAMESTATE_START(data) (data + sizeof(GamestateHeader))
     96//#define GAMESTATE_HEADER(data) ((GamestateHeader *)data)
     97//#define HEADER GAMESTATE_HEADER(data_)
     98
    6199};
    62100
     
    74112    bool collectData(int id, uint8_t mode=0x0);
    75113    bool spreadData( uint8_t mode=0x0);
    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; }
     114    inline int32_t getID() const { return header_->getID(); }
     115    inline bool isDiffed() const { return header_->isDiffed(); }
     116    inline bool isCompressed() const { return header_->isCompressed(); }
     117    inline int32_t getBaseID() const { return header_->getBaseID(); }
    80118    Gamestate *diff(Gamestate *base);
    81119    Gamestate *undiff(Gamestate *base);
     
    93131    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
    94132    std::list<obj> dataMap_;
     133    GamestateHeader* header_;
    95134};
    96135
Note: See TracChangeset for help on using the changeset viewer.