#include <tb_entity_manager.hpp>
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 ¢er, const float radius, const EntityType &byType=Entity::kInvalidType, bool onlyCollidableEntities=false) |
EntityList | GetEntitiesWithin (const tbMath::Vector2 ¢er, 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 |
virtual PixelSpace | GetPixelWidth (void) const |
virtual PixelSpace | GetPixelHeight (void) const |
void | RecalculateWidthAndHeight (void) |
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::Vector2 & | GetPosition (void) const |
void | SetPosition (const float x, const float y) |
void | SetPosition (const tbMath::Vector2 &position) |
const tbMath::Vector2 & | GetOrigin (void) const |
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::Vector2 & | GetScale (void) const |
void | SetScale (const float scale) |
void | SetScale (const tbMath::Vector2 &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 Color & | GetColor (void) const |
float | GetWidth (void) const |
float | GetHeight (void) const |
float | GetScaledWidth (void) const |
float | GetScaledHeight (void) const |
bool | UnstableIsPointContained (const tbMath::Vector2 &point) const |
Protected Member Functions | |
virtual void | OnSimulate (void) |
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 |
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.
typedef std::list<Entity*> TurtleBrains::Game::EntityManager::EntityList |
A simple list of entities.
TurtleBrains::Game::EntityManager::EntityManager | ( | void | ) |
Constructs an EntityManager object which contains no entities.
|
pure virtual |
Destructs an entity which currently (TurtleBrains v0.2.0) does not have any resources to clean up after.
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.
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 given by oldType, then places the entity in the containers from new types.
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.
point | the location to test in world space. |
byType | only check entities of a specific type, of if Entity::kInvalidType is used, all entities regardless of the type. |
onlyCollidableEntities | Set to true to check only the entities that are collidable. |
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.
|
protectedvirtual |
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.
Reimplemented in TurtleBrains::Game::GameScene.
|
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 OnSimulate which calls Simulate on each entity and performs collision checks.