Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2010, 11:49:48 AM (14 years ago)
Author:
scheusso
Message:

changed diff behaviour in order to reduce datasize before and after compress
this reduces time needed for gamestate diff and compress about 50%

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network2/src/libraries/network/synchronisable/Synchronisable.h

    r6417 r6449  
    7171   * in an emulated bitset.
    7272   * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
    73    * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 0
     73   * Bit 32 is a bool and defines whether the variables are stored in diff mode
    7474   * Byte 5 to 8: objectID_
    7575   * Byte 9 to 12: classID_
     
    8888      inline void setDataSize(uint32_t size)
    8989        { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); }
    90       inline bool isDataAvailable() const
     90      inline bool isDiffed() const
    9191        { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; }
    92       inline void setDataAvailable( bool b)
     92      inline void setDiffed( bool b)
    9393        { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }
    9494      inline uint32_t getObjectID() const
     
    108108  };
    109109
     110    /**
     111   * @brief: stores information about a Synchronisable (light version)
     112   *
     113   * This class stores the information about a Synchronisable (objectID_, dataSize)
     114   * in an emulated bitset.
     115   * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
     116   * Bit 32 is a bool and defines whether the variables are stored in diff mode
     117   * Byte 5 to 8: objectID_
     118   */
     119  class _NetworkExport SynchronisableHeaderLight{
     120    private:
     121      uint8_t *data_;
     122    public:
     123      SynchronisableHeader(uint8_t* data)
     124        { data_ = data; }
     125      inline static uint32_t getSize()
     126        { return 16; }
     127      inline uint32_t getDataSize() const
     128        { return (*(uint32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits
     129      inline void setDataSize(uint32_t size)
     130        { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); }
     131      inline bool isDiffed() const
     132        { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; }
     133      inline void setDiffed( bool b)
     134        { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }
     135      inline uint32_t getObjectID() const
     136        { return *(uint32_t*)(data_+4); }
     137      inline void setObjectID(uint32_t objectID_)
     138        { *(uint32_t*)(data_+4) = objectID_; }
     139      inline void operator=(SynchronisableHeader& h)
     140        { memcpy(data_, h.data_, getSize()); }
     141  };
    110142
    111143  /**
     
    121153    static void setClient(bool b);
    122154
    123     static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);
     155    static Synchronisable *fabricate(uint8_t*& mem, bool diffed, uint8_t mode=0x0);
    124156    static bool deleteObject(uint32_t objectID_);
    125157    static Synchronisable *getSynchronisable(uint32_t objectID_);
     
    134166
    135167    void setSyncMode(uint8_t mode);
     168   
     169    inline uint32_t getNrOfVariables(){ return this->syncList_.size(); }
     170    inline uint32_t getVarSize( uint32_t ID )
     171    { return this->syncList_[ID]->getSize(state_); }
    136172
    137173  protected:
     
    143179
    144180  private:
    145     uint32_t getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
     181    uint32_t getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode);
    146182    uint32_t getSize(int32_t id, uint8_t mode=0x0);
    147183    bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
    148     bool isMyData(uint8_t* mem);
    149184    bool doSync(int32_t id, uint8_t mode=0x0);
    150185
     
    156191    uint32_t classID_;
    157192
    158     std::vector<SynchronisableVariableBase*> syncList;
    159     std::vector<SynchronisableVariableBase*> stringList;
     193    std::vector<SynchronisableVariableBase*> syncList_;
     194    std::vector<SynchronisableVariableBase*> stringList_;
    160195    uint32_t dataSize_; //size of all variables except strings
    161196    static uint8_t state_; // detemines wheter we are server (default) or client
     
    171206    if (bidirectional)
    172207    {
    173       syncList.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb));
    174       this->dataSize_ += syncList.back()->getSize(state_);
     208      syncList_.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb));
     209      this->dataSize_ += syncList_.back()->getSize(state_);
    175210    }
    176211    else
    177212    {
    178       syncList.push_back(new SynchronisableVariable<T>(variable, mode, cb));
     213      syncList_.push_back(new SynchronisableVariable<T>(variable, mode, cb));
    179214      if ( this->state_ == mode )
    180         this->dataSize_ += syncList.back()->getSize(state_);
     215        this->dataSize_ += syncList_.back()->getSize(state_);
    181216    }
    182217  }
Note: See TracChangeset for help on using the changeset viewer.