Thrive
Classes | Public Member Functions | Static Public Member Functions | List of all members
thrive::Entity Class Reference

Convenience class to handle an entity. More...

#include <entity.h>

Classes

struct  Implementation
 

Public Member Functions

 Entity (GameState *gameState=nullptr)
 Constructor. More...
 
 Entity (EntityId id, GameState *gameState=nullptr)
 Constructor. More...
 
 Entity (const std::string &name, GameState *gameState=nullptr)
 Constructor. More...
 
 Entity (const Entity &other)
 Copy constructor. More...
 
 ~Entity ()
 Destructor.
 
Entity & operator= (const Entity &other)
 Copy assignment. More...
 
bool operator== (const Entity &other) const
 Compares two entities. More...
 
void addComponent (std::unique_ptr< Component > component)
 Adds a component to this entity. More...
 
void destroy ()
 Removes all components of this entity.
 
bool exists () const
 Checks if the entity has any components. More...
 
Component * getComponent (ComponentTypeId typeId)
 Retrieves a component by type id. More...
 
bool hasComponent (ComponentTypeId typeId)
 Checks whether this entity has a component. More...
 
EntityId id () const
 The entity's id.
 
bool isVolatile () const
 Returns the volatile flag. More...
 
void addChild (Entity &child)
 Adds a child to the current entity. More...
 
bool hasChildren () const
 Returns whether the entity has any children. More...
 
void stealName (const std::string &name)
 Rebinds the name to the new Id. More...
 
void removeComponent (ComponentTypeId typeId)
 Removes a component by type id. More...
 
Entity transfer (GameState *newGameState)
 Transfers an entity to a different gameState. More...
 
void setVolatile (bool isVolatile)
 Sets the volatile flag. More...
 

Static Public Member Functions

static luabind::scope luaBindings ()
 Lua bindings. More...
 

Detailed Description

Convenience class to handle an entity.

This is a thin wrapper around the EntityManager API. Mostly for script purposes, but if you prefer, you can use this class instead of directly calling the EntityManager functions.

Note
Generally, the type id overloads of this class are to be preferred for optimum performance.

Constructor & Destructor Documentation

Entity::Entity ( GameState *  gameState = nullptr)

Constructor.

Creates a new unnamed entity

Parameters
gameStateThe game state the new entity belongs to. If null, the current game state of the global engine object is used.
Entity::Entity ( EntityId  id,
GameState *  gameState = nullptr 
)

Constructor.

Interfaces to an existing entity

Parameters
idThe entity id to interface to
gameStateThe game state the entity belongs to. If null, the current game state of the global engine object is used.
Entity::Entity ( const std::string &  name,
GameState *  gameState = nullptr 
)

Constructor.

Interfaces to a named entity

Uses the EntityManager of Game::engine()

Parameters
nameThe name of the entity to interface to
gameStateThe game state the entity belongs to. If null, the current game state of the global engine object is used.
Entity::Entity ( const Entity &  other)

Copy constructor.

This does not copy the entity's components, it just creates another wrapper.

Parameters
other

Member Function Documentation

void Entity::addChild ( Entity &  child)

Adds a child to the current entity.

Parameters
child
Note
Parent-child relationships are not serialized
Returns
void Entity::addComponent ( std::unique_ptr< Component >  component)

Adds a component to this entity.

Parameters
component
bool Entity::exists ( ) const

Checks if the entity has any components.

Returns
true if the entity has at least one component, false otherwise
Component * Entity::getComponent ( ComponentTypeId  typeId)

Retrieves a component by type id.

Parameters
typeIdThe component's type id
Returns
A non-owning pointer to the component or nullptr if no such component was found
bool Entity::hasChildren ( ) const

Returns whether the entity has any children.

Returns
bool Entity::hasComponent ( ComponentTypeId  typeId)

Checks whether this entity has a component.

Equivalent to

entity->getComponent(typeId) != nullptr;
Parameters
typeIdThe component's type id
Returns
true if such a component was found, false otherwise
bool Entity::isVolatile ( ) const

Returns the volatile flag.

Volatile entities are not serialized into a savegame

Returns
luabind::scope Entity::luaBindings ( )
static

Lua bindings.

Exposes the following constructors:

  • Entity(): Entity()
  • Entity(number): Entity(EntityId)
  • Entity(string): Entity(const std::string&)

Exposes the following functions:

Exposes the following operators:

  • ==: operator==(const Entity&)
Entity & Entity::operator= ( const Entity &  other)

Copy assignment.

This does not copy the entity's components, it just changes the entity id this wrapper points to.

bool Entity::operator== ( const Entity &  other) const

Compares two entities.

Entities compare to true if their entity ids are equal and they are part of the same game state.

void Entity::removeComponent ( ComponentTypeId  typeId)

Removes a component by type id.

If no such component was found, does nothing.

Note
The component is only actually removed after the entity manager's EntityManager::processRemovals() function is called.
Parameters
typeIdThe component's type id
void Entity::setVolatile ( bool  isVolatile)

Sets the volatile flag.

Parameters
isVolatile
See also
isVolatile()
void Entity::stealName ( const std::string &  name)

Rebinds the name to the new Id.

Parameters
entityIdThe stealing entity
nameThe name to rebind
Returns
Entity Entity::transfer ( GameState *  newGameState)

Transfers an entity to a different gameState.

Parameters
GameStateThe GameState to transfer to
Returns
The new entity in the new gamestate. Note that the actual transfer will take place before next update so the old entity is valid until then.

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