29 #ifndef _Synchronisable_H__ 30 #define _Synchronisable_H__ 40 #include <type_traits> 52 namespace ObjectDirection{
90 {
return (*(uint16_t*)data_) & 0x7FFF; }
92 { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); }
94 {
return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }
96 { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); }
98 {
return *(uint32_t*)(data_+2); }
100 { *(uint32_t*)(data_+2) = objectID_; }
134 { memcpy(data_, h.
data_, getSize()); }
147 static void setClient(
bool b);
149 static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);
150 static bool deleteObject(uint32_t objectID_);
153 static uint32_t
popDeletedObject(){ uint32_t i = deletedObjects_.front(); deletedObjects_.pop();
return i; }
158 inline unsigned int getPriority()
const {
return this->objectFrequency_;}
161 void setSyncMode(uint8_t mode);
165 {
return this->syncList_[ID]->getSize(state_); }
169 template <
class T>
void registerVariable(
T& variable, uint8_t mode=0x1,
NetworkCallbackBase *cb=
nullptr,
bool bidirectional=
false);
170 template <
class T>
void registerVariable(std::set<T>& variable, uint8_t mode=0x1,
NetworkCallbackBase *cb=
nullptr,
bool bidirectional=
false);
171 template <
class T>
void unregisterVariable(
T& var);
174 uint32_t findContextID(
Context* context);
177 uint32_t getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t
id, uint8_t mode);
178 uint32_t getSize(int32_t
id, uint8_t mode=0x0);
179 bool updateData(uint8_t*& mem, uint8_t mode=0x0,
bool forceCallback=
false);
180 bool doSync( uint8_t mode=0x0);
181 bool doReceive( uint8_t mode );
183 inline void setObjectID(uint32_t
id){ this->objectID_ = id; objectMap_[this->objectID_] =
this; }
203 template <class T, bool = std::is_enum<T>::value>
204 struct UnderlyingType;
206 struct UnderlyingType<T, true> {
typedef typename std::underlying_type<T>::type type; };
208 struct UnderlyingType<T, false> {
typedef T type; };
214 typedef typename detail::UnderlyingType<T>::type UnderlyingType;
218 this->dataSize_ += syncList_.back()->getSize(state_);
223 if ( this->state_ == mode )
224 this->dataSize_ += syncList_.back()->getSize(state_);
231 std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin();
232 while(it!=syncList_.end())
234 if( ((*it)->getReference()) == &variable )
244 orxout(
internal_error, context::network) <<
"Tried to unregister not registered variable" << endl;
252 typedef typename detail::UnderlyingType<T>::type UnderlyingType;
258 syncList_.push_back(sv);
259 stringList_.push_back(sv);
Definition: SynchronisableVariable.h:58
void registerVariable(T &variable, uint8_t mode=0x1, NetworkCallbackBase *cb=nullptr, bool bidirectional=false)
Definition: Synchronisable.h:212
Definition: Synchronisable.h:65
Shared library macros, enums, constants and forward declarations for the network library ...
Definition: Synchronisable.h:56
This class is the base class of all the Objects in the universe that need to be synchronised over the...
Definition: Synchronisable.h:142
static uint8_t state_
Definition: Synchronisable.h:193
uint8_t VariableID
Definition: Synchronisable.h:105
void unregisterVariable(T &var)
Definition: Synchronisable.h:229
::std::string string
Definition: gtest-port.h:756
static uint32_t popDeletedObject()
Definition: Synchronisable.h:153
uint32_t getClassID() const
Definition: Synchronisable.h:157
Definition: Synchronisable.h:54
Definition: Synchronisable.h:57
Definition: Synchronisable.h:64
Definition: NetworkPrereqs.h:177
Definition: Synchronisable.h:66
uint32_t contextID_
Definition: Synchronisable.h:187
std::vector< SynchronisableVariableBase * > syncList_
Definition: Synchronisable.h:190
This is the class from which all interfaces of the game-logic (not the engine) are derived from...
Definition: OrxonoxInterface.h:50
uint32_t getNrOfVariables()
Definition: Synchronisable.h:163
static std::map< uint32_t, Synchronisable * > objectMap_
Definition: Synchronisable.h:197
Output level, used for error messages which are important for developers.
Definition: OutputDefinitions.h:95
uint8_t getSyncMode() const
Definition: Synchronisable.h:159
uint32_t classID_
Definition: Synchronisable.h:188
Definition: Synchronisable.h:67
uint32_t getObjectID() const
Definition: Synchronisable.h:155
Definition: Gamestate.h:109
unsigned int getPriority() const
Definition: Synchronisable.h:158
OutputStream & orxout(OutputLevel level=level::debug_output, const OutputContextContainer &context=context::undefined())
This helper function returns a reference to a commonly used instance of OutputStream.
Definition: Output.h:81
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Definition: Synchronisable.h:55
static std::queue< uint32_t > deletedObjects_
Definition: Synchronisable.h:198
#define _NetworkExport
Definition: NetworkPrereqs.h:59
Declaration of OrxonoxInterface, the base class of all interfaces in Orxonox.
Value
Definition: Synchronisable.h:53
void setClassID(uint32_t id)
Definition: Synchronisable.h:184
Defines the helper function orxout() and includes all necessary headers to use the output system...
Declaration and implementation of the orxonox::mbool class.
Definition: InputPrereqs.h:78
Definition: Synchronisable.h:63
Definition: NetworkPrereqs.h:174
unsigned int getContextID() const
Definition: Synchronisable.h:156
std::vector< SynchronisableVariableBase * > stringList_
Definition: Synchronisable.h:191
uint32_t dataSize_
Definition: Synchronisable.h:192
int objectMode_
Definition: Synchronisable.h:196
void setPriority(unsigned int freq)
Definition: Synchronisable.h:173
uint32_t objectID_
Definition: Synchronisable.h:186
uint32_t getVarSize(VariableID ID)
Definition: Synchronisable.h:164
Value
Definition: Synchronisable.h:62
void setObjectID(uint32_t id)
Definition: Synchronisable.h:183
bool backsync_
Definition: Synchronisable.h:194
static unsigned int getNumberOfDeletedObject()
Definition: Synchronisable.h:152
Definition: NetworkCallback.h:41
unsigned int objectFrequency_
Definition: Synchronisable.h:195