Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2822


Ignore:
Timestamp:
Mar 23, 2009, 10:28:25 AM (16 years ago)
Author:
scheusso
Message:

reduced overhead/load of Synchronisable::getSize quite a lot

Location:
code/branches/netp/src/network/synchronisable
Files:
4 edited

Legend:

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

    r2773 r2822  
    6666      objectID=OBJECTID_UNKNOWN;
    6767    classID = static_cast<uint32_t>(-1);
    68 
     68   
     69    // set dataSize to 0
     70    this->dataSize_ = 0;
    6971    // set standard priority
    7072    this->setPriority( priority::normal );
     
    251253    assert(this->classID==this->getIdentifier()->getNetworkID());
    252254    std::list<SynchronisableVariableBase*>::iterator i;
    253     uint32_t size;
    254     size=getSize(id, mode);
    255255
    256256    // start copy header
    257257    SynchronisableHeader header(mem);
    258     header.setDataSize( size );
     258    mem += SynchronisableHeader::getSize();
     259    // end copy header
     260
     261
     262    COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << std::endl;
     263    // copy to location
     264    for(i=syncList.begin(); i!=syncList.end(); ++i){
     265      tempsize += (*i)->getData( mem, mode );
     266      //tempsize += (*i)->getSize( mode );
     267    }
     268   
     269    tempsize += SynchronisableHeader::getSize();
    259270    header.setObjectID( this->objectID );
    260271    header.setCreatorID( this->creatorID );
    261272    header.setClassID( this->classID );
    262273    header.setDataAvailable( true );
    263     tempsize += SynchronisableHeader::getSize();
    264     mem += SynchronisableHeader::getSize();
    265     // end copy header
    266 
    267 
    268     COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl;
    269     // copy to location
    270     for(i=syncList.begin(); i!=syncList.end(); ++i){
    271       (*i)->getData( mem, mode );
    272       tempsize += (*i)->getSize( mode );
    273     }
     274    header.setDataSize( tempsize );
     275   
     276#ifndef NDEBUG
     277    uint32_t size;
     278    size=getSize(id, mode);
    274279    assert(tempsize==size);
     280#endif
    275281    return true;
    276282  }
     
    325331  uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){
    326332    int tsize=SynchronisableHeader::getSize();
    327     if(mode==0x0)
     333    if (mode==0x0)
    328334      mode=state_;
    329     if(!doSync(id, mode))
     335    if (!doSync(id, mode))
    330336      return 0;
     337    assert( mode==state_ );
     338    tsize += this->dataSize_;
    331339    std::list<SynchronisableVariableBase*>::iterator i;
    332     for(i=syncList.begin(); i!=syncList.end(); i++){
     340    for(i=stringList.begin(); i!=stringList.end(); ++i){
    333341      tsize += (*i)->getSize( mode );
    334342    }
  • code/branches/netp/src/network/synchronisable/Synchronisable.h

    r2773 r2822  
    3636#include <queue>
    3737#include <cassert>
     38#include <string>
    3839#include "util/Math.h"
    3940#include "util/mbool.h"
     
    139140    Synchronisable(BaseObject* creator);
    140141    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
    141     template <class T> void unregisterVariable(T& var);
     142    //template <class T> void unregisterVariable(T& var);
    142143    void setObjectMode(uint8_t mode);
    143144    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
     
    156157
    157158    std::list<SynchronisableVariableBase*> syncList;
     159    std::list<SynchronisableVariableBase*> stringList;
     160    uint32_t dataSize_; //size of all variables except strings
    158161    static uint8_t state_; // detemines wheter we are server (default) or client
    159162    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
     
    164167  };
    165168
    166   template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
    167   {
    168     if (bidirectional)
    169       syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
    170     else
    171       syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
    172   }
    173 
    174   template <class T> void Synchronisable::unregisterVariable(T& var){
    175     std::list<SynchronisableVariableBase*>::iterator it = syncList.begin();
    176     while(it!=syncList.end()){
    177       if( ((*it)->getReference()) == &var ){
    178         delete (*it);
    179         syncList.erase(it);
    180         return;
    181       }
    182       else
    183         it++;
    184     }
    185     bool unregistered_nonexistent_variable = false;
    186     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
    187     // the variable has not been registered before
    188   }
    189 
    190169  // ================= Specialisation declarations
     170 
     171//   template <> _NetworkExport void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
     172  template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    191173  template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    192174  template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
     
    200182  template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    201183  template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
     184 
     185  template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     186  {
     187    if (bidirectional)
     188      syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
     189    else
     190      syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
     191    if ( this->state_ == mode )
     192      this->dataSize_ += syncList.back()->getSize(state_);
     193  }
     194 
     195
     196
     197//   template <class T> void Synchronisable::unregisterVariable(T& var){
     198//     std::list<SynchronisableVariableBase*>::iterator it = syncList.begin();
     199//     while(it!=syncList.end()){
     200//       if( ((*it)->getReference()) == &var ){
     201//         delete (*it);
     202//         syncList.erase(it);
     203//         return;
     204//       }
     205//       else
     206//         it++;
     207//     }
     208//     bool unregistered_nonexistent_variable = false;
     209//     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
     210//     // the variable has not been registered before
     211//   }
     212
     213 
    202214}
    203215
  • code/branches/netp/src/network/synchronisable/SynchronisableSpecialisations.cc

    r2662 r2822  
    2929
    3030#include "network/synchronisable/Synchronisable.h"
     31#include <string>
    3132
    3233// ================ template spezialisation
     
    3435 
    3536namespace orxonox{
     37 
     38//   template <> void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     39//   {
     40//     if (bidirectional)
     41//       syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
     42//     else
     43//       syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
     44//     stringList.push_back(syncList.back());
     45//   }
     46 
     47  template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     48  {
     49    if (bidirectional)
     50      syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
     51    else
     52      syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
     53    stringList.push_back(syncList.back());
     54  }
    3655 
    3756  template <> void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
  • code/branches/netp/src/network/synchronisable/SynchronisableVariable.h

    r2794 r2822  
    5656  {
    5757    public:
    58       virtual void getData(uint8_t*& mem, uint8_t mode)=0;
     58      virtual uint32_t getData(uint8_t*& mem, uint8_t mode)=0;
    5959      virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false)=0;
    6060      virtual uint32_t getSize(uint8_t mode)=0;
     
    7474
    7575      virtual inline uint8_t getMode(){ return mode_; }
    76       virtual inline void getData(uint8_t*& mem, uint8_t mode);
     76      virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode);
    7777      virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false);
    7878      virtual inline uint32_t getSize(uint8_t mode);
     
    9797     
    9898      virtual inline uint8_t getMode(){ return 0x3; } //this basically is a hack ^^
    99       virtual inline void getData(uint8_t*& mem, uint8_t mode);
     99      virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode);
    100100      virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false);
    101101      virtual inline uint32_t getSize(uint8_t mode);
     
    122122  }
    123123
    124   template <class T> inline void SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)
     124  template <class T> inline uint32_t SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)
    125125  {
    126126    if ( state_ == this->mode_ )
     127    {
    127128      getAndIncrease( mem );
     129      return returnSize();
     130    }
     131    else
     132      return 0;
    128133//   mem += SynchronisableVariable<T>::getSize();
    129134  }
     
    230235    }
    231236
    232     template <class T> void SynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode)
     237    template <class T> uint32_t SynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode)
    233238    {
    234239      if ( this->mode_ == mode )
     
    246251      SynchronisableVariable<T>::getAndIncrease( mem );
    247252//   mem += SynchronisableVariable<T>::getSize();
     253      return SynchronisableVariableBidirectional::getSize(mode);
    248254    }
    249255
Note: See TracChangeset for help on using the changeset viewer.