Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 22, 2010, 7:24:24 PM (13 years ago)
Author:
dafrick
Message:

Merging presentation2 branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/network/packet/Gamestate.h

    r7163 r7801  
    4242#include "Packet.h"
    4343
    44 namespace orxonox {
     44namespace orxonox
     45{
    4546
    46 namespace packet {
     47namespace packet
     48{
     49   
     50static const uint8_t GAMESTATE_MODE_SERVER = 0x1;
     51static const uint8_t GAMESTATE_MODE_CLIENT = 0x2;
    4752
    48 class _NetworkExport GamestateHeader{
     53class _NetworkExport GamestateHeader
     54{
    4955  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()); }
     56    GamestateHeader(){ data_=0; }
     57    GamestateHeader(uint8_t* data)
     58      { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
     59    /*GamestateHeader(uint8_t* data, GamestateHeader* h)
     60      { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/
     61    void setData(uint8_t* data)
     62      { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
    5363    static inline uint32_t getSize()
    54     { return 21; }
     64      { return 21; }
    5565
    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; }
     66    inline uint32_t getID() const
     67      { assert(data_); return *(uint32_t*)(data_+4); }
     68    inline void setID(uint32_t id)
     69      { assert(data_); *(uint32_t*)(data_+4) = id; }
    6070
    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; }
     71    inline uint32_t getBaseID() const
     72      { assert(data_); return *(uint32_t*)(data_+8); }
     73    inline void setBaseID(uint32_t id)
     74      { assert(data_); *(uint32_t*)(data_+8) = id; }
    6575
    6676    inline uint32_t getDataSize() const
    67     { assert(data_); return *(uint32_t*)(data_+12); }
     77      { assert(data_); return *(uint32_t*)(data_+12); }
    6878    inline void setDataSize(uint32_t size)
    69     { assert(data_); *(uint32_t*)(data_+12) = size; }
     79      { assert(data_); *(uint32_t*)(data_+12) = size; }
    7080
    7181    inline uint32_t getCompSize() const
     
    7585
    7686    inline bool isDiffed() const
    77     { assert(data_); return *(int8_t*)(data_+20) & 0x1; }
     87      { assert(data_); return *(int8_t*)(data_+20) & 0x1; }
    7888    inline void setDiffed(bool b)
    79     { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
     89      { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
    8090
    8191    inline bool isComplete() const
    82     { assert(data_); return *(int8_t*)(data_+20) & 0x2; }
     92      { assert(data_); return *(int8_t*)(data_+20) & 0x2; }
    8393    inline void setComplete(bool b)
    84     { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
     94      { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
    8595
    8696    inline bool isCompressed() const
    87     { assert(data_); return *(int8_t*)(data_+20) & 0x4; }
     97      { assert(data_); return *(int8_t*)(data_+20) & 0x4; }
    8898    inline void setCompressed(bool b)
    89     { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
     99      { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
    90100
    91101    inline void operator=(GamestateHeader& h)
    92     { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }
     102      { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }
    93103  private:
    94     uint8_t *data_;
     104    uint8_t* data_;
    95105
    96106};
     
    99109    @author Oliver Scheuss
    100110*/
    101 class _NetworkExport Gamestate: public Packet{
     111class _NetworkExport Gamestate: public Packet
     112{
    102113  public:
    103114    Gamestate();
     
    110121    bool collectData(int id, uint8_t mode=0x0);
    111122    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(); }
     123    inline uint32_t getID() const { return header_.getID(); }
     124    inline bool isDiffed() const { return header_.isDiffed(); }
     125    inline bool isCompressed() const { return header_.isCompressed(); }
     126    inline int32_t getBaseID() const { return header_.getBaseID(); }
     127    inline uint32_t getDataSize() const { return header_.getDataSize(); }
    117128    Gamestate* diffVariables(Gamestate *base);
    118     Gamestate* diffData(Gamestate *base);
    119     Gamestate *undiff(Gamestate *base);
    120     Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
     129//     Gamestate* diffData(Gamestate *base);
     130//     Gamestate *undiff(Gamestate *base);
     131//     Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
    121132    bool compressData();
    122133    bool decompressData();
     
    125136    // Packet functions
    126137  private:
    127     void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
    128     inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );
     138//     void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
     139//     inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );
    129140    virtual uint32_t getSize() const;
    130     virtual inline bool process();
    131     uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
     141    virtual bool process(orxonox::Host* host);
     142    uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0);
     143//     inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
     144//     inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
    132145   
    133146    std::list<obj>          dataVector_;
    134     GamestateHeader*        header_;
     147    GamestateHeader         header_;
    135148    std::vector<uint32_t>   sizes_;
    136149    uint32_t                nrOfVariables_;
Note: See TracChangeset for help on using the changeset viewer.