- Timestamp:
- Dec 2, 2009, 11:35:24 AM (15 years ago)
- 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 2 2 NetworkCallbackManager.cc 3 3 Synchronisable.cc 4 SynchronisableSpecialisations.cc5 4 SynchronisableVariable.cc 6 5 ) -
code/branches/presentation2/src/libraries/network/synchronisable/NetworkCallback.h
r6073 r6192 33 33 #include "network/NetworkPrereqs.h" 34 34 #include "NetworkCallbackManager.h" 35 // #include "util/MultiType.h" 35 36 36 37 namespace orxonox{ 38 39 struct EmptyType{}; 37 40 38 41 class _NetworkExport NetworkCallbackBase … … 57 60 void (T::*function_) (void); 58 61 }; 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 }; 59 78 60 79 } -
code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.cc
r5929 r6192 390 390 } 391 391 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 392 403 393 404 } -
code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h
r6123 r6192 138 138 Synchronisable(BaseObject* creator); 139 139 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false); 140 140 141 void setPriority(unsigned int freq){ objectFrequency_ = freq; } 141 142 … … 166 167 }; 167 168 168 // ================= Specialisation declarations169 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 184 169 template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 185 170 { … … 196 181 } 197 182 } 183 184 template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 198 185 199 186 -
code/branches/presentation2/src/libraries/network/synchronisable/SynchronisableVariable.h
r6132 r6192 81 81 virtual inline void* getReference(){ return static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->variable_)); } 82 82 protected: 83 84 T& variable_; 85 uint8_t mode_; 86 NetworkCallbackBase *callback_; 83 T& variable_; 84 uint8_t mode_; 85 NetworkCallbackBase *callback_; 87 86 }; 88 87 … … 116 115 template <class T> SynchronisableVariable<T>::~SynchronisableVariable() 117 116 { 118 if (this->callback_ != 0)117 if (this->callback_) 119 118 { 120 119 NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion … … 141 140 return; 142 141 // check whether we need to consider a callback 143 if ( this->callback_ != 0)142 if ( this->callback_ ) 144 143 { 145 144 callback = forceCallback || !checkEquality( this->variable_, mem ); 145 } 146 // now do a callback if neccessary 147 if ( callback ) 148 { 149 NetworkCallbackManager::triggerCallback( this->callback_ ); 146 150 } 147 151 // write the data 148 152 loadAndIncrease( this->variable_, mem ); 149 // now do a callback if neccessary150 if ( callback )151 NetworkCallbackManager::triggerCallback( this->callback_ );152 153 } 153 154 … … 215 216 mem += sizeof(varReference_); 216 217 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_ ) 218 219 callback = true; 219 220 } … … 234 235 { 235 236 // value changed so remark for callback 236 if ( this->callback_ != 0)237 if ( this->callback_ ) 237 238 callback = true; 238 239 } 239 240 } 240 241 } 242 // now do a callback if neccessary 243 if ( callback ) 244 { 245 NetworkCallbackManager::triggerCallback( this->callback_ ); 246 } 241 247 // now write the data 242 248 loadAndIncrease(this->variable_, mem); 243 // now do a callback if neccessary244 if ( callback )245 NetworkCallbackManager::triggerCallback( this->callback_ );246 249 } 247 250
Note: See TracChangeset
for help on using the changeset viewer.