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.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
Note: See TracChangeset for help on using the changeset viewer.