Changeset 2861 for code/branches/netp2/src
- Timestamp:
- Mar 28, 2009, 11:19:06 PM (16 years ago)
- Location:
- code/branches/netp2/src
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp2/src/network/synchronisable/SynchronisableSpecialisations.cc
r2836 r2861 71 71 registerVariable(variable.y, mode, cb, bidirectional); 72 72 } 73 template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)74 {75 registerVariable( (const ColourValue&)variable, mode, cb, bidirectional);76 }73 // template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional) 74 // { 75 // registerVariable( (const ColourValue&)variable, mode, cb, bidirectional); 76 // } 77 77 78 78 template <> void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional) -
code/branches/netp2/src/network/synchronisable/SynchronisableVariable.h
r2836 r2861 21 21 * 22 22 * Author: 23 * Oliver Scheuss , (C) 200823 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 35 35 #include <string> 36 36 #include <cassert> 37 #include "util/Serialise.h" 37 38 #include "core/Core.h" 38 39 #include "core/CoreIncludes.h" … … 79 80 virtual inline void* getReference(){ return (void *)&this->variable_; } 80 81 protected: 81 inline bool checkEquality(uint8_t* mem);82 inline void setAndIncrease(uint8_t*& mem);83 inline void getAndIncrease(uint8_t*& mem);84 inline uint32_t returnSize();82 // inline bool checkEquality(uint8_t* mem); 83 // inline void loadAndIncrease(uint8_t*& mem); 84 // inline void saveAndIncrease(uint8_t*& mem); 85 // inline uint32_t returnSize(); 85 86 86 87 T& variable_; … … 126 127 if ( state_ == this->mode_ ) 127 128 { 128 getAndIncrease(mem );129 return returnSize( );129 saveAndIncrease( this->variable_, mem ); 130 return returnSize( this->variable_ ); 130 131 } 131 132 else … … 143 144 if ( this->callback_ != 0 ) 144 145 { 145 if( forceCallback || !checkEquality( mem ) )146 if( forceCallback || !checkEquality( this->variable_, mem ) ) 146 147 callback = true; 147 148 } 148 149 // write the data 149 setAndIncrease(mem );150 loadAndIncrease( this->variable_, mem ); 150 151 // now do a callback if neccessary 151 152 if ( callback ) … … 156 157 { 157 158 if ( mode == this->mode_ ) 158 return returnSize( );159 return returnSize( this->variable_ ); 159 160 else 160 161 return 0; 161 162 } 162 163 163 template <> _NetworkExport uint32_t SynchronisableVariable<const bool>::returnSize();164 template <> _NetworkExport void SynchronisableVariable<const bool>:: setAndIncrease(uint8_t*& mem);165 template <> _NetworkExport void SynchronisableVariable<const bool>:: getAndIncrease(uint8_t*& mem);164 /*template <> _NetworkExport uint32_t SynchronisableVariable<const bool>::returnSize(); 165 template <> _NetworkExport void SynchronisableVariable<const bool>::loadAndIncrease(uint8_t*& mem); 166 template <> _NetworkExport void SynchronisableVariable<const bool>::saveAndIncrease(uint8_t*& mem); 166 167 template <> _NetworkExport bool SynchronisableVariable<const bool>::checkEquality(uint8_t* mem); 167 168 template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned char>::returnSize(); 168 template <> _NetworkExport void SynchronisableVariable<const unsigned char>:: setAndIncrease(uint8_t*& mem);169 template <> _NetworkExport void SynchronisableVariable<const unsigned char>:: getAndIncrease(uint8_t*& mem);169 template <> _NetworkExport void SynchronisableVariable<const unsigned char>::loadAndIncrease(uint8_t*& mem); 170 template <> _NetworkExport void SynchronisableVariable<const unsigned char>::saveAndIncrease(uint8_t*& mem); 170 171 template <> _NetworkExport bool SynchronisableVariable<const unsigned char>::checkEquality(uint8_t* mem); 171 172 template <> _NetworkExport uint32_t SynchronisableVariable<const short>::returnSize(); 172 template <> _NetworkExport void SynchronisableVariable<const short>:: setAndIncrease(uint8_t*& mem);173 template <> _NetworkExport void SynchronisableVariable<const short>:: getAndIncrease(uint8_t*& mem);173 template <> _NetworkExport void SynchronisableVariable<const short>::loadAndIncrease(uint8_t*& mem); 174 template <> _NetworkExport void SynchronisableVariable<const short>::saveAndIncrease(uint8_t*& mem); 174 175 template <> _NetworkExport bool SynchronisableVariable<const short>::checkEquality(uint8_t* mem); 175 176 template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned short>::returnSize(); 176 template <> _NetworkExport void SynchronisableVariable<const unsigned short>:: setAndIncrease(uint8_t*& mem);177 template <> _NetworkExport void SynchronisableVariable<const unsigned short>:: getAndIncrease(uint8_t*& mem);177 template <> _NetworkExport void SynchronisableVariable<const unsigned short>::loadAndIncrease(uint8_t*& mem); 178 template <> _NetworkExport void SynchronisableVariable<const unsigned short>::saveAndIncrease(uint8_t*& mem); 178 179 template <> _NetworkExport bool SynchronisableVariable<const unsigned short>::checkEquality(uint8_t* mem); 179 180 template <> _NetworkExport uint32_t SynchronisableVariable<const int>::returnSize(); 180 template <> _NetworkExport void SynchronisableVariable<const int>:: setAndIncrease(uint8_t*& mem);181 template <> _NetworkExport void SynchronisableVariable<const int>:: getAndIncrease(uint8_t*& mem);181 template <> _NetworkExport void SynchronisableVariable<const int>::loadAndIncrease(uint8_t*& mem); 182 template <> _NetworkExport void SynchronisableVariable<const int>::saveAndIncrease(uint8_t*& mem); 182 183 template <> _NetworkExport bool SynchronisableVariable<const int>::checkEquality(uint8_t* mem); 183 184 template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned int>::returnSize(); 184 template <> _NetworkExport void SynchronisableVariable<const unsigned int>:: setAndIncrease(uint8_t*& mem);185 template <> _NetworkExport void SynchronisableVariable<const unsigned int>:: getAndIncrease(uint8_t*& mem);185 template <> _NetworkExport void SynchronisableVariable<const unsigned int>::loadAndIncrease(uint8_t*& mem); 186 template <> _NetworkExport void SynchronisableVariable<const unsigned int>::saveAndIncrease(uint8_t*& mem); 186 187 template <> _NetworkExport bool SynchronisableVariable<const unsigned int>::checkEquality(uint8_t* mem); 187 188 template <> _NetworkExport uint32_t SynchronisableVariable<const long>::returnSize(); 188 template <> _NetworkExport void SynchronisableVariable<const long>:: setAndIncrease(uint8_t*& mem);189 template <> _NetworkExport void SynchronisableVariable<const long>:: getAndIncrease(uint8_t*& mem);189 template <> _NetworkExport void SynchronisableVariable<const long>::loadAndIncrease(uint8_t*& mem); 190 template <> _NetworkExport void SynchronisableVariable<const long>::saveAndIncrease(uint8_t*& mem); 190 191 template <> _NetworkExport bool SynchronisableVariable<const long>::checkEquality(uint8_t* mem); 191 192 template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned long>::returnSize(); 192 template <> _NetworkExport void SynchronisableVariable<const unsigned long>:: setAndIncrease(uint8_t*& mem);193 template <> _NetworkExport void SynchronisableVariable<const unsigned long>:: getAndIncrease(uint8_t*& mem);193 template <> _NetworkExport void SynchronisableVariable<const unsigned long>::loadAndIncrease(uint8_t*& mem); 194 template <> _NetworkExport void SynchronisableVariable<const unsigned long>::saveAndIncrease(uint8_t*& mem); 194 195 template <> _NetworkExport bool SynchronisableVariable<const unsigned long>::checkEquality(uint8_t* mem); 195 196 template <> _NetworkExport uint32_t SynchronisableVariable<const long long>::returnSize(); 196 template <> _NetworkExport void SynchronisableVariable<const long long>:: setAndIncrease(uint8_t*& mem);197 template <> _NetworkExport void SynchronisableVariable<const long long>:: getAndIncrease(uint8_t*& mem);197 template <> _NetworkExport void SynchronisableVariable<const long long>::loadAndIncrease(uint8_t*& mem); 198 template <> _NetworkExport void SynchronisableVariable<const long long>::saveAndIncrease(uint8_t*& mem); 198 199 template <> _NetworkExport bool SynchronisableVariable<const long long>::checkEquality(uint8_t* mem); 199 200 template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned long long>::returnSize(); 200 template <> _NetworkExport void SynchronisableVariable<const unsigned long long>:: setAndIncrease(uint8_t*& mem);201 template <> _NetworkExport void SynchronisableVariable<const unsigned long long>:: getAndIncrease(uint8_t*& mem);201 template <> _NetworkExport void SynchronisableVariable<const unsigned long long>::loadAndIncrease(uint8_t*& mem); 202 template <> _NetworkExport void SynchronisableVariable<const unsigned long long>::saveAndIncrease(uint8_t*& mem); 202 203 template <> _NetworkExport bool SynchronisableVariable<const unsigned long long>::checkEquality(uint8_t* mem); 203 204 template <> _NetworkExport uint32_t SynchronisableVariable<const float>::returnSize(); 204 template <> _NetworkExport void SynchronisableVariable<const float>:: setAndIncrease(uint8_t*& mem);205 template <> _NetworkExport void SynchronisableVariable<const float>:: getAndIncrease(uint8_t*& mem);205 template <> _NetworkExport void SynchronisableVariable<const float>::loadAndIncrease(uint8_t*& mem); 206 template <> _NetworkExport void SynchronisableVariable<const float>::saveAndIncrease(uint8_t*& mem); 206 207 template <> _NetworkExport bool SynchronisableVariable<const float>::checkEquality(uint8_t* mem); 207 208 template <> _NetworkExport uint32_t SynchronisableVariable<const double>::returnSize(); 208 template <> _NetworkExport void SynchronisableVariable<const double>:: setAndIncrease(uint8_t*& mem);209 template <> _NetworkExport void SynchronisableVariable<const double>:: getAndIncrease(uint8_t*& mem);209 template <> _NetworkExport void SynchronisableVariable<const double>::loadAndIncrease(uint8_t*& mem); 210 template <> _NetworkExport void SynchronisableVariable<const double>::saveAndIncrease(uint8_t*& mem); 210 211 template <> _NetworkExport bool SynchronisableVariable<const double>::checkEquality(uint8_t* mem); 211 212 template <> _NetworkExport uint32_t SynchronisableVariable<const long double>::returnSize(); 212 template <> _NetworkExport void SynchronisableVariable<const long double>:: setAndIncrease(uint8_t*& mem);213 template <> _NetworkExport void SynchronisableVariable<const long double>:: getAndIncrease(uint8_t*& mem);213 template <> _NetworkExport void SynchronisableVariable<const long double>::loadAndIncrease(uint8_t*& mem); 214 template <> _NetworkExport void SynchronisableVariable<const long double>::saveAndIncrease(uint8_t*& mem); 214 215 template <> _NetworkExport bool SynchronisableVariable<const long double>::checkEquality(uint8_t* mem); 215 216 template <> _NetworkExport uint32_t SynchronisableVariable<const std::string>::returnSize(); 216 template <> _NetworkExport void SynchronisableVariable<const std::string>:: setAndIncrease(uint8_t*& mem);217 template <> _NetworkExport void SynchronisableVariable<const std::string>:: getAndIncrease(uint8_t*& mem);217 template <> _NetworkExport void SynchronisableVariable<const std::string>::loadAndIncrease(uint8_t*& mem); 218 template <> _NetworkExport void SynchronisableVariable<const std::string>::saveAndIncrease(uint8_t*& mem); 218 219 template <> _NetworkExport bool SynchronisableVariable<const std::string>::checkEquality(uint8_t* mem); 219 220 template <> _NetworkExport uint32_t SynchronisableVariable<const Degree>::returnSize(); 220 template <> _NetworkExport void SynchronisableVariable<const Degree>:: setAndIncrease(uint8_t*& mem);221 template <> _NetworkExport void SynchronisableVariable<const Degree>:: getAndIncrease(uint8_t*& mem);222 template <> _NetworkExport bool SynchronisableVariable<const Degree>::checkEquality(uint8_t* mem); 221 template <> _NetworkExport void SynchronisableVariable<const Degree>::loadAndIncrease(uint8_t*& mem); 222 template <> _NetworkExport void SynchronisableVariable<const Degree>::saveAndIncrease(uint8_t*& mem); 223 template <> _NetworkExport bool SynchronisableVariable<const Degree>::checkEquality(uint8_t* mem);*/ 223 224 224 225 … … 249 250 mem += sizeof(this->varReference_); 250 251 // now write the content 251 SynchronisableVariable<T>::getAndIncrease(mem );252 saveAndIncrease( this->variable_, mem ); 252 253 // mem += SynchronisableVariable<T>::getSize(); 253 254 return SynchronisableVariableBidirectional::getSize(mode); … … 268 269 // apply data 269 270 mem += sizeof(varReference_); 270 if ( SynchronisableVariableBidirectional<T>::checkEquality(mem )==true )271 if ( checkEquality( this->variable_, mem )==true ) 271 272 { 272 mem += SynchronisableVariable<T>::getSize( mode );273 mem += getSize( mode ); 273 274 return; 274 275 } … … 292 293 this->varReference_ = *static_cast<uint8_t*>(mem); 293 294 mem += sizeof(varReference_); 294 if ( SynchronisableVariable<T>::checkEquality(mem ) == false )295 if ( checkEquality( this->variable_, mem ) == false ) 295 296 { 296 297 // value changed so remark for callback … … 301 302 } 302 303 // now write the data 303 SynchronisableVariable<T>::setAndIncrease(mem);304 loadAndIncrease(this->variable_, mem); 304 305 // now do a callback if neccessary 305 306 if ( callback ) … … 310 311 template <class T> inline uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode) 311 312 { 312 return SynchronisableVariable<T>::returnSize() + sizeof(varReference_);313 return returnSize( this->variable_ ) + sizeof(varReference_); 313 314 } 314 315 … … 316 317 } 317 318 318 #include "network/synchronisable/SynchronisableVariableSpecialisations.h"319 //#include "network/synchronisable/SynchronisableVariableSpecialisations.h" 319 320 320 321 #endif -
code/branches/netp2/src/util/MultiType.h
r2662 r2861 223 223 224 224 virtual void toString(std::ostream& outstream) const = 0; 225 226 virtual void importData( uint8_t*& mem )=0; 227 virtual void exportData( uint8_t*& mem ) const=0; 228 virtual uint8_t getSize() const=0; 225 229 226 230 MT_Type type_; //!< The type of the current value … … 320 324 template <typename T> inline bool isType() const { return false; } // Only works for specialized values - see below 321 325 std::string getTypename() const; 326 327 /** @brief Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT */ 328 inline void importData(uint8_t*& mem) { assert(sizeof(MT_Type)<=8); *(uint8_t*)(mem) = this->getType(); mem+=sizeof(uint8_t); this->value_->importData(mem); } 329 /** @brief Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT */ 330 inline void exportData(uint8_t*& mem) { assert(sizeof(MT_Type)<=8); this->setType(*(uint8_t*)mem); mem+=sizeof(uint8_t); this->value_->exportData(mem); } 331 /** @brief Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT */ 332 inline uint8_t*& operator << (uint8_t*& mem) { importData(mem); return mem; } 333 /** @brief Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT */ 334 inline void operator >> (uint8_t*& mem) { exportData(mem); } 322 335 323 336 /** @brief Checks whether the value is a default one. */ -
code/branches/netp2/src/util/MultiTypeValue.h
r2171 r2861 40 40 #include "MathConvert.h" 41 41 #include "MultiType.h" 42 #include "Serialise.h" 43 #include <cassert> 42 44 43 45 namespace orxonox … … 147 149 /** @brief Puts the current value on the stream */ 148 150 inline void toString(std::ostream& outstream) const { outstream << this->value_; } 151 152 /** @brief loads data from the bytestream (mem) into the MT and increases the bytestream pointer by the size of the data */ 153 inline void importData( uint8_t*& mem ) { loadAndIncrease( /*(const T&)*/this->value_, mem ); } 154 /** @brief saves data from the MT into the bytestream (mem) and increases the bytestream pointer by the size of the data */ 155 inline void exportData( uint8_t*& mem ) const { saveAndIncrease( /*(const T&)*/this->value_, mem ); } 156 /** @brief returns the size of the data that would be saved by exportData */ 157 inline uint8_t getSize() const { return returnSize( this->value_ ); } 149 158 150 159 T value_; //!< The stored value 151 160 }; 161 162 // Import / Export specialisation 163 // ColourValue 164 template <> inline void MT_Value<ColourValue>::importData( uint8_t*& mem ) 165 { 166 loadAndIncrease( this->value_.r, mem ); 167 loadAndIncrease( this->value_.g, mem ); 168 loadAndIncrease( this->value_.b, mem ); 169 loadAndIncrease( this->value_.a, mem ); 170 } 171 template <> inline void MT_Value<ColourValue>::exportData( uint8_t*& mem ) const 172 { 173 saveAndIncrease( this->value_.r, mem ); 174 saveAndIncrease( this->value_.g, mem ); 175 saveAndIncrease( this->value_.b, mem ); 176 saveAndIncrease( this->value_.a, mem ); 177 } 178 template <> inline uint8_t MT_Value<ColourValue>::getSize() const 179 { 180 return 4*returnSize(this->value_.r); 181 } 182 // Ogre::Quaternion 183 template <> inline void MT_Value<Ogre::Quaternion>::importData( uint8_t*& mem ) 184 { 185 loadAndIncrease( this->value_.x, mem ); 186 loadAndIncrease( this->value_.y, mem ); 187 loadAndIncrease( this->value_.z, mem ); 188 loadAndIncrease( this->value_.w, mem ); 189 } 190 template <> inline void MT_Value<Ogre::Quaternion>::exportData( uint8_t*& mem ) const 191 { 192 saveAndIncrease( this->value_.x, mem ); 193 saveAndIncrease( this->value_.y, mem ); 194 saveAndIncrease( this->value_.z, mem ); 195 saveAndIncrease( this->value_.w, mem ); 196 }template <> inline uint8_t MT_Value<Ogre::Quaternion>::getSize() const 197 { 198 return 4*returnSize(this->value_.x); 199 } 200 // Ogre::Vector2 201 template <> inline void MT_Value<Ogre::Vector2>::importData( uint8_t*& mem ) 202 { 203 loadAndIncrease( this->value_.x, mem ); 204 loadAndIncrease( this->value_.y, mem ); 205 } 206 template <> inline void MT_Value<Ogre::Vector2>::exportData( uint8_t*& mem ) const 207 { 208 saveAndIncrease( this->value_.x, mem ); 209 saveAndIncrease( this->value_.y, mem ); 210 } 211 template <> inline uint8_t MT_Value<Ogre::Vector2>::getSize() const 212 { 213 return 2*returnSize(this->value_.x); 214 } 215 // Ogre::Vector3 216 template <> inline void MT_Value<Ogre::Vector3>::importData( uint8_t*& mem ) 217 { 218 loadAndIncrease( this->value_.x, mem ); 219 loadAndIncrease( this->value_.y, mem ); 220 loadAndIncrease( this->value_.z, mem ); 221 } 222 template <> inline void MT_Value<Ogre::Vector3>::exportData( uint8_t*& mem ) const 223 { 224 saveAndIncrease( this->value_.x, mem ); 225 saveAndIncrease( this->value_.y, mem ); 226 saveAndIncrease( this->value_.z, mem ); 227 } 228 template <> inline uint8_t MT_Value<Ogre::Vector3>::getSize() const 229 { 230 return 3*returnSize(this->value_.x); 231 } 232 // Ogre::Vector4 233 template <> inline void MT_Value<Ogre::Vector4>::importData( uint8_t*& mem ) 234 { 235 loadAndIncrease( this->value_.x, mem ); 236 loadAndIncrease( this->value_.y, mem ); 237 loadAndIncrease( this->value_.z, mem ); 238 loadAndIncrease( this->value_.w, mem ); 239 } 240 template <> inline void MT_Value<Ogre::Vector4>::exportData( uint8_t*& mem ) const 241 { 242 saveAndIncrease( this->value_.x, mem ); 243 saveAndIncrease( this->value_.y, mem ); 244 saveAndIncrease( this->value_.z, mem ); 245 saveAndIncrease( this->value_.w, mem ); 246 } 247 template <> inline uint8_t MT_Value<Ogre::Vector4>::getSize() const 248 { 249 return 4*returnSize(this->value_.x); 250 } 251 template <> inline void MT_Value<void*>::importData( uint8_t*& mem ) 252 { 253 assert(0); 254 } 255 template <> inline void MT_Value<void*>::exportData( uint8_t*& mem ) const 256 { 257 assert(0); 258 } 259 template <> inline uint8_t MT_Value<void*>::getSize() const 260 { 261 assert(0); return 0; 262 } 152 263 } 153 264
Note: See TracChangeset
for help on using the changeset viewer.