Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 18, 2010, 12:05:57 AM (15 years ago)
Author:
scheusso
Message:

further traffic reduction:

  • synchronisableheaders are now smaller( by 2 bytes per header )
  • variableID of SynchronisableVariables are now uint8_t → max 256 synchronised variables per Synchronisable
Location:
code/branches/network2/src/libraries/network/synchronisable
Files:
2 edited

Legend:

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

    r6449 r6450  
    132132   * @return pointer to the newly created synchronisable
    133133   */
    134   Synchronisable *Synchronisable::fabricate(uint8_t*& mem, bool diffed, uint8_t mode)
     134  Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode)
    135135  {
    136136    SynchronisableHeader header(mem);
     137    assert( !header.isDiffed() );
    137138
    138139    COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl;
     
    308309    if(syncList_.empty()){
    309310      assert(0);
    310       COUT(4) << "Synchronisable::updateData syncList_ is empty" << std::endl;
     311      COUT(2) << "Synchronisable::updateData syncList_ is empty" << std::endl;
    311312      return false;
    312313    }
     
    314315    uint8_t* data=mem;
    315316    // start extract header
    316     SynchronisableHeader syncHeader(mem);
    317     assert(syncHeader.getObjectID()==this->objectID_);
    318     assert(syncHeader.getCreatorID()==this->creatorID_);
    319     assert(syncHeader.getClassID()==this->classID_);
    320 
    321     mem += SynchronisableHeader::getSize();
    322     // stop extract header
     317    SynchronisableHeaderLight syncHeaderLight(mem);
     318    assert(syncHeaderLight.getObjectID()==this->getObjectID());
    323319
    324320    //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
    325     if( !syncHeader.isDiffed() )
    326     {
     321    if( !syncHeaderLight.isDiffed() )
     322    {
     323      SynchronisableHeader syncHeader2(mem);
     324      assert( this->getClassID() == syncHeader2.getClassID() );
     325      assert( this->getCreatorID() == syncHeader2.getCreatorID() );
     326      mem += SynchronisableHeader::getSize();
    327327      std::vector<SynchronisableVariableBase *>::iterator i;
    328328      for(i=syncList_.begin(); i!=syncList_.end(); i++)
    329329      {
    330         assert( mem <= data+syncHeader.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream
     330        assert( mem <= data+syncHeader2.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream
    331331        (*i)->putData( mem, mode, forceCallback );
    332332      }
     333      assert(mem == data+syncHeaderLight.getDataSize()+SynchronisableHeader::getSize() );
    333334    }
    334335    else
    335336    {
    336       COUT(0) << "objectID: " << this->objectID_ << endl;
    337       while( mem < data+syncHeader.getDataSize()+SynchronisableHeader::getSize() )
     337      mem += SynchronisableHeaderLight::getSize();
     338//       COUT(0) << "objectID: " << this->objectID_ << endl;
     339      while( mem < data+syncHeaderLight.getDataSize()+SynchronisableHeaderLight::getSize() )
    338340      {
    339         uint32_t varID = *(uint32_t*)mem;
    340         COUT(0) << "varID: " << varID << endl;
    341         if( varID == 22 )
    342           COUT(6) << " blub " << endl;
     341        VariableID varID = *(VariableID*)mem;
     342//         COUT(0) << "varID: " << varID << endl;
    343343        assert( varID < syncList_.size() );
    344         mem += sizeof(uint32_t);
     344        mem += sizeof(VariableID);
    345345        syncList_[varID]->putData( mem, mode, forceCallback );
    346346      }
    347     }
    348     assert(mem == data+syncHeader.getDataSize()+SynchronisableHeader::getSize() );
     347      assert(mem == data+syncHeaderLight.getDataSize()+SynchronisableHeaderLight::getSize() );
     348    }
    349349    return true;
    350350  }
  • code/branches/network2/src/libraries/network/synchronisable/Synchronisable.h

    r6449 r6450  
    6464    };
    6565  }
     66 
     67  typedef uint8_t VariableID;
    6668
    6769  /**
     
    7779   */
    7880  class _NetworkExport SynchronisableHeader{
     81    friend class SynchronisableHeaderLight;
    7982    private:
    80       uint8_t *data_;
     83      uint8_t* data_;
    8184    public:
    8285      SynchronisableHeader(uint8_t* data)
    8386        { data_ = data; }
    8487      inline static uint32_t getSize()
    85         { return 16; }
    86       inline uint32_t getDataSize() const
    87         { return (*(uint32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits
    88       inline void setDataSize(uint32_t size)
    89         { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); }
     88        { return 14; }
     89      inline uint16_t getDataSize() const
     90        { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 31 bits
     91      inline void setDataSize(uint16_t size)
     92        { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); }
    9093      inline bool isDiffed() const
    91         { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; }
     94        { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }
    9295      inline void setDiffed( bool b)
    93         { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }
     96        { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); }
    9497      inline uint32_t getObjectID() const
    95         { return *(uint32_t*)(data_+4); }
     98        { return *(uint32_t*)(data_+2); }
    9699      inline void setObjectID(uint32_t objectID_)
    97         { *(uint32_t*)(data_+4) = objectID_; }
     100        { *(uint32_t*)(data_+2) = objectID_; }
    98101      inline uint32_t getClassID() const
    99         { return *(uint32_t*)(data_+8); }
     102        { return *(uint32_t*)(data_+6); }
    100103      inline void setClassID(uint32_t classID_)
    101         { *(uint32_t*)(data_+8) = classID_; }
     104        { *(uint32_t*)(data_+6) = classID_; }
    102105      inline uint32_t getCreatorID() const
    103         { return *(uint32_t*)(data_+12); }
     106        { return *(uint32_t*)(data_+10); }
    104107      inline void setCreatorID(uint32_t creatorID_)
    105         { *(uint32_t*)(data_+12) = creatorID_; }
     108        { *(uint32_t*)(data_+10) = creatorID_; }
    106109      inline void operator=(SynchronisableHeader& h)
    107110        { memcpy(data_, h.data_, getSize()); }
     
    119122  class _NetworkExport SynchronisableHeaderLight{
    120123    private:
    121       uint8_t *data_;
     124      uint8_t* data_;
    122125    public:
    123       SynchronisableHeader(uint8_t* data)
     126      SynchronisableHeaderLight(uint8_t* data)
    124127        { data_ = data; }
    125128      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 ); }
     129        { return 6; }
     130      inline uint16_t getDataSize() const
     131        { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 31 bits
     132      inline void setDataSize(uint16_t size)
     133        { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); }
    131134      inline bool isDiffed() const
    132         { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; }
     135        { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }
    133136      inline void setDiffed( bool b)
    134         { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }
     137        { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); }
    135138      inline uint32_t getObjectID() const
    136         { return *(uint32_t*)(data_+4); }
     139        { return *(uint32_t*)(data_+2); }
    137140      inline void setObjectID(uint32_t objectID_)
    138         { *(uint32_t*)(data_+4) = objectID_; }
     141        { *(uint32_t*)(data_+2) = objectID_; }
    139142      inline void operator=(SynchronisableHeader& h)
    140143        { memcpy(data_, h.data_, getSize()); }
     
    153156    static void setClient(bool b);
    154157
    155     static Synchronisable *fabricate(uint8_t*& mem, bool diffed, uint8_t mode=0x0);
     158    static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);
    156159    static bool deleteObject(uint32_t objectID_);
    157160    static Synchronisable *getSynchronisable(uint32_t objectID_);
     
    168171   
    169172    inline uint32_t getNrOfVariables(){ return this->syncList_.size(); }
    170     inline uint32_t getVarSize( uint32_t ID )
     173    inline uint32_t getVarSize( VariableID ID )
    171174    { return this->syncList_[ID]->getSize(state_); }
    172175
Note: See TracChangeset for help on using the changeset viewer.