Skip to content

Latest commit

 

History

History
106 lines (71 loc) · 2.4 KB

EntityManager.md

File metadata and controls

106 lines (71 loc) · 2.4 KB

Manages GameObjects, Components and Systems.

An EntityManager is also a Mediator, managing communication for Systems.

Base classes

An EntityManager's role is split-up into three parts:

Members

Constructor
EntityManager(std::unique_ptr<EntityFactory> &&factory = nullptr);

An EntityManager can be constructed with an EntityFactory, which will be used to create entities.

createEntity
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.

removeEntity
void removeEntity(kengine::GameObject &go);
void removeEntity(std::string_view name);
getEntity
GameObject &getEntity(std::string_view name);
hasEntity
bool hasEntity(std::string_view name) const noexcept;
getGameObjects
const std::vector<GameObject> &getGameObjects();

Returns all GameObjects.

template<typename T>
const std::vector<GameObject> &getGameObjects<T>();

Returns all GameObjects with a T component.

addLink
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.

removeLink
void removeLink(const GameObject &child);
getParent
const GameObject &getParent(const GameObject &go) const;
getFactory
template<typename T>
T &getFactory();

Returns the EntityFactory as a T.