Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 10, 2010, 8:13:57 PM (15 years ago)
Author:
scheusso
Message:

some optimisations (mostly including gamestateheader inside gamestate)

File:
1 edited

Legend:

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

    r7753 r7754  
    4848class _NetworkExport GamestateHeader{
    4949  public:
    50     GamestateHeader(uint8_t *data){ assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
    51     GamestateHeader(uint8_t *data, GamestateHeader* h)
    52     { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }
     50    GamestateHeader();
     51    GamestateHeader(uint8_t* data)
     52      { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
     53    /*GamestateHeader(uint8_t* data, GamestateHeader* h)
     54      { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/
     55    void setData(uint8_t* data)
     56      { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
    5357    static inline uint32_t getSize()
    54     { return 21; }
     58      { return 21; }
    5559
    5660    inline int32_t getID() const
    57     { assert(data_); return *(int32_t*)(data_+4); }
     61      { assert(data_); return *(int32_t*)(data_+4); }
    5862    inline void setID(int32_t id)
    59     { assert(data_); *(int32_t*)(data_+4) = id; }
     63      { assert(data_); *(int32_t*)(data_+4) = id; }
    6064
    6165    inline int32_t getBaseID() const
    62     { assert(data_); return *(int32_t*)(data_+8); }
     66      { assert(data_); return *(int32_t*)(data_+8); }
    6367    inline void setBaseID(int32_t id)
    64     { assert(data_); *(int32_t*)(data_+8) = id; }
     68      { assert(data_); *(int32_t*)(data_+8) = id; }
    6569
    6670    inline uint32_t getDataSize() const
    67     { assert(data_); return *(uint32_t*)(data_+12); }
     71      { assert(data_); return *(uint32_t*)(data_+12); }
    6872    inline void setDataSize(uint32_t size)
    69     { assert(data_); *(uint32_t*)(data_+12) = size; }
     73      { assert(data_); *(uint32_t*)(data_+12) = size; }
    7074
    7175    inline uint32_t getCompSize() const
     
    7579
    7680    inline bool isDiffed() const
    77     { assert(data_); return *(int8_t*)(data_+20) & 0x1; }
     81      { assert(data_); return *(int8_t*)(data_+20) & 0x1; }
    7882    inline void setDiffed(bool b)
    79     { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
     83      { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
    8084
    8185    inline bool isComplete() const
    82     { assert(data_); return *(int8_t*)(data_+20) & 0x2; }
     86      { assert(data_); return *(int8_t*)(data_+20) & 0x2; }
    8387    inline void setComplete(bool b)
    84     { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
     88      { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
    8589
    8690    inline bool isCompressed() const
    87     { assert(data_); return *(int8_t*)(data_+20) & 0x4; }
     91      { assert(data_); return *(int8_t*)(data_+20) & 0x4; }
    8892    inline void setCompressed(bool b)
    89     { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
     93      { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
    9094
    9195    inline void operator=(GamestateHeader& h)
    92     { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }
     96      { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }
    9397  private:
    94     uint8_t *data_;
     98    uint8_t* data_;
    9599
    96100};
     
    110114    bool collectData(int id, uint8_t mode=0x0);
    111115    bool spreadData( uint8_t mode=0x0);
    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(); }
    116     inline uint32_t getDataSize() const { return header_->getDataSize(); }
     116    inline int32_t getID() const { return header_.getID(); }
     117    inline bool isDiffed() const { return header_.isDiffed(); }
     118    inline bool isCompressed() const { return header_.isCompressed(); }
     119    inline int32_t getBaseID() const { return header_.getBaseID(); }
     120    inline uint32_t getDataSize() const { return header_.getDataSize(); }
    117121    Gamestate* diffVariables(Gamestate *base);
    118122//     Gamestate* diffData(Gamestate *base);
     
    134138   
    135139    std::list<obj>          dataVector_;
    136     GamestateHeader*        header_;
     140    GamestateHeader         header_;
    137141    std::vector<uint32_t>   sizes_;
    138142    uint32_t                nrOfVariables_;
Note: See TracChangeset for help on using the changeset viewer.