Changeset 9667 for code/trunk/src/libraries/network/synchronisable
- Timestamp:
- Aug 25, 2013, 9:08:42 PM (11 years ago)
- Location:
- code/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core6 merged: 9552-9554,9556-9574,9577-9579,9585-9593,9596-9612,9626-9662
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/synchronisable/Serialise.h
r8706 r9667 41 41 #include "util/Serialise.h" 42 42 #include "core/CorePrereqs.h" 43 #include "core/CoreIncludes.h"44 #include "core/BaseObject.h" // remove this if circular dependencies in BaseObject/SmartPtr are fixed45 //#include "core/SmartPtr.h"46 43 47 44 namespace orxonox{ -
code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
r8858 r9667 45 45 uint8_t Synchronisable::state_=0x1; // detemines wheter we are server (default) or client 46 46 47 RegisterAbstractClass(Synchronisable).inheritsFrom(Class(OrxonoxInterface)); 48 47 49 /** 48 50 * Constructor: 49 51 * Initializes all Variables and sets the right objectID_ 50 52 */ 51 Synchronisable::Synchronisable( BaseObject* creator)52 { 53 RegisterRootObject(Synchronisable);53 Synchronisable::Synchronisable(Context* context) 54 { 55 RegisterObject(Synchronisable); 54 56 static uint32_t idCounter=0; 55 57 objectMode_=0x1; // by default do not send data to server … … 69 71 this->setPriority( Priority::Normal ); 70 72 71 // get creator id 72 if( creator ) 73 this->creatorID_ = creator->getSceneID(); 74 else 75 this->creatorID_ = OBJECTID_UNKNOWN; 73 // get context id 74 this->contextID_ = this->findContextID(context); 76 75 } 77 76 … … 83 82 { 84 83 // delete callback function objects 85 if(!Identifier ::isCreatingHierarchy()){84 if(!IdentifierManager::getInstance().isCreatingHierarchy()){ 86 85 // remove object from the static objectMap 87 86 if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer())) … … 100 99 } 101 100 101 /** 102 * @brief Returns the id of the context. 103 * If the context is not Synchronisable, it moves on to its parent, recursively. 104 */ 105 uint32_t Synchronisable::findContextID(Context* context) 106 { 107 if (context == NULL) 108 return OBJECTID_UNKNOWN; 109 110 Synchronisable* synchronisableContext = orxonox_cast<Synchronisable*>(context); 111 if (synchronisableContext != NULL) 112 return synchronisableContext->getObjectID(); 113 else 114 return this->findContextID(context->getParentContext()); 115 } 102 116 103 117 /** … … 142 156 } 143 157 assert(id); 144 BaseObject* creator= 0;145 if (header.getC reatorID() != OBJECTID_UNKNOWN)146 { 147 Synchronisable* synchronisable_c reator = Synchronisable::getSynchronisable(header.getCreatorID());148 if (!synchronisable_c reator)158 Context* context = 0; 159 if (header.getContextID() != OBJECTID_UNKNOWN) 160 { 161 Synchronisable* synchronisable_context = Synchronisable::getSynchronisable(header.getContextID()); 162 if (!synchronisable_context) 149 163 { 150 164 mem += header.getDataSize()+SynchronisableHeader::getSize(); //.TODO: this suckz.... remove size from header … … 153 167 } 154 168 else 155 creator = orxonox_cast<BaseObject*>(synchronisable_creator); 156 } 169 context = orxonox_cast<Context*>(synchronisable_context); 170 } 171 else 172 context = Context::getRootContext(); 173 157 174 assert(getSynchronisable(header.getObjectID())==0); //make sure no object with this id exists 158 BaseObject *bo = id->fabricate(creator);175 BaseObject *bo = orxonox_cast<BaseObject*>(id->fabricate(context)); 159 176 assert(bo); 160 177 Synchronisable *no = orxonox_cast<Synchronisable*>(bo); … … 162 179 assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() ); 163 180 no->setObjectID(header.getObjectID()); 164 //no->c reatorID=header.getCreatorID(); //TODO: remove this181 //no->contextID=header.getContextID(); //TODO: remove this 165 182 no->setClassID(header.getClassID()); 166 assert(no->creatorID_ == header.getCreatorID()); 167 if( creator ) 168 bo->setLevel(creator->getLevel()); // Note: this ensures that the level is known on the client for child objects of the scene (and the scene itself) 183 assert(no->contextID_ == header.getContextID()); 184 if( context ) 185 { 186 BaseObject* boContext = orxonox_cast<BaseObject*>(context); 187 if (boContext) 188 bo->setLevel(boContext->getLevel()); // Note: this ensures that the level is known on the client for child objects of the scene (and the scene itself) 189 } 169 190 //assert(no->classID_ == header.getClassID()); 170 191 orxout(verbose, context::network) << "fabricate objectID_: " << no->objectID_ << " classID_: " << no->classID_ << endl; … … 274 295 275 296 header.setObjectID( this->objectID_ ); 276 header.setC reatorID( this->creatorID_ );297 header.setContextID( this->contextID_ ); 277 298 header.setClassID( this->classID_ ); 278 299 header.setDataSize( tempsize ); … … 331 352 SynchronisableHeader syncHeader2(mem); 332 353 assert( this->getClassID() == syncHeader2.getClassID() ); 333 assert( this->getC reatorID() == syncHeader2.getCreatorID() );354 assert( this->getContextID() == syncHeader2.getContextID() ); 334 355 mem += SynchronisableHeader::getSize(); 335 356 std::vector<SynchronisableVariableBase *>::iterator i; -
code/trunk/src/libraries/network/synchronisable/Synchronisable.h
r8858 r9667 40 40 41 41 #include "util/mbool.h" 42 #include "core/OrxonoxClass.h" 42 #include "util/Output.h" 43 #include "core/class/OrxonoxInterface.h" 43 44 #include "SynchronisableVariable.h" 44 45 #include "NetworkCallback.h" … … 106 107 * @brief: stores information about a Synchronisable 107 108 * 108 * This class stores the information about a Synchronisable (objectID_, classID_, c reatorID_, dataSize)109 * This class stores the information about a Synchronisable (objectID_, classID_, contextID_, dataSize) 109 110 * in an emulated bitset. 110 111 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream … … 112 113 * Byte 5 to 8: objectID_ 113 114 * Byte 9 to 12: classID_ 114 * Byte 13 to 16: c reatorID_115 * Byte 13 to 16: contextID_ 115 116 */ 116 117 class _NetworkExport SynchronisableHeader: public SynchronisableHeaderLight … … 125 126 inline void setClassID(uint32_t classID_) 126 127 { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()) = classID_; } 127 inline uint32_t getC reatorID() const128 inline uint32_t getContextID() const 128 129 { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4); } 129 inline void setC reatorID(uint32_t creatorID_)130 { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4) = c reatorID_; }130 inline void setContextID(uint32_t contextID_) 131 { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4) = contextID_; } 131 132 inline void operator=(SynchronisableHeader& h) 132 133 { memcpy(data_, h.data_, getSize()); } … … 143 144 * @author Oliver Scheuss 144 145 */ 145 class _NetworkExport Synchronisable : virtual public Orxonox Class{146 class _NetworkExport Synchronisable : virtual public OrxonoxInterface { 146 147 public: 147 148 friend class packet::Gamestate; … … 157 158 158 159 inline uint32_t getObjectID() const {return this->objectID_;} 159 inline unsigned int getC reatorID() const {return this->creatorID_;}160 inline unsigned int getContextID() const {return this->contextID_;} 160 161 inline uint32_t getClassID() const {return this->classID_;} 161 162 inline unsigned int getPriority() const { return this->objectFrequency_;} … … 169 170 170 171 protected: 171 Synchronisable( BaseObject* creator);172 Synchronisable(Context* context); 172 173 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false); 173 174 template <class T> void registerVariable(std::set<T>& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false); … … 175 176 176 177 void setPriority(unsigned int freq){ objectFrequency_ = freq; } 177 178 uint32_t findContextID(Context* context); 178 179 179 180 private: … … 188 189 189 190 uint32_t objectID_; 190 uint32_t c reatorID_;191 uint32_t contextID_; 191 192 uint32_t classID_; 192 193
Note: See TracChangeset
for help on using the changeset viewer.