Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
orxonox::Synchronisable Class Reference

This class is the base class of all the Objects in the universe that need to be synchronised over the network Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/network/synchronisable/Synchronisable.h>

Inheritance diagram for orxonox::Synchronisable:
orxonox::OrxonoxInterface orxonox::Configurable orxonox::Destroyable orxonox::Listable orxonox::Identifiable orxonox::CollisionShape orxonox::GlobalShader orxonox::Info orxonox::Item orxonox::Level orxonox::NotificationDispatcher orxonox::NotificationQueue orxonox::PickupRepresentation orxonox::Scene orxonox::Test orxonox::WorldAmbientSound orxonox::WorldEntity

Public Member Functions

virtual ~Synchronisable ()
 Destructor: Delete all callback objects and remove objectID_ from the objectMap_. More...
 
uint32_t getClassID () const
 
unsigned int getContextID () const
 
uint32_t getNrOfVariables ()
 
uint32_t getObjectID () const
 
unsigned int getPriority () const
 
uint8_t getSyncMode () const
 
uint32_t getVarSize (VariableID ID)
 
template<>
_NetworkExport void registerVariable (std::string &variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
 
template<>
void registerVariable (std::string &variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
 
void setSyncMode (uint8_t mode)
 This function sets the synchronisation mode of the object If set to 0x0 variables will not be synchronised at all If set to 0x1 variables will only be synchronised to the client If set to 0x2 variables will only be synchronised to the server If set to 0x3 variables will be synchronised bidirectionally (only if set so in registerVar) More...
 
template<>
_NetworkExport void unregisterVariable (std::string &variable)
 
template<>
void unregisterVariable (std::string &variable)
 
- Public Member Functions inherited from orxonox::OrxonoxInterface
 OrxonoxInterface ()
 
- Public Member Functions inherited from orxonox::Configurable
 Configurable ()
 
void setConfigValues ()
 Function to collect the SetConfigValue-macro calls. More...
 
- Public Member Functions inherited from orxonox::Listable
 Listable ()
 Constructor: Allocates space in the element list. More...
 
 Listable (Context *context)
 Constructor: Allocates space in the element list and assigns the context. More...
 
virtual ~Listable ()
 Destructor: Removes the object from the object-lists. More...
 
ContextgetContext () const
 
void setContext (Context *context)
 Changes the context. More...
 
void unregisterObject ()
 Removes this object from the object-lists. More...
 
- Public Member Functions inherited from orxonox::Identifiable
 Identifiable ()
 Constructor: Sets the default values. More...
 
virtual ~Identifiable ()
 
ORX_FORCEINLINE voidgetDerivedPointer (unsigned int classID)
 Returns a valid pointer of any derived type that is registered in the class hierarchy. More...
 
template<class T >
ORX_FORCEINLINE T * getDerivedPointer (unsigned int classID)
 Version of getDerivedPointer with template. More...
 
template<class T >
ORX_FORCEINLINE const T * getDerivedPointer (unsigned int classID) const
 Const version of getDerivedPointer with template. More...
 
IdentifiergetIdentifier () const
 Returns the Identifier of the object. More...
 
bool isA (const Identifier *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
template<class B >
bool isA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isA (const Identifiable *object)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isChildOf (const Identifier *identifier)
 Returns true if the object's class is a child of the given type. More...
 
template<class B >
bool isChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a child of the given type. More...
 
bool isChildOf (const Identifiable *object)
 Returns true if the object's class is a child of the given type. More...
 
bool isDirectChildOf (const Identifier *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
template<class B >
bool isDirectChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectChildOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectParentOf (const Identifier *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
template<class B >
bool isDirectParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
bool isDirectParentOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isExactlyA (const Identifier *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
template<class B >
bool isExactlyA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
bool isExactlyA (const Identifiable *object)
 Returns true if the object's class is exactly of the given type. More...
 
bool isParentOf (const Identifier *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
template<class B >
bool isParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
bool isParentOf (const Identifiable *object)
 Returns true if the object's class is a parent of the given type. More...
 
- Public Member Functions inherited from orxonox::Destroyable
 Destroyable ()
 Constructor: Sets the default values. More...
 
virtual ~Destroyable ()
 Destructor: Notifies all DestructionListener (for example weak pointers) that this object is being deleted. More...
 
void destroy ()
 Deletes the object if no strong pointers point to this object. More...
 
void destroyLater ()
 Works like destroy() but doesn't destroy the object until the current tick has ended. More...
 
unsigned int getReferenceCount () const
 Returns the number of strong pointers that point to this object. More...
 

Static Public Member Functions

static bool deleteObject (uint32_t objectID_)
 Finds and deletes the Synchronisable with the appropriate objectID_. More...
 
static Synchronisablefabricate (uint8_t *&mem, uint8_t mode=0x0)
 This function fabricated a new synchrnisable (and children of it), sets calls updateData and create After calling this function the mem pointer will be increased by the size of the needed data. More...
 
static unsigned int getNumberOfDeletedObject ()
 
static SynchronisablegetSynchronisable (uint32_t objectID_)
 This function looks up the objectID_ in the objectMap_ and returns a pointer to the right Synchronisable. More...
 
static uint32_t popDeletedObject ()
 
static void setClient (bool b)
 This function sets the internal mode for synchronisation. More...
 

Protected Member Functions

 Synchronisable (Context *context)
 Constructor: Initializes all Variables and sets the right objectID_. More...
 
uint32_t findContextID (Context *context)
 Returns the id of the context. More...
 
template<class T >
void registerVariable (T &variable, uint8_t mode=0x1, NetworkCallbackBase *cb=nullptr, bool bidirectional=false)
 
template<class T >
void registerVariable (std::set< T > &variable, uint8_t mode=0x1, NetworkCallbackBase *cb=nullptr, bool bidirectional=false)
 
void setPriority (unsigned int freq)
 
template<class T >
void unregisterVariable (T &var)
 
- Protected Member Functions inherited from orxonox::Destroyable
virtual void preDestroy ()
 This virtual function is called if destroy() is called and no StrongPtr points to this object. More...
 

Private Member Functions

bool doReceive (uint8_t mode)
 This function determines, wheter the object should accept data from the bytestream (according to its syncmode/direction) More...
 
bool doSync (uint8_t mode=0x0)
 This function determines, wheter the object should be saved to the bytestream (according to its syncmode/direction) More...
 
uint32_t getData (uint8_t *&mem, std::vector< uint32_t > &sizes, int32_t id, uint8_t mode)
 This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID_ and classID_ to the given memory takes a pointer to already allocated memory (must have at least getSize bytes length) structure of the bitstream: |totalsize,objectID_,classID_,var1,var2,string1_length,string1,var3,...| length of varx: size saved int syncvarlist. More...
 
uint32_t getSize (int32_t id, uint8_t mode=0x0)
 This function returns the total amount of bytes needed by getData to save the whole content of the variables. More...
 
void setClassID (uint32_t id)
 
void setObjectID (uint32_t id)
 
bool updateData (uint8_t *&mem, uint8_t mode=0x0, bool forceCallback=false)
 This function takes a bytestream and loads the data into the registered variables. More...
 

Private Attributes

bool backsync_
 
uint32_t classID_
 
uint32_t contextID_
 
uint32_t dataSize_
 
unsigned int objectFrequency_
 
uint32_t objectID_
 
int objectMode_
 
std::vector< SynchronisableVariableBase * > stringList_
 
std::vector< SynchronisableVariableBase * > syncList_
 

Static Private Attributes

static std::queue< uint32_t > deletedObjects_
 
static std::map< uint32_t, Synchronisable * > objectMap_
 
static uint8_t state_ =0x1
 

Friends

class packet::Gamestate
 

Detailed Description

This class is the base class of all the Objects in the universe that need to be synchronised over the network Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list.

Author
Oliver Scheuss

Constructor & Destructor Documentation

orxonox::Synchronisable::~Synchronisable ( )
virtual

Destructor: Delete all callback objects and remove objectID_ from the objectMap_.

orxonox::Synchronisable::Synchronisable ( Context context)
protected

Constructor: Initializes all Variables and sets the right objectID_.

Member Function Documentation

bool orxonox::Synchronisable::deleteObject ( uint32_t  objectID_)
static

Finds and deletes the Synchronisable with the appropriate objectID_.

Parameters
objectID_objectID_ of the Synchronisable
Returns
true/false
bool orxonox::Synchronisable::doReceive ( uint8_t  mode)
private

This function determines, wheter the object should accept data from the bytestream (according to its syncmode/direction)

Parameters
modeSynchronisation mode (toclient, toserver or bidirectional)
Returns
true/false
bool orxonox::Synchronisable::doSync ( uint8_t  mode = 0x0)
private

This function determines, wheter the object should be saved to the bytestream (according to its syncmode/direction)

Parameters
modeSynchronisation mode (toclient, toserver or bidirectional)
Returns
true/false
Synchronisable * orxonox::Synchronisable::fabricate ( uint8_t *&  mem,
uint8_t  mode = 0x0 
)
static

This function fabricated a new synchrnisable (and children of it), sets calls updateData and create After calling this function the mem pointer will be increased by the size of the needed data.

Parameters
mempointer to where the appropriate data is located
modedefines the mode, how the data should be loaded
Returns
pointer to the newly created synchronisable
uint32_t orxonox::Synchronisable::findContextID ( Context context)
protected

Returns the id of the context.

If the context is not Synchronisable, it moves on to its parent, recursively.

uint32_t orxonox::Synchronisable::getClassID ( ) const
inline
unsigned int orxonox::Synchronisable::getContextID ( ) const
inline
uint32_t orxonox::Synchronisable::getData ( uint8_t *&  mem,
std::vector< uint32_t > &  sizes,
int32_t  id,
uint8_t  mode 
)
private

This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID_ and classID_ to the given memory takes a pointer to already allocated memory (must have at least getSize bytes length) structure of the bitstream: |totalsize,objectID_,classID_,var1,var2,string1_length,string1,var3,...| length of varx: size saved int syncvarlist.

Parameters
mempointer to allocated memory with enough size
sizesvector containing sizes of all objects in gamestate (to be appended)
idgamestateid of the gamestate to be saved (important for priorities)
modedefines the direction in which the data will be send/received 0x1: server->client 0x2: client->server 0x3: bidirectional
Returns
true: if !doSync or if everything was successfully saved
uint32_t orxonox::Synchronisable::getNrOfVariables ( )
inline
static unsigned int orxonox::Synchronisable::getNumberOfDeletedObject ( )
inlinestatic
uint32_t orxonox::Synchronisable::getObjectID ( ) const
inline
unsigned int orxonox::Synchronisable::getPriority ( ) const
inline
uint32_t orxonox::Synchronisable::getSize ( int32_t  id,
uint8_t  mode = 0x0 
)
private

This function returns the total amount of bytes needed by getData to save the whole content of the variables.

Parameters
idid of the gamestate
modesame as getData
Returns
amount of bytes
Synchronisable * orxonox::Synchronisable::getSynchronisable ( uint32_t  objectID_)
static

This function looks up the objectID_ in the objectMap_ and returns a pointer to the right Synchronisable.

Parameters
objectID_objectID_ of the Synchronisable
Returns
pointer to the Synchronisable with the objectID_
uint8_t orxonox::Synchronisable::getSyncMode ( ) const
inline
uint32_t orxonox::Synchronisable::getVarSize ( VariableID  ID)
inline
static uint32_t orxonox::Synchronisable::popDeletedObject ( )
inlinestatic
template<class T >
void orxonox::Synchronisable::registerVariable ( T &  variable,
uint8_t  mode = 0x1,
NetworkCallbackBase cb = nullptr,
bool  bidirectional = false 
)
protected
template<class T >
void orxonox::Synchronisable::registerVariable ( std::set< T > &  variable,
uint8_t  mode = 0x1,
NetworkCallbackBase cb = nullptr,
bool  bidirectional = false 
)
protected
template<>
_NetworkExport void orxonox::Synchronisable::registerVariable ( std::string &  variable,
uint8_t  mode,
NetworkCallbackBase cb,
bool  bidirectional 
)
template<>
void orxonox::Synchronisable::registerVariable ( std::string &  variable,
uint8_t  mode,
NetworkCallbackBase cb,
bool  bidirectional 
)
void orxonox::Synchronisable::setClassID ( uint32_t  id)
inlineprivate
void orxonox::Synchronisable::setClient ( bool  b)
static

This function sets the internal mode for synchronisation.

Parameters
btrue if this object is located on a client or on a server
void orxonox::Synchronisable::setObjectID ( uint32_t  id)
inlineprivate
void orxonox::Synchronisable::setPriority ( unsigned int  freq)
inlineprotected
void orxonox::Synchronisable::setSyncMode ( uint8_t  mode)

This function sets the synchronisation mode of the object If set to 0x0 variables will not be synchronised at all If set to 0x1 variables will only be synchronised to the client If set to 0x2 variables will only be synchronised to the server If set to 0x3 variables will be synchronised bidirectionally (only if set so in registerVar)

Parameters
modesame as in registerVar
template<class T >
void orxonox::Synchronisable::unregisterVariable ( T &  var)
protected
template<>
_NetworkExport void orxonox::Synchronisable::unregisterVariable ( std::string &  variable)
template<>
void orxonox::Synchronisable::unregisterVariable ( std::string &  variable)
bool orxonox::Synchronisable::updateData ( uint8_t *&  mem,
uint8_t  mode = 0x0,
bool  forceCallback = false 
)
private

This function takes a bytestream and loads the data into the registered variables.

Parameters
mempointer to the bytestream
modesame as in getData
forceCallbackthis makes updateData call each callback
Returns
true/false

Friends And Related Function Documentation

friend class packet::Gamestate
friend

Member Data Documentation

bool orxonox::Synchronisable::backsync_
private
uint32_t orxonox::Synchronisable::classID_
private
uint32_t orxonox::Synchronisable::contextID_
private
uint32_t orxonox::Synchronisable::dataSize_
private
std::queue< uint32_t > orxonox::Synchronisable::deletedObjects_
staticprivate
unsigned int orxonox::Synchronisable::objectFrequency_
private
uint32_t orxonox::Synchronisable::objectID_
private
std::map< uint32_t, Synchronisable * > orxonox::Synchronisable::objectMap_
staticprivate
int orxonox::Synchronisable::objectMode_
private
uint8_t orxonox::Synchronisable::state_ =0x1
staticprivate
std::vector<SynchronisableVariableBase*> orxonox::Synchronisable::stringList_
private
std::vector<SynchronisableVariableBase*> orxonox::Synchronisable::syncList_
private

The documentation for this class was generated from the following files: