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%

Location:
code/branches/network2/src/libraries/network/synchronisable
Files:
3 edited

Legend:

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

    r6417 r6449  
    7272            return *(uint32_t*)(mem) == variable->getObjectID();
    7373        else
    74             return *(uint32_t*)(mem) == OBJECTID_UNKNOWN;
     74            return variable == variable->getSynchronisable(*(uint32_t*)(mem));
    7575    }
    7676}
  • code/branches/network2/src/libraries/network/synchronisable/Synchronisable.cc

    r6417 r6449  
    101101        deletedObjects_.push(objectID_);
    102102    }
    103     // delete all Synchronisable Variables from syncList ( which are also in stringList )
    104     for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
     103    // delete all Synchronisable Variables from syncList_ ( which are also in stringList_ )
     104    for(std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); it!=syncList_.end(); it++)
    105105      delete (*it);
    106     syncList.clear();
    107     stringList.clear();
     106    syncList_.clear();
     107    stringList_.clear();
    108108    std::map<uint32_t, Synchronisable*>::iterator it;
    109109    it = objectMap_.find(objectID_);
     
    132132   * @return pointer to the newly created synchronisable
    133133   */
    134   Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode)
     134  Synchronisable *Synchronisable::fabricate(uint8_t*& mem, bool diffed, uint8_t mode)
    135135  {
    136136    SynchronisableHeader header(mem);
    137 
    138     if(!header.isDataAvailable())
    139     {
    140       mem += header.getDataSize();
    141       return 0;
    142     }
    143137
    144138    COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl;
     
    160154      if (!synchronisable_creator)
    161155      {
    162         mem += header.getDataSize(); //.TODO: this suckz.... remove size from header
     156        mem += header.getDataSize()+SynchronisableHeader::getSize(); //.TODO: this suckz.... remove size from header
    163157        assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^
    164158        return 0;
     
    245239   * @return true: if !doSync or if everything was successfully saved
    246240   */
    247   uint32_t Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){
     241  uint32_t Synchronisable::getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode){
     242    unsigned int test = 0;
    248243    if(mode==0x0)
    249244      mode=state_;
     
    253248    uint32_t tempsize = 0;
    254249#ifndef NDEBUG
     250    uint8_t* oldmem = mem;
    255251    if (this->classID_==0)
    256252      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
     
    270266    // end copy header
    271267
    272 
    273     COUT(5) << "Synchronisable getting data from objectID_: " << objectID_ << " classID_: " << classID_ << std::endl;
     268    CCOUT(5) << "getting data from objectID_: " << objectID_ << ", classID_: " << classID_ << std::endl;
     269//     COUT(4) << "objectid: " << this->objectID_ << ":";
    274270    // copy to location
    275     for(i=syncList.begin(); i!=syncList.end(); ++i){
    276       tempsize += (*i)->getData( mem, mode );
     271    for(i=syncList_.begin(); i!=syncList_.end(); ++i){
     272      uint32_t varsize = (*i)->getData( mem, mode );
     273//       COUT(4) << " " << varsize;
     274      tempsize += varsize;
     275      sizes.push_back(varsize);
     276      ++test;
    277277      //tempsize += (*i)->getSize( mode );
    278278    }
    279 
    280     tempsize += SynchronisableHeader::getSize();
     279//     COUT(4) << endl;
     280
    281281    header.setObjectID( this->objectID_ );
    282282    header.setCreatorID( this->creatorID_ );
    283283    header.setClassID( this->classID_ );
    284     header.setDataAvailable( true );
    285284    header.setDataSize( tempsize );
     285    assert( tempsize == mem-oldmem-SynchronisableHeader::getSize() );
     286    assert( test == this->getNrOfVariables() );
     287    header.setDiffed(false);
     288    tempsize += SynchronisableHeader::getSize();
    286289
    287290#ifndef NDEBUG
     
    303306    if(mode==0x0)
    304307      mode=state_;
    305     std::vector<SynchronisableVariableBase *>::iterator i;
    306     if(syncList.empty()){
     308    if(syncList_.empty()){
    307309      assert(0);
    308       COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
     310      COUT(4) << "Synchronisable::updateData syncList_ is empty" << std::endl;
    309311      return false;
    310312    }
     
    316318    assert(syncHeader.getCreatorID()==this->creatorID_);
    317319    assert(syncHeader.getClassID()==this->classID_);
    318     if(syncHeader.isDataAvailable()==false){
    319       mem += syncHeader.getDataSize();
    320       return true;
    321     }
    322320
    323321    mem += SynchronisableHeader::getSize();
     
    325323
    326324    //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
    327     for(i=syncList.begin(); i!=syncList.end(); i++)
    328     {
    329       assert( mem <= data+syncHeader.getDataSize() ); // always make sure we don't exceed the datasize in our stream
    330       (*i)->putData( mem, mode, forceCallback );
    331     }
    332     assert(mem == data+syncHeader.getDataSize());
     325    if( !syncHeader.isDiffed() )
     326    {
     327      std::vector<SynchronisableVariableBase *>::iterator i;
     328      for(i=syncList_.begin(); i!=syncList_.end(); i++)
     329      {
     330        assert( mem <= data+syncHeader.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream
     331        (*i)->putData( mem, mode, forceCallback );
     332      }
     333    }
     334    else
     335    {
     336      COUT(0) << "objectID: " << this->objectID_ << endl;
     337      while( mem < data+syncHeader.getDataSize()+SynchronisableHeader::getSize() )
     338      {
     339        uint32_t varID = *(uint32_t*)mem;
     340        COUT(0) << "varID: " << varID << endl;
     341        if( varID == 22 )
     342          COUT(6) << " blub " << endl;
     343        assert( varID < syncList_.size() );
     344        mem += sizeof(uint32_t);
     345        syncList_[varID]->putData( mem, mode, forceCallback );
     346      }
     347    }
     348    assert(mem == data+syncHeader.getDataSize()+SynchronisableHeader::getSize() );
    333349    return true;
    334350  }
     
    341357  */
    342358  uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){
    343     int tsize=SynchronisableHeader::getSize();
     359    uint32_t tsize=SynchronisableHeader::getSize();
    344360    if (mode==0x0)
    345361      mode=state_;
     
    349365    tsize += this->dataSize_;
    350366    std::vector<SynchronisableVariableBase*>::iterator i;
    351     for(i=stringList.begin(); i!=stringList.end(); ++i){
     367    for(i=stringList_.begin(); i!=stringList_.end(); ++i){
    352368      tsize += (*i)->getSize( mode );
    353369    }
     
    363379    if(mode==0x0)
    364380      mode=state_;
    365     return ( (this->objectMode_ & mode)!=0 && (!syncList.empty() ) );
    366   }
    367 
    368   /**
    369    * This function looks at the header located in the bytestream and checks wheter objectID_ and classID_ match with the Synchronisables ones
    370    * @param mem pointer to the bytestream
    371    */
    372   bool Synchronisable::isMyData(uint8_t* mem)
    373   {
    374     SynchronisableHeader header(mem);
    375     assert(header.getObjectID()==this->objectID_);
    376     return header.isDataAvailable();
     381    return ( (this->objectMode_ & mode)!=0 && (!syncList_.empty() ) );
    377382  }
    378383
     
    397402    else
    398403      sv = new SynchronisableVariable<std::string>(variable, mode, cb);
    399     syncList.push_back(sv);
    400     stringList.push_back(sv);
     404    syncList_.push_back(sv);
     405    stringList_.push_back(sv);
    401406  }
    402407
  • 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.