TurtleBrains  0.2.1
High quality, portable, C++ API for native application and game development.
TurtleBrains::Game::EntityManager Class Referenceabstract

#include <tb_entity_manager.h>

Inheritance diagram for TurtleBrains::Game::EntityManager:
TurtleBrains::Graphics::GraphicList TurtleBrains::Graphics::Graphic TurtleBrains::Game::GameScene

Public Types

typedef std::list< EntityInterface * > EntityList
 

Public Member Functions

 EntityManager (void)
 
virtual ~EntityManager (void)=0
 
void AddEntity (EntityInterface *entity)
 
void AddEntity (EntityInterface &entity)
 
void RemoveEntity (EntityInterface *entity)
 
void RemoveEntities (const EntityType &byType=Entity::kInvalidType)
 
EntityList GetAllEntities (void)
 
EntityList GetEntitiesByType (const EntityType &byType)
 
EntityList GetEntitiesAt (const tbMath::Vector2 &point, const EntityType &byType=Entity::kInvalidType, bool onlyCollidableEntities=false)
 
EntityList GetEntitiesWithin (const tbMath::Vector2 &center, const float radius, const EntityType &byType=Entity::kInvalidType, bool onlyCollidableEntities=false)
 
EntityList GetEntitiesWithin (const tbMath::Vector2 &center, const float width, const float height, const EntityType &byType=Entity::kInvalidType, bool onlyCollidableEntities=false)
 
void Simulate (void)
 
- Public Member Functions inherited from TurtleBrains::Graphics::GraphicList
 GraphicList (void)
 
virtual ~GraphicList (void)
 
void AddGraphic (Graphic *graphic)
 
void AddGraphic (Graphic &graphic)
 
void RemoveGraphic (Graphic *graphic)
 
virtual void SetColor (const tbGraphics::Color &newColor)
 
- Public Member Functions inherited from TurtleBrains::Graphics::Graphic
 Graphic (void)
 
 Graphic (const Graphic &other)
 
virtual ~Graphic (void)
 
bool IsActive (void) const
 
void SetActive (const bool isActive)
 
void Update (const float deltaTime)
 
bool IsVisible (void) const
 
void SetVisible (const bool isVisible)
 
void Render (void) const
 
const tbMath::Vector2GetPosition (void) const
 
void SetPosition (const float x, const float y)
 
void SetPosition (const tbMath::Vector2 &position)
 
float GetDepth (void) const
 
void SetDepth (const float newDepth)
 
bool IsRelative (void) const
 

Protected Member Functions

virtual void OnUpdate (const float deltaTime) override
 
- Protected Member Functions inherited from TurtleBrains::Graphics::GraphicList
virtual void OnRender (void) const override
 
- Protected Member Functions inherited from TurtleBrains::Graphics::Graphic
const ColorGetColor (void) const
 

Detailed Description

The EntityManager will contain several entities to Simulate, Update and Render as well as perform collisions and access the entities by type or area.

Member Typedef Documentation

A simple list of entities.

Constructor & Destructor Documentation

TurtleBrains::Game::EntityManager::EntityManager ( void  )

Constructs an empty entity object which contains no Graphics and position is defaults to 0,0.

virtual TurtleBrains::Game::EntityManager::~EntityManager ( void  )
pure virtual

Destructs an entity which currently (TurtleBrains v0.2.0) does not have any resources to clean up after.

Member Function Documentation

void TurtleBrains::Game::EntityManager::AddEntity ( EntityInterface entity)

First creates an Entity by calling the EntityFactoryInterface CreateEntity() then adds the entity to be managed and accessed.

Note
This function currently is not implemented, undecided how the EntityFactoryInterface will register.

Adds an Entity to the manager in a few containers for the entity to be accessed, and it will be simulated, updated and rendered each from of the game while it exists in the EntityManager. When the Entity is removed from the manager it will be deleted, cleaned up and destroyed.

void TurtleBrains::Game::EntityManager::AddEntity ( EntityInterface entity)

Adds an Entity to the manager in a few containers for the entity to be accessed, and it will be simulated, updated and rendered each from of the game while it exists in the EntityManager. When the Entity is removed from the manager it will NOT be deleted or cleaned up, or destroyed. The entity manager will not 'own' an entity added this way.

EntityList TurtleBrains::Game::EntityManager::GetAllEntities ( void  )

TODO: TIM: Documentation: Teach the user how to use this.

EntityList TurtleBrains::Game::EntityManager::GetEntitiesAt ( const tbMath::Vector2 point,
const EntityType byType = Entity::kInvalidType,
bool  onlyCollidableEntities = false 
)

TODO: TIM: Documentation: Teach the user how to use this.

Note
This will only get entities that the point collides with one of the bounding volumes, and requires the entity to have a bounding volume to work correctl.y
EntityList TurtleBrains::Game::EntityManager::GetEntitiesByType ( const EntityType byType)

TODO: TIM: Documentation: Teach the user how to use this.

EntityList TurtleBrains::Game::EntityManager::GetEntitiesWithin ( const tbMath::Vector2 center,
const float  radius,
const EntityType byType = Entity::kInvalidType,
bool  onlyCollidableEntities = false 
)

TODO: TIM: Documentation: Teach the user how to use this.

EntityList TurtleBrains::Game::EntityManager::GetEntitiesWithin ( const tbMath::Vector2 center,
const float  width,
const float  height,
const EntityType byType = Entity::kInvalidType,
bool  onlyCollidableEntities = false 
)

TODO: TIM: Documentation: Teach the user how to use this.

virtual void TurtleBrains::Game::EntityManager::OnUpdate ( const float  deltaTime)
overrideprotectedvirtual

Calls Update() on each of the entities, before removing any entities that may have expired.

Reimplemented from TurtleBrains::Graphics::GraphicList.

Reimplemented in TurtleBrains::Game::GameScene.

void TurtleBrains::Game::EntityManager::RemoveEntities ( const EntityType byType = Entity::kInvalidType)

Marks entities for removal by type, or removes all entities if Entity::kInvalidType is used.

void TurtleBrains::Game::EntityManager::RemoveEntity ( EntityInterface entity)

Marks an Entity for removal from the EntityManger, the actual removal will happen at the end of either Simulate or Update to prevent modifying the container while iterating through it.

void TurtleBrains::Game::EntityManager::Simulate ( void  )

Calls Simulate() on each of the entities, and then calls PerformCollision() to check for collision updates before finally removing any entities that may have expired during the simulate logic.