Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 2, 2009, 11:35:24 AM (15 years ago)
Author:
scheusso
Message:

some cleaning up and improvements in synchronisation of vector2,3,4 and quaternions

Location:
code/branches/presentation2/src/libraries/network/synchronisable
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/libraries/network/synchronisable/CMakeLists.txt

    r6124 r6192  
    22  NetworkCallbackManager.cc
    33  Synchronisable.cc
    4   SynchronisableSpecialisations.cc
    54  SynchronisableVariable.cc
    65)
  • code/branches/presentation2/src/libraries/network/synchronisable/NetworkCallback.h

    r6073 r6192  
    3333#include "network/NetworkPrereqs.h"
    3434#include "NetworkCallbackManager.h"
     35// #include "util/MultiType.h"
    3536
    3637namespace orxonox{
     38 
     39  struct EmptyType{};
    3740 
    3841  class _NetworkExport NetworkCallbackBase
     
    5760      void (T::*function_) (void);
    5861  };
     62 
     63  template <class T, class U>
     64  class NetworkCallbackNotify: public NetworkCallbackBase
     65  {
     66    public:
     67      NetworkCallbackNotify(T* object, void (T::*function) (const U&)) : object_(object), function_(function) {}
     68      NetworkCallbackNotify() {}
     69      virtual ~NetworkCallbackNotify() {}
     70      virtual void call()
     71        { (this->object_->*function_)( this->oldValue_ ); }
     72      void setOldValue(const U& value){ this->oldValue_ = value; }
     73    private:
     74      T* object_;
     75      U oldValue_;
     76      void (T::*function_) (const U&);
     77  };
    5978
    6079}
  • code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.cc

    r5929 r6192  
    390390  }
    391391
     392  template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     393  {
     394    SynchronisableVariableBase* sv;
     395    if (bidirectional)
     396      sv = new SynchronisableVariableBidirectional<std::string>(variable, mode, cb);
     397    else
     398      sv = new SynchronisableVariable<std::string>(variable, mode, cb);
     399    syncList.push_back(sv);
     400    stringList.push_back(sv);
     401  }
     402
    392403
    393404}
  • code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h

    r6123 r6192  
    138138    Synchronisable(BaseObject* creator);
    139139    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
     140   
    140141    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
    141142
     
    166167  };
    167168
    168   // ================= Specialisation declarations
    169  
    170 //   template <> _NetworkExport void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    171   template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    172   template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    173   template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    174   template <> _NetworkExport void Synchronisable::registerVariable( const Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    175   template <> _NetworkExport void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    176   template <> _NetworkExport void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    177   template <> _NetworkExport void Synchronisable::registerVariable( Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    178   template <> _NetworkExport void Synchronisable::registerVariable( const Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    179   template <> _NetworkExport void Synchronisable::registerVariable( Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    180   template <> _NetworkExport void Synchronisable::registerVariable( mbool& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    181   template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    182   template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    183  
    184169  template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
    185170  {
     
    196181    }
    197182  }
     183 
     184  template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    198185
    199186 
  • code/branches/presentation2/src/libraries/network/synchronisable/SynchronisableVariable.h

    r6132 r6192  
    8181      virtual inline void* getReference(){ return static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->variable_)); }
    8282    protected:
    83      
    84       T& variable_;
    85       uint8_t mode_;
    86       NetworkCallbackBase *callback_;
     83      T&                       variable_;
     84      uint8_t                  mode_;
     85      NetworkCallbackBase      *callback_;
    8786  };
    8887 
     
    116115  template <class T> SynchronisableVariable<T>::~SynchronisableVariable()
    117116  {
    118     if (this->callback_ != 0)
     117    if (this->callback_)
    119118    {
    120119      NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion
     
    141140      return;
    142141  // check whether we need to consider a callback
    143     if ( this->callback_ != 0 )
     142    if ( this->callback_ )
    144143    {
    145144      callback = forceCallback || !checkEquality( this->variable_, mem );
     145    }
     146  // now do a callback if neccessary
     147    if ( callback )
     148    {
     149      NetworkCallbackManager::triggerCallback( this->callback_ );
    146150    }
    147151  // write the data
    148152    loadAndIncrease( this->variable_, mem );
    149   // now do a callback if neccessary
    150     if ( callback )
    151       NetworkCallbackManager::triggerCallback( this->callback_ );
    152153  }
    153154
     
    215216            mem += sizeof(varReference_);
    216217            memcpy(static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->varBuffer_)), &this->variable_, sizeof(T));
    217             if ( this->callback_ != 0 )
     218            if ( this->callback_ )
    218219              callback = true;
    219220          }
     
    234235          {
    235236            // value changed so remark for callback
    236             if ( this->callback_ != 0 )
     237            if ( this->callback_ )
    237238              callback = true;
    238239          }
    239240        }
    240241      }
     242  // now do a callback if neccessary
     243      if ( callback )
     244      {
     245        NetworkCallbackManager::triggerCallback( this->callback_ );
     246      }
    241247  // now write the data
    242248      loadAndIncrease(this->variable_, mem);
    243   // now do a callback if neccessary
    244       if ( callback )
    245         NetworkCallbackManager::triggerCallback( this->callback_ );
    246249    }
    247250
Note: See TracChangeset for help on using the changeset viewer.