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
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/libraries/network/NetworkPrereqs.h

    r5929 r6192  
    144144  template <class T>
    145145  class NetworkCallback;
     146  template <class T, class U>
     147  class NetworkCallbackNotify;
    146148  class NetworkCallbackBase;
    147149  class NetworkCallbackManager;
  • code/branches/presentation2/src/libraries/network/packet/DeleteObjects.cc

    r5781 r6192  
    7171  for(unsigned int i=0; i<number; i++){
    7272    unsigned int temp = Synchronisable::popDeletedObject();
    73 //     assert(temp<10000); //ugly hack
    7473    *reinterpret_cast<uint32_t*>(tdata) = temp;
    7574    COUT(4) << temp << " ";
  • 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
  • code/branches/presentation2/src/libraries/util/Serialise.h

    r6123 r6192  
    3737#include <cstring>
    3838#include "util/Math.h"
     39#include "util/mbool.h"
    3940
    4041namespace orxonox{
     
    374375        double temp;
    375376        memcpy(&temp, mem, sizeof(uint64_t));
    376         *(long double*)( &variable ) = static_cast<const long double>(temp);
     377        *(long double*)( &variable ) = static_cast<long double>(temp);
    377378        mem += returnSize( variable );
    378379    }
     
    469470        return variable==Degree(*r);
    470471    }
     472   
     473    // =========== Vector2
     474
     475    template <> inline uint32_t returnSize( const Vector2& variable )
     476    {
     477        return returnSize( variable.x )+returnSize( variable.y );
     478    }
     479
     480    template <> inline void saveAndIncrease( const Vector2& variable, uint8_t*& mem )
     481    {
     482        saveAndIncrease( variable.x, mem );
     483        saveAndIncrease( variable.y, mem );
     484    }
     485
     486    template <> inline void loadAndIncrease( const Vector2& variable, uint8_t*& mem )
     487    {
     488        loadAndIncrease( variable.x, mem );
     489        loadAndIncrease( variable.y, mem );
     490    }
     491
     492    template <> inline bool checkEquality( const Vector2& variable, uint8_t* mem )
     493    {
     494        return checkEquality(variable.x, mem) && checkEquality(variable.y, mem+returnSize(variable.x));
     495    }
     496   
     497    // =========== Vector3
     498
     499    template <> inline uint32_t returnSize( const Vector3& variable )
     500    {
     501        return returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z );
     502    }
     503
     504    template <> inline void saveAndIncrease( const Vector3& variable, uint8_t*& mem )
     505    {
     506        saveAndIncrease( variable.x, mem );
     507        saveAndIncrease( variable.y, mem );
     508        saveAndIncrease( variable.z, mem );
     509    }
     510
     511    template <> inline void loadAndIncrease( const Vector3& variable, uint8_t*& mem )
     512    {
     513        loadAndIncrease( variable.x, mem );
     514        loadAndIncrease( variable.y, mem );
     515        loadAndIncrease( variable.z, mem );
     516    }
     517
     518    template <> inline bool checkEquality( const Vector3& variable, uint8_t* mem )
     519    {
     520        return checkEquality(variable.x, mem) && checkEquality(variable.y, mem+returnSize(variable.x)) &&
     521            checkEquality(variable.z, mem+returnSize(variable.x)+returnSize(variable.y));
     522    }
     523   
     524    // =========== Vector4
     525
     526    template <> inline uint32_t returnSize( const Vector4& variable )
     527    {
     528        return returnSize( variable.w )+returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z );
     529    }
     530
     531    template <> inline void saveAndIncrease( const Vector4& variable, uint8_t*& mem )
     532    {
     533        saveAndIncrease( variable.w, mem );
     534        saveAndIncrease( variable.x, mem );
     535        saveAndIncrease( variable.y, mem );
     536        saveAndIncrease( variable.z, mem );
     537    }
     538
     539    template <> inline void loadAndIncrease( const Vector4& variable, uint8_t*& mem )
     540    {
     541        loadAndIncrease( variable.w, mem );
     542        loadAndIncrease( variable.x, mem );
     543        loadAndIncrease( variable.y, mem );
     544        loadAndIncrease( variable.z, mem );
     545    }
     546
     547    template <> inline bool checkEquality( const Vector4& variable, uint8_t* mem )
     548    {
     549        return checkEquality(variable.w, mem) && checkEquality(variable.x, mem+returnSize(variable.w)) &&
     550            checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)) &&
     551            checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)+returnSize(variable.y));
     552    }
     553   
     554    // =========== Quaternion
     555
     556    template <> inline uint32_t returnSize( const Quaternion& variable )
     557    {
     558        return returnSize( variable.w )+returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z );
     559    }
     560
     561    template <> inline void saveAndIncrease( const Quaternion& variable, uint8_t*& mem )
     562    {
     563        saveAndIncrease( variable.w, mem );
     564        saveAndIncrease( variable.x, mem );
     565        saveAndIncrease( variable.y, mem );
     566        saveAndIncrease( variable.z, mem );
     567    }
     568
     569    template <> inline void loadAndIncrease( const Quaternion& variable, uint8_t*& mem )
     570    {
     571        loadAndIncrease( variable.w, mem );
     572        loadAndIncrease( variable.x, mem );
     573        loadAndIncrease( variable.y, mem );
     574        loadAndIncrease( variable.z, mem );
     575    }
     576
     577    template <> inline bool checkEquality( const Quaternion& variable, uint8_t* mem )
     578    {
     579        return checkEquality(variable.w, mem) && checkEquality(variable.x, mem+returnSize(variable.w)) &&
     580            checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)) &&
     581            checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)+returnSize(variable.y));
     582    }
     583   
     584    // =========== ColourValue
     585
     586    template <> inline uint32_t returnSize( const ColourValue& variable )
     587    {
     588        return returnSize( variable.r )+returnSize( variable.g )+returnSize( variable.b )+returnSize( variable.a );
     589    }
     590
     591    template <> inline void saveAndIncrease( const ColourValue& variable, uint8_t*& mem )
     592    {
     593        saveAndIncrease( variable.r, mem );
     594        saveAndIncrease( variable.g, mem );
     595        saveAndIncrease( variable.b, mem );
     596        saveAndIncrease( variable.a, mem );
     597    }
     598
     599    template <> inline void loadAndIncrease( const ColourValue& variable, uint8_t*& mem )
     600    {
     601        loadAndIncrease( variable.r, mem );
     602        loadAndIncrease( variable.g, mem );
     603        loadAndIncrease( variable.b, mem );
     604        loadAndIncrease( variable.a, mem );
     605    }
     606
     607    template <> inline bool checkEquality( const ColourValue& variable, uint8_t* mem )
     608    {
     609        return checkEquality(variable.r, mem) && checkEquality(variable.g, mem+returnSize(variable.r)) &&
     610            checkEquality(variable.b, mem+returnSize(variable.r)+returnSize(variable.g)) &&
     611            checkEquality(variable.a, mem+returnSize(variable.r)+returnSize(variable.g)+returnSize(variable.b));
     612    }
     613   
     614    // =========== mbool
     615
     616    template <> inline uint32_t returnSize( const mbool& variable )
     617    {
     618        return returnSize( (unsigned char&)((mbool&)variable).getMemory() );
     619    }
     620
     621    template <> inline void saveAndIncrease( const mbool& variable, uint8_t*& mem )
     622    {
     623        saveAndIncrease( (unsigned char&)((mbool&)variable).getMemory(), mem );
     624    }
     625
     626    template <> inline void loadAndIncrease( const mbool& variable, uint8_t*& mem )
     627    {
     628        loadAndIncrease( (unsigned char&)((mbool&)variable).getMemory(), mem );
     629    }
     630
     631    template <> inline bool checkEquality( const mbool& variable, uint8_t* mem )
     632    {
     633        return checkEquality( (unsigned char&)((mbool&)variable).getMemory(), mem );
     634    }
    471635}
    472636
Note: See TracChangeset for help on using the changeset viewer.