Changeset 6192
- Timestamp:
- Dec 2, 2009, 11:35:24 AM (15 years ago)
- Location:
- code/branches/presentation2/src
- Files:
-
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/network/NetworkPrereqs.h
r5929 r6192 144 144 template <class T> 145 145 class NetworkCallback; 146 template <class T, class U> 147 class NetworkCallbackNotify; 146 148 class NetworkCallbackBase; 147 149 class NetworkCallbackManager; -
code/branches/presentation2/src/libraries/network/packet/DeleteObjects.cc
r5781 r6192 71 71 for(unsigned int i=0; i<number; i++){ 72 72 unsigned int temp = Synchronisable::popDeletedObject(); 73 // assert(temp<10000); //ugly hack74 73 *reinterpret_cast<uint32_t*>(tdata) = temp; 75 74 COUT(4) << temp << " "; -
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 -
code/branches/presentation2/src/libraries/util/Serialise.h
r6123 r6192 37 37 #include <cstring> 38 38 #include "util/Math.h" 39 #include "util/mbool.h" 39 40 40 41 namespace orxonox{ … … 374 375 double temp; 375 376 memcpy(&temp, mem, sizeof(uint64_t)); 376 *(long double*)( &variable ) = static_cast< constlong double>(temp);377 *(long double*)( &variable ) = static_cast<long double>(temp); 377 378 mem += returnSize( variable ); 378 379 } … … 469 470 return variable==Degree(*r); 470 471 } 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 } 471 635 } 472 636 -
code/branches/presentation2/src/orxonox/infos/PlayerInfo.cc
r6108 r6192 218 218 ControllableEntity* entity = this->controllableEntity_; 219 219 220 if (!entity || !this->oldControllableEntity_) 220 assert( this->controllableEntity_ && this->oldControllableEntity_ ); 221 if( !entity || !this->oldControllableEntity_ ) 221 222 return; 222 223
Note: See TracChangeset
for help on using the changeset viewer.