TurtleBrains  0.3.1
High quality, portable, C++ framework for rapid 2D 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< Entity * > EntityList
 

Public Member Functions

 EntityManager (void)
 
virtual ~EntityManager (void)=0
 
void ClearEntities (void)
 
void AddEntity (Entity *entity)
 
void AddEntity (Entity &entity)
 
void RemoveEntity (Entity *entity)
 
void RemoveEntities (const EntityType &byType=Entity::kInvalidType)
 
void EntityTypeChanged (Entity &entity, const EntityTypeContainer &oldTypes)
 
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 ClearGraphics (void)
 
void AddGraphic (Graphic *graphic)
 
void AddGraphic (Graphic &graphic)
 
void RemoveGraphic (Graphic *graphic)
 
virtual void SetColor (const tbGraphics::Color &newColor) override
 
- 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)
 
void SetOrigin (const AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero())
 
void SetOrigin (const float originX, const float originY)
 
void SetOrigin (const tbMath::Vector2 &origin)
 
float GetDepth (void) const
 
void SetDepth (const float newDepth)
 
const tbMath::Vector2GetScale (void) const
 
void SetScale (const float scale)
 
void SetScale (const float scaleX, const float scaleY)
 
float GetRotation (void) const
 
void SetRotation (const float rotation)
 
void SetScroll (const float scroll)
 
void SetScroll (const float scrollX, const float scrollY)
 
bool IsRelative (void) const
 
const ColorGetColor (void) const
 
virtual PixelSpace GetPixelWidth (void) const
 
virtual PixelSpace GetPixelHeight (void) const
 
float GetWidth (void) const
 
float GetHeight (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
virtual void ApplyTransform (void) const
 
virtual void PopTransform (void) const
 

Detailed Description

The EntityManager is a container of entities to perform Simulate, Update and Render on, as well as collisions and provides access to the entities by type or intersected areas. Entities added by AddEntity(Entity*) will be deleted when the entity is removed or EntityManager is destroyed while entities added by AddEntity(Entity&) are expected to remain available and in scope until removed.

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 ( Entity 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 frame 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 ( Entity 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 frame 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 EntityManager will not 'own' an entity added this way.

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

Removes all entities from the EntityManager as soon as it is possible to do so.

void TurtleBrains::Game::EntityManager::EntityTypeChanged ( Entity entity,
const EntityTypeContainer oldTypes 
)

Removes the Entity from the EntityType containers and re-updates based on the new EntityTypes.

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

Creates an EntityList containing all the entities and returns it for general use.

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

Checks all the entities with bounding volumes to see if the point is contained, returning an list of the entities that contain the point. If only collidableEntities is true, the returned list only contains entities that contain the point and are set to be collidable.

Parameters
pointthe location to test in world space.
byTypeonly check entities of a specific type, of if Entity::kInvalidType is used, all entities regardless of the type.
onlyCollidableEntitiesSet to true to check only the entities that are collidable.
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)

Creates an EntityList containing all the entities that have the EntityType byType.

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

TODO: TurtleBrains: 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: TurtleBrains: 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 ( Entity 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.