Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

File:
1 edited

Legend:

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