Manages GameObjects, Components and Systems.
An EntityManager
is also a Mediator, managing communication for Systems
.
An EntityManager
's role is split-up into three parts:
- the
EntityManager
itself, which simply manages entities - a ComponentManager base
- a SystemManager base
EntityManager(std::unique_ptr<EntityFactory> &&factory = nullptr);
An EntityManager
can be constructed with an EntityFactory
, which will be used to create
entities.
GameObject &createEntity(std::string_view type, std::string name,
const std::function<void(GameObject &)> &postCreate = nullptr)
Asks the underlying EntityFactory
to create an entity of type type
, with the given name
.
Once creation is complete, calls postCreate
on the entity.
template<class GO, typename = std::enable_if_t<std::is_base_of<GameObject, GO>::value>>
GO &createEntity(std::string const &name,
const std::function<void(GameObject &)> &postCreate = nullptr,
auto &&... params) noexcept
Creates a new entity of type GO
by giving it params
as constructor arguments.
Once creation is complete, calls postCreate
on the entity.
void removeEntity(kengine::GameObject &go);
void removeEntity(std::string_view name);
GameObject &getEntity(std::string_view name);
bool hasEntity(std::string_view name) const noexcept;
const std::vector<GameObject> &getGameObjects();
Returns all GameObjects
.
template<typename T>
const std::vector<GameObject> &getGameObjects<T>();
Returns all GameObjects
with a T
component.
void addLink(const GameObject &parent, const GameObject &child);
Registers parent
as child
's parent object. This process can be used by systems to store relations between GameObjects
.
void removeLink(const GameObject &child);
const GameObject &getParent(const GameObject &go) const;
template<typename T>
T &getFactory();
Returns the EntityFactory
as a T
.