TrueReality  v0.1.1912
trManager::EntityBase Class Referenceabstract

This serves as the base class for the Entity class and removes a circular dependency between Entity and System Manager. More...

#include <EntityBase.h>

Inheritance diagram for trManager::EntityBase:
Collaboration diagram for trManager::EntityBase:

Public Types

using BaseClass = trBase::Base
 
- Public Types inherited from trBase::Base
using BaseClass = trBase::SmrtClass
 
- Public Types inherited from trBase::SmrtClass
using BaseClass = osg::Referenced
 

Public Member Functions

 EntityBase (const std::string &name=CLASS_TYPE)
 Invokable for Tick Remote messages. More...
 
virtual const std::string & GetType () const override=0
 Returns the class type. More...
 
const EntityTypeGetEntityType ()
 Returns the Entity Type, which is usually a Director, Actor, or an Actor module. More...
 
virtual void SetSystemManager (trManager::SystemManager *sysMan)
 This method is used by the System Manager to pass the Entity an instance if itself when it is registered. More...
 
virtual void OnAddedToSysMan ()
 Called by the System Manager when EntityBase Registration is complete. More...
 
virtual void OnRemovedFromSysMan ()
 Called by the System Manager after removing and Unregistering the EntityBase. More...
 
virtual const bool & IsRegistered ()
 Returns True if the Instance is registered with a System Manager. More...
 
virtual void SetRegistration (bool isRegistered)
 Is set to True by the System Manager when the class instance is registered with it. More...
 
virtual void AddInvokable (trManager::Invokable &newInvokable)
 Adds an invokable that can receive a message. More...
 
virtual void RemoveInvokable (trManager::Invokable *invokable)
 Removes the invokable that is passed in. More...
 
virtual void RemoveInvokable (const std::string &invokableName)
 Removes the invokable described by invokableName. More...
 
trManager::InvokableGetInvokable (const std::string &name)
 Gets a registered invokable. More...
 
void GetInvokables (std::vector< trManager::Invokable *> &toFill)
 Gets the list of invokables. More...
 
void GetInvokables (std::vector< const trManager::Invokable *> &toFill) const
 Gets the invokables. More...
 
virtual void OnTick (const trManager::MessageBase &msg)=0
 Convenience function that will receive Tick Messages from the System Manager This does not happen automatically, each class needs to register for the message. More...
 
virtual void OnTickRemote (const trManager::MessageBase &msg)=0
 Convenience function that will receive a Network Tick Message from the System Manager This does not happen automatically, each class needs to register for the message. More...
 
virtual bool AddChild (trManager::EntityBase &child)
 Adds a child to this Entity. More...
 
virtual bool RemoveChild (trManager::EntityBase &child)
 Removes the child from this Entity. More...
 
virtual bool RemoveAllChildren ()
 Removes all of the entities children . More...
 
virtual std::vector< trBase::SmrtPtr< trManager::EntityBase > > * GetChildren ()
 
virtual const std::vector< trBase::SmrtPtr< trManager::EntityBase > > * GetChildren () const
 
virtual const trManager::EntityBaseFindChild (const trBase::UniqueId &childId)
 Finds a child of this Entity in the children list. More...
 
virtual int GetNumOfChildren ()
 Gets the children of this Entity has. More...
 
virtual void SetParent (trManager::EntityBase &parent)
 Sets the hierarchal parent of this Entity. More...
 
virtual void ForgetParent ()
 Forgets the hierarchal parent of this Entiry. More...
 
trManager::EntityBaseGetParent ()
 Gets the parent of this hierarchal Entity. More...
 
const trManager::EntityBaseGetParent () const
 Gets the parent of this hierarchal Entity. More...
 
virtual void OnParentRemoved (trManager::EntityBase &parent)
 Convenience function that will be called by the system when the Entities parent is removed. More...
 
virtual void OnParentSet (trManager::EntityBase &parent)
 Convenience function that will be called by the system when a new parent is added or set to the Entity. More...
 
virtual void Emancipate ()
 Removes the hierarchal parent of this Entity, and removes this Entity from the parent. More...
 
virtual bool RemoveFromHierarchy ()
 Removes from this entity from the hierarchy tree attaching its children to its parent. More...
 
- Public Member Functions inherited from trBase::Base
 Base (const std::string &name=CLASS_TYPE)
 Holds the class type name for efficient comparisons. More...
 
virtual void SetName (const std::string &name)
 Sets this instances name. More...
 
virtual const std::string & GetName ()
 Returns this instances name. More...
 
virtual const std::string & GetName () const
 Returns this instances name. More...
 
virtual void SetUUID (const trBase::UniqueId &id)
 Overwrites the default internal UUID with the passed in one. More...
 
virtual const trBase::UniqueIdGetUUID (void)
 Returns the instances Universally Unique ID. More...
 
- Public Member Functions inherited from trBase::SmrtClass
 SmrtClass ()
 Adds an easy and swappable access to the base class. More...
 
 SmrtClass (bool threadSafeRefUnref)
 Constructor. More...
 
 SmrtClass (const SmrtClass &inst)
 Copy constructor. More...
 
virtual bool GetThreadSafeRefUnref ()
 Get whether a mutex is used to ensure Ref() and UnRef() are thread safe. More...
 
OpenThreads::Mutex * GetRefMutex () const
 Get the mutex used to ensure thread safety of Ref()/UnRef(). More...
 
int Ref () const
 Increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
int Unref () const
 Decrement the reference count by one, indicating that a pointer to this object is no longer referencing it. More...
 
int UnRefNoDelete () const
 Decrement the reference count by one, indicating that a pointer to this object is no longer referencing it. More...
 
int ReferenceCount () const
 Return the number of pointers currently referencing this object. More...
 

Static Public Attributes

static const trUtil::RefStr CLASS_TYPE
 Adds an easy and swappable access to the base class. More...
 
static const trUtil::RefStr ON_MESSAGE_INVOKABLE
 Holds the class type name for efficient comparisons. More...
 
static const trUtil::RefStr ON_TICK_INVOKABLE
 Invokable for general messages. More...
 
static const trUtil::RefStr ON_TICK_REMOTE_INVOKABLE
 Invokable for Tick messages. More...
 
- Static Public Attributes inherited from trBase::Base
static const trUtil::RefStr CLASS_TYPE = trUtil::RefStr("trBase::Base")
 Adds an easy and swappable access to the base class. More...
 

Protected Member Functions

 ~EntityBase ()
 
- Protected Member Functions inherited from trBase::Base
 ~Base ()
 Base destructor. More...
 
- Protected Member Functions inherited from trBase::SmrtClass
 ~SmrtClass ()
 

Protected Attributes

trBase::ObsrvrPtr< trManager::SystemManagermSysMan
 
trUtil::EnumerationPointer< const trManager::EntityTypemEntityType
 
trUtil::HashMap< std::string, trBase::SmrtPtr< trManager::Invokable > > mInvokables
 

Private Attributes

bool mIsRegistered = false
 
std::vector< trBase::SmrtPtr< trManager::EntityBase > > mChildren
 
trBase::SmrtPtr< trManager::EntityBasemParent
 

Additional Inherited Members

- Static Public Member Functions inherited from trBase::SmrtClass
static OpenThreads::Mutex * GetGlobalReferencedMutex ()
 Get the optional global Referenced mutex, this can be shared between all trBase::SmrtClass. More...
 

Detailed Description

This serves as the base class for the Entity class and removes a circular dependency between Entity and System Manager.

Definition at line 46 of file EntityBase.h.

Member Typedef Documentation

◆ BaseClass

Definition at line 50 of file EntityBase.h.

Constructor & Destructor Documentation

◆ EntityBase()

trManager::EntityBase::EntityBase ( const std::string &  name = CLASS_TYPE)

Invokable for Tick Remote messages.

Constructor.

Parameters
name(Optional) The name.

Definition at line 36 of file EntityBase.cpp.

References trManager::EntityType::INVALID, and mEntityType.

◆ ~EntityBase()

trManager::EntityBase::~EntityBase ( )
protected

Definition at line 337 of file EntityBase.cpp.

Member Function Documentation

◆ AddChild()

bool trManager::EntityBase::AddChild ( trManager::EntityBase child)
virtual

Adds a child to this Entity.

Parameters
[in,out]childThe child.
Returns
True if it succeeds, false if it fails.

Definition at line 143 of file EntityBase.cpp.

References trManager::EntityType::ACTOR, GetEntityType(), trUtil::EnumerationString::GetName(), trBase::Base::GetName(), GetParent(), LOG_E, mChildren, and SetParent().

Referenced by RemoveFromHierarchy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddInvokable()

void trManager::EntityBase::AddInvokable ( trManager::Invokable newInvokable)
virtual

Adds an invokable that can receive a message.

Parameters
[in,out]newInvokableThe new invokable.

Definition at line 66 of file EntityBase.cpp.

References trBase::Base::GetName(), trManager::Invokable::GetName(), LOG_D, LOG_W, and mInvokables.

Referenced by trManager::DirectorBase::BuildInvokables(), and trManager::ActorBase::BuildInvokables().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Emancipate()

void trManager::EntityBase::Emancipate ( )
virtual

Removes the hierarchal parent of this Entity, and removes this Entity from the parent.

Parameters
[in,out]parentThe parent.

Definition at line 286 of file EntityBase.cpp.

References ForgetParent(), trBase::Base::GetName(), LOG_W, mParent, RemoveChild(), and trBase::SmrtPtr< T >::Valid().

Referenced by RemoveChild().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindChild()

const trManager::EntityBase * trManager::EntityBase::FindChild ( const trBase::UniqueId childId)
virtual

Finds a child of this Entity in the children list.

Parameters
childIdIdentifier for the child.
Returns
Null if it fails, else the found child.

Definition at line 214 of file EntityBase.cpp.

References trBase::Base::GetUUID(), and mChildren.

Here is the call graph for this function:

◆ ForgetParent()

void trManager::EntityBase::ForgetParent ( )
virtual

Forgets the hierarchal parent of this Entiry.

This is for system use only. Used Emancipate() if you want to disconnect your entity.

Definition at line 253 of file EntityBase.cpp.

References mParent, and OnParentRemoved().

Referenced by Emancipate(), and RemoveFromHierarchy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetChildren() [1/2]

std::vector< trBase::SmrtPtr< trManager::EntityBase > > * trManager::EntityBase::GetChildren ( )
virtual

Definition at line 202 of file EntityBase.cpp.

References mChildren.

◆ GetChildren() [2/2]

const std::vector< trBase::SmrtPtr< trManager::EntityBase > > * trManager::EntityBase::GetChildren ( ) const
virtual

Definition at line 208 of file EntityBase.cpp.

References mChildren.

◆ GetEntityType()

◆ GetInvokable()

trManager::Invokable * trManager::EntityBase::GetInvokable ( const std::string &  name)

Gets a registered invokable.

Parameters
nameThe name.
Returns
Null if it fails, else the invokable.

Definition at line 102 of file EntityBase.cpp.

References mInvokables.

Referenced by trManager::SystemManager::CallInvokable(), and trManager::SystemManager::SendGlobalyRegisteredMessage().

Here is the caller graph for this function:

◆ GetInvokables() [1/2]

void trManager::EntityBase::GetInvokables ( std::vector< trManager::Invokable *> &  toFill)

Gets the list of invokables.

Parameters
[in,out]toFill[in,out] If non-null, to fill.

Definition at line 117 of file EntityBase.cpp.

References mInvokables.

◆ GetInvokables() [2/2]

void trManager::EntityBase::GetInvokables ( std::vector< const trManager::Invokable *> &  toFill) const

Gets the invokables.

Parameters
toFillto fill.

Definition at line 130 of file EntityBase.cpp.

References mInvokables.

◆ GetNumOfChildren()

int trManager::EntityBase::GetNumOfChildren ( )
virtual

Gets the children of this Entity has.

Returns
The number of children.

Definition at line 230 of file EntityBase.cpp.

References mChildren.

◆ GetParent() [1/2]

trManager::EntityBase * trManager::EntityBase::GetParent ( )

Gets the parent of this hierarchal Entity.

Returns
Null if it fails, else the parent.

Definition at line 264 of file EntityBase.cpp.

References trBase::SmrtPtr< T >::Get(), and mParent.

Referenced by AddChild(), and RemoveChild().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetParent() [2/2]

const trManager::EntityBase * trManager::EntityBase::GetParent ( ) const

Gets the parent of this hierarchal Entity.

Returns
Null if it fails, else the parent.

Definition at line 270 of file EntityBase.cpp.

References trBase::SmrtPtr< T >::Get(), and mParent.

Here is the call graph for this function:

◆ GetType()

const std::string & trManager::EntityBase::GetType ( ) const
overridepure virtual

◆ IsRegistered()

◆ OnAddedToSysMan()

void trManager::EntityBase::OnAddedToSysMan ( )
inlinevirtual

Called by the System Manager when EntityBase Registration is complete.

Reimplemented in trManager::ActorBase.

Definition at line 100 of file EntityBase.h.

Referenced by trManager::ActorBase::OnAddedToSysMan(), trManager::SystemManager::RegisterActor(), and trManager::SystemManager::RegisterDirector().

Here is the caller graph for this function:

◆ OnParentRemoved()

void trManager::EntityBase::OnParentRemoved ( trManager::EntityBase parent)
virtual

Convenience function that will be called by the system when the Entities parent is removed.

Overwrite to capture the event.

Parameters
[in,out]parentThe parent.

Definition at line 276 of file EntityBase.cpp.

Referenced by ForgetParent().

Here is the caller graph for this function:

◆ OnParentSet()

void trManager::EntityBase::OnParentSet ( trManager::EntityBase parent)
virtual

Convenience function that will be called by the system when a new parent is added or set to the Entity.

Overwrite to capture the event.

Parameters
[in,out]parentThe parent.

Definition at line 281 of file EntityBase.cpp.

Referenced by SetParent().

Here is the caller graph for this function:

◆ OnRemovedFromSysMan()

void trManager::EntityBase::OnRemovedFromSysMan ( )
inlinevirtual

Called by the System Manager after removing and Unregistering the EntityBase.

Reimplemented in trManager::ActorBase.

Definition at line 107 of file EntityBase.h.

Referenced by trManager::ActorBase::OnRemovedFromSysMan().

Here is the caller graph for this function:

◆ OnTick()

void trManager::EntityBase::OnTick ( const trManager::MessageBase msg)
pure virtual

Convenience function that will receive Tick Messages from the System Manager This does not happen automatically, each class needs to register for the message.

Parameters
msgThe message.

Implemented in trManager::ActorBase, trManager::DirectorBase, and trManager::ActorModuleBase.

◆ OnTickRemote()

void trManager::EntityBase::OnTickRemote ( const trManager::MessageBase msg)
pure virtual

Convenience function that will receive a Network Tick Message from the System Manager This does not happen automatically, each class needs to register for the message.

Parameters
msgThe message.

Implemented in trManager::ActorBase.

◆ RemoveAllChildren()

bool trManager::EntityBase::RemoveAllChildren ( )
virtual

Removes all of the entities children .

Returns
True if it succeeds, false if it fails.

Definition at line 189 of file EntityBase.cpp.

References mChildren.

◆ RemoveChild()

bool trManager::EntityBase::RemoveChild ( trManager::EntityBase child)
virtual

Removes the child from this Entity.

Parameters
[in,out]childThe child.
Returns
True if it succeeds, false if it fails.

Definition at line 168 of file EntityBase.cpp.

References Emancipate(), GetParent(), and mChildren.

Referenced by Emancipate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveFromHierarchy()

bool trManager::EntityBase::RemoveFromHierarchy ( )
virtual

Removes from this entity from the hierarchy tree attaching its children to its parent.

Does nothing if this entity does not have a parent.

Returns
True if it succeeds, false if it fails.

Definition at line 305 of file EntityBase.cpp.

References AddChild(), ForgetParent(), trBase::Base::GetName(), LOG_E, mChildren, mParent, and trBase::SmrtPtr< T >::Valid().

Here is the call graph for this function:

◆ RemoveInvokable() [1/2]

void trManager::EntityBase::RemoveInvokable ( trManager::Invokable invokable)
virtual

Removes the invokable that is passed in.

Parameters
[in,out]invokableIf non-null, the invokable.

Definition at line 81 of file EntityBase.cpp.

References trManager::Invokable::GetName().

Here is the call graph for this function:

◆ RemoveInvokable() [2/2]

void trManager::EntityBase::RemoveInvokable ( const std::string &  invokableName)
virtual

Removes the invokable described by invokableName.

Parameters
invokableNameName of the invokable.

Definition at line 87 of file EntityBase.cpp.

References LOG_W, and mInvokables.

◆ SetParent()

void trManager::EntityBase::SetParent ( trManager::EntityBase parent)
virtual

Sets the hierarchal parent of this Entity.

This is for system use only. Use AddChild() if you want to attach entities.

Parameters
[in,out]parentThe parent.

Definition at line 236 of file EntityBase.cpp.

References trBase::Base::GetName(), LOG_E, mParent, OnParentSet(), and trBase::SmrtPtr< T >::Valid().

Referenced by trManager::ActorBase::AddActorModule(), and AddChild().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetRegistration()

void trManager::EntityBase::SetRegistration ( bool  isRegistered)
virtual

Is set to True by the System Manager when the class instance is registered with it.

This function should not be called by the user.

Parameters
isRegisteredTrue if this object is registered.

Definition at line 60 of file EntityBase.cpp.

References mIsRegistered.

Referenced by trManager::SystemManager::RegisterActor(), and trManager::SystemManager::RegisterDirector().

Here is the caller graph for this function:

◆ SetSystemManager()

void trManager::EntityBase::SetSystemManager ( trManager::SystemManager sysMan)
virtual

This method is used by the System Manager to pass the Entity an instance if itself when it is registered.

The user should not use this function.

Parameters
[in,out]sysManIf non-null, manager for system.

Definition at line 48 of file EntityBase.cpp.

References IsRegistered(), mIsRegistered, and mSysMan.

Referenced by trManager::SystemManager::RegisterActor(), and trManager::SystemManager::RegisterDirector().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ CLASS_TYPE

const trUtil::RefStr trManager::EntityBase::CLASS_TYPE
static

Adds an easy and swappable access to the base class.

Definition at line 52 of file EntityBase.h.

◆ mChildren

std::vector<trBase::SmrtPtr<trManager::EntityBase> > trManager::EntityBase::mChildren
private

◆ mEntityType

◆ mInvokables

trUtil::HashMap<std::string, trBase::SmrtPtr<trManager::Invokable> > trManager::EntityBase::mInvokables
protected

Definition at line 353 of file EntityBase.h.

Referenced by AddInvokable(), GetInvokable(), GetInvokables(), and RemoveInvokable().

◆ mIsRegistered

bool trManager::EntityBase::mIsRegistered = false
private

Definition at line 359 of file EntityBase.h.

Referenced by SetRegistration(), and SetSystemManager().

◆ mParent

trBase::SmrtPtr<trManager::EntityBase> trManager::EntityBase::mParent
private

Definition at line 361 of file EntityBase.h.

Referenced by Emancipate(), ForgetParent(), GetParent(), RemoveFromHierarchy(), and SetParent().

◆ mSysMan

◆ ON_MESSAGE_INVOKABLE

const trUtil::RefStr trManager::EntityBase::ON_MESSAGE_INVOKABLE
static

Holds the class type name for efficient comparisons.

Definition at line 54 of file EntityBase.h.

Referenced by trManager::DirectorBase::BuildInvokables(), and trManager::SystemManager::SendMessageToDirectors().

◆ ON_TICK_INVOKABLE

const trUtil::RefStr trManager::EntityBase::ON_TICK_INVOKABLE
static

Invokable for general messages.

Definition at line 55 of file EntityBase.h.

Referenced by trManager::ActorBase::BuildInvokables().

◆ ON_TICK_REMOTE_INVOKABLE

const trUtil::RefStr trManager::EntityBase::ON_TICK_REMOTE_INVOKABLE
static

Invokable for Tick messages.

Definition at line 56 of file EntityBase.h.

Referenced by trManager::ActorBase::BuildInvokables().


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