#include <Entity.h>

Description

Basic interactive object.

Entity s are the main classes that are extended to meet abstractions for your multimedia project. In conjunction with functionality you write in the OnStep(), OnDraw(), etc. virtual functions, you can dynamically extend Entity s using Component s and attaching them as you see fit.

Entity::ID s may also be used. Entity::ID s allow you to safely work with references of Entities. Using Entity::ID::Valid() calls can also safely and reliable tell you whether an Entity is still accessible.

Entity s are also inherently hierarchical. By Attach()ing other Entity s, you can create trees of self-managed Entities.

Data Structures

class  ID
 

Public Types

enum  UpdateClass {
  Before,
  After
}
 

Functions

const std::vector< Entity::ID > & GetChildren () const
 
std::vector< Entity::IDGetAllSubEntities () const
 
bool Contains (Entity::ID)
 
std::vector< Entity::IDFindChildByName (const std::string &)
 
void Step ()
 
void Draw ()
 
void Attach (Entity::ID)
 
void Detach (Entity::ID)
 
template<typename T >
T * CreateChild ()
 
int GetNumChildren ()
 
double StepDuration ()
 
double DrawDuration ()
 
void SetPriority (Priority p)
 
void SetPriorityLast ()
 
void SetPriorityFirst ()
 
Priority GetPriority ()
 
EntityGetParent ()
 
bool HasParent ()
 
void Remove ()
 
void SetName (const std::string &name)
 
ID GetID ()
 
std::string GetName ()
 
Variable control

When debugging, it is often convenient to view the value of something while the program runs normally. This interface allows you to connect specific values to be viewed in the Debugger.

void Watch (Variable v)
 
Variable GetWatched (const std::string &name)
 
std::vector< VariableGetWatchedVars ()
 
void Unwatch (const std::string &varName)
 
Component Control

Components offer additional standard sets of functionality that extend the capabilities of the Entity it is attached to.

template<typename T >
T * AddComponent (UpdateClass when=UpdateClass::Before)
 
template<typename T >
T * QueryComponent ()
 
const std::vector< Component * > & GetComponents () const
 
void RemoveComponent (const std::string &tag)
 
void RemoveComponent (const Component *)
 

Static Functions

template<typename T >
static Entity::ID Create ()
 
static Entity::ID Create ()
 
template<typename T >
static T * CreateReference ()
 
static std::vector< Entity::IDGetAll ()
 

Protected Member Functions

Base Functionality

When defining your Entity, these are the basic functions that allow the Entity to express logic.

virtual void OnEnter ()
 
virtual void OnDepart ()
 
virtual void OnRemove ()
 
virtual void OnPreStep ()
 
virtual void OnStep ()
 
virtual void OnPreDraw ()
 
virtual void OnDraw ()
 

Update Handling

When using the Engine, Entities are utomatically updated based on your specified framerate. However, it is useful at times to control when you update the Entity manually.

bool step
 
bool draw
 
bool IsStepping ()
 
bool IsDrawing ()
 

Member Enumeration Documentation

enum UpdateClass
strong

When Components should be updated.

Enumerator
Before 

Before Entity base logic is run.

After 

After Entity base logic is run.

Member Function Documentation

const std::vector<Entity::ID>& GetChildren ( ) const

Returns the i'th Entity starting at 0.

Entities are ordered by priority, where the first entity is guaranteed to be the one with the lowest Priority value. If unsuccessful, the EntityID will be invalid.

std::vector<Entity::ID> GetAllSubEntities ( ) const

Returns all Entities that are within this Entity's hierarchy.

bool Contains ( Entity::ID  )

Returns the Entity with the given ID.

If unsuccessful returns nullptr.

std::vector<Entity::ID> FindChildByName ( const std::string &  )

Returns all bound Entities with the name equivalent to the one given within this Entity's hierarchy. The Entity's IDs are returned.

void Step ( )

Updates all attached Entities.

void Draw ( )

Draws all attached Entities.

void Attach ( Entity::ID  )

Binds an entity to the World. If bound, an Entity will be updated when the World is updated.

void Detach ( Entity::ID  )

Unbinds an Entity.

T* CreateChild ( )
inline

Allocates an Entity and Attaches it for you.

static Entity::ID Create ( )
inlinestatic

Creates a new Entity and returns its ID.

static Entity::ID Create ( )
inlinestatic

Creates a new Entity of no type and returns its ID.

static T* CreateReference ( )
inlinestatic

Creates a new Entity of the given type.

int GetNumChildren ( )

Returns number of active Entities.

double StepDuration ( )

Returns the last recorded amount of milliseconds it took the Entity, iedentified by id, to complete its run cycle. A run cycle consists of the Entities Run function and any attached components' run.

double DrawDuration ( )

Returns the last recorded amount of milliseconds it took the Entity, iedentified by id, to complete its draw cycle. A draw cycle consists of the Entities Draw function and any attached components' draw.

void Watch ( Variable  v)

Allows you to monitor a Variable through the debugger.

Parameters
vThe variable to watch.
Variable GetWatched ( const std::string &  name)

Returns a watched Variable of the given name.

Parameters
nameThe name of the Variable to ask for.
std::vector<Variable> GetWatchedVars ( )

Returns all watched variables associated with this Entity.

void Unwatch ( const std::string &  varName)

Stops watching a variable of the given name.

Parameters
varNameThe variable to stop watching.
void SetPriority ( Priority  p)

Alters the priority of this entity.

Priorty determines the order in which this entity is updated. A lower priority means it will be drawn and updated earlier. It is undefined which entity is updated first if both have the same priority.

Parameters
pThe new priority.
void SetPriorityLast ( )

Sends the entity of the ID to be the last of in line for drawing and updates.

void SetPriorityFirst ( )

Sends the entity to be drawn and updated as the last in the queue causing it to be on top when drawing.

Priority GetPriority ( )

Returns the priority of the this entity.

bool IsStepping ( )

Returns wether or not the Engine is handling calling Step() automatically, taking into account the Entity's hierarchy.

bool IsDrawing ( )

Returns wether or not the Engine is handling calling Draw() automatically, taking into account the Entity's hierarchy.

Entity& GetParent ( )

Returns the World that the Entity belongs to.

Every Entity is guaranteed to return a valid reference. In the case that no actual world owns the Entity,

bool HasParent ( )

Returns whether or not the Entity belongs to a world.

T* AddComponent ( UpdateClass  when = UpdateClass::Before)
inline

Attaches a component to this entity.

Once attached, the component's Step and Draw functions will be called before this entity's Run and Draw.

Parameters
whenWhen to step and draw this component in relation to the hosts own step/draw. The default is "before"
T * QueryComponent ( )

Returns whether or not there is currently an attached component of the type given.

If there is, a reference to the first one is returned. If not, nullptr is returned.

const std::vector<Component *>& GetComponents ( ) const

Returns all components that belong to the Entity.

void RemoveComponent ( const std::string &  tag)

Removes the first occurrance of a component with the tag given.

No action is taken on the data associated with the component.

Parameters
tagThe tag that identifies the component to remove.
void RemoveComponent ( const Component )

Removes the attached component with the given pointer.

void Remove ( )

Detaches and marks this entity for deletion. After this is called, all references to.

void SetName ( const std::string &  name)

Sets an optional name to further identify the entity. Tools such as the debugger.

use this to further identify entities.

Parameters
nameThe new name of the Entity. This name will also be displayed in the Debugger.
ID GetID ( )

Returns the Entity's unique ID.

The ID uniquely identifies an Entity. If the source Entity is removed or freed, the ID will return false for a Valid call and Entity() will return NULL.

std::string GetName ( )

Returns the name identifier of the Entity.

static std::vector<Entity::ID> GetAll ( )
static

Returns a list of all Entitys. Note that this list is generated every time.

virtual void OnEnter ( )
inlineprotectedvirtual

The Entry function is called upon each attachment to a world.

On the first attachment, Init is called before Enter.

virtual void OnDepart ( )
inlineprotectedvirtual

The Depart function is called upon each detachment from a world.

virtual void OnRemove ( )
inlineprotectedvirtual

The Destruct function is called just before removal of the object.

It should be used like a destructor to free and resources associated with the entity.

virtual void OnPreStep ( )
inlineprotectedvirtual

Called when Step() is called.

virtual void OnStep ( )
inlineprotectedvirtual

Called when Step() is called.

Reimplemented in Camera, and InputBox.

virtual void OnPreDraw ( )
inlineprotectedvirtual

Called when Draw() is called.

virtual void OnDraw ( )
inlineprotectedvirtual

Called when Draw() is called.

Reimplemented in ParticleEmitter2D, and InputBox.

Field Documentation

bool step

Whether the engine should call Step() automatically for this entity. Note that Step() calls also manage components and child entities. The default is true.

bool draw

Whether the engine should call Draw() automatically for this entity. Note that Draw() calls also manage components and child entities. The default is true.


The documentation for this class was generated from the following file:
  • /home/jc/git/Dynacoe/DynacoeSrc/includes/Dynacoe/Entity.h