#include <Environment.h>
Public Member Functions | |
Environment (std::shared_ptr< EntityManager > entityManager) | |
Constructor of an Environment without files, the only need is an EntityManager. | |
Environment (const std::string &entitiesPath, const std::string &componentsPath, const std::string &subscriptionsPath) | |
Constructor which take the paths of the JSON's description of the entities, components and subscriptions of this ECS environment. | |
void | addManager (std::shared_ptr< ComponentManager > manager) |
Let you add a ComponentManager from the environment interface. | |
std::vector< std::shared_ptr< ComponentManager > > | getManagers () |
Return all the ComponentManagers. | |
std::shared_ptr< ComponentManager > | getManager (const std::string &name) |
Return a specific ComponentManager. | |
std::shared_ptr< EntityManager > | getEntityManager () |
Return the EntityManager. | |
void | setEntityState (const std::string &name, bool state, bool share=true) |
Let you set an entity's state with its name. | |
void | setEntityState (int entity, bool state, bool share=true) |
Let you set an entity's state with its ID. | |
void | setEntitiesState (const std::string &prefixOrTag, bool state, bool share=true, bool isPrefix=true) |
Let you update the state of all entities with a certain prefix in their name or with a certain tag. | |
void | setState (int entity, const std::string &compName, bool state, bool share=true) |
Set the state of a specific component for an entity, with its ID. | |
void | setState (const std::string &name, const std::string &compName, bool state, bool share=true) |
Set the state of a specific component for an entity, with its name. | |
void | setStates (const std::string &prefixOrTag, const std::string &compName, bool state, bool share=true, bool isPrefix=true) |
Set the state of a set of entities for a specific component. | |
bool | getState (int entity, const std::string &compName) |
Return the state of an entity's component, with its ID. | |
bool | getState (const std::string &name, const std::string &compName) |
Return the state of an entity's component, with its name. | |
int | getEntity (const std::string &name) |
Return an entity's ID from its name. | |
const std::string & | getName (int entity) |
Return an entity's name from its ID. | |
int | createEntity (const std::string &name, bool createFile=false, bool share=true) |
Create a new entity and return its ID. | |
void | removeEntity (const std::string &name, bool share=true) |
Remove an entity from the EntityManager. | |
std::vector< std::shared_ptr< Component > > | getComponents (int entity) |
Return all the components from an entity, with its ID. | |
std::vector< std::shared_ptr< Component > > | getComponents (const std::string &name) |
Return all the components of an entity, with its name. | |
std::shared_ptr< Component > | getComponent (int entity, const std::string &name) |
Return the component of a specific entity, with its ID. | |
std::shared_ptr< Component > | getComponent (const std::string &entityName, const std::string &name) |
Return the component of a specific entity, with its name. | |
bool | hasComponent (const std::string &name, const std::string &compName) |
Return true if the given entity possess the given component, false otherwise. | |
bool | hasComponent (int entity, const std::string &compName) |
Return true if the given entity possess the given component, false otherwise. | |
bool | hasTag (int entity, const std::string &tagName) |
Return true if the entity have the given tag, false otherwise. | |
bool | hasTag (const std::string &name, const std::string &tagName) |
Return true if the entity have the given tag, false otherwise. | |
void | addTag (int entity, const std::string &tag, bool share=true) |
Add a tag to an entity. | |
void | addTag (const std::string &entity, const std::string &tag, bool share=true) |
Add a tag to an entity. | |
void | save (int entity) |
Let you save the subscription of an entity in a file, it will preserve the current values of the components, therefore it can be used as a saving system. | |
void | save (const std::string &name) |
Let you save the subscription of an entity in a file, it will preserve the current values of the components, therefore it can be used as a saving system. | |
void | join (std::function< void(int)> callback, size_t ID) |
Let you join the Environment's update list. | |
void | notify (int entity) |
Will notify every callbacks of an update in the environment. | |
void | notify (size_t ID) |
Will share with a specific system all the entities currently in the environment. | |
int | copy (const std::string &original, const std::string ©, bool createFile=false, bool share=true) |
Let you create a new entity, which is a perfect copy of the original. | |
void | give (const std::string &component, int giver, int receiver, bool copy, bool share=true) |
Give the ownership, or make a copy, of an entity's component to another component. | |
void | makeSnapshot (const std::string &snapshotName, const std::vector< std::string > &toSave={}, const std::vector< std::string > &components={}) |
Make and store a snapshot of the desired entities and components. | |
void | loadSnapshot (const std::string &snapshotName) |
Load the snapshot from the given name if it exist. | |
void | clearSnapshot (const std::string &snapshotName) |
Let you clear a snapshot from its name. | |
Environment::Environment | ( | std::shared_ptr< EntityManager > | entityManager | ) |
Constructor of an Environment without files, the only need is an EntityManager.
entityManager | The EntityManager which will be used by this environment. |
Environment::Environment | ( | const std::string & | entitiesPath, |
const std::string & | componentsPath, | ||
const std::string & | subscriptionsPath ) |
Constructor which take the paths of the JSON's description of the entities, components and subscriptions of this ECS environment.
The entire environment settings are loaded from these files.
entitiesPath | The entities' root directory. |
componentsPath | The components' root directory. |
subscriptionsPath | The subscriptions' root directory. |
void Environment::addManager | ( | std::shared_ptr< ComponentManager > | manager | ) |
Let you add a ComponentManager from the environment interface.
manager | A shared_ptr towards the ComponentManagers which will be added to the environment. |
void Environment::addTag | ( | const std::string & | entity, |
const std::string & | tag, | ||
bool | share = true ) |
Add a tag to an entity.
name | Entity's name. |
tag | The tag to add. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
void Environment::addTag | ( | int | entity, |
const std::string & | tag, | ||
bool | share = true ) |
Add a tag to an entity.
entity | Entity's ID. |
tag | The tag to add. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
void Environment::clearSnapshot | ( | const std::string & | snapshotName | ) |
Let you clear a snapshot from its name.
snapshotName | Name of the snapshot. |
int Environment::copy | ( | const std::string & | original, |
const std::string & | copy, | ||
bool | createFile = false, | ||
bool | share = true ) |
Let you create a new entity, which is a perfect copy of the original.
The new entity will have the name "copy" and its ID is returned.
original | The name of the original entity. |
copy | The desired name for the copy. |
createFile | If true, an entity's file is created in the root directory. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
int Environment::createEntity | ( | const std::string & | name, |
bool | createFile = false, | ||
bool | share = true ) |
Create a new entity and return its ID.
If createFile is true, the entity's file will be create in the root directory.
name | Entity's name. |
createFile | If true, an entity's file is created in the root directory. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
std::shared_ptr< Component > Environment::getComponent | ( | const std::string & | entityName, |
const std::string & | name ) |
Return the component of a specific entity, with its name.
name | Entity's name. |
name | The name of the component. |
std::shared_ptr< Component > Environment::getComponent | ( | int | entity, |
const std::string & | name ) |
Return the component of a specific entity, with its ID.
entity | Entity's ID. |
name | The name of the component. |
std::vector< std::shared_ptr< Component > > Environment::getComponents | ( | const std::string & | name | ) |
Return all the components of an entity, with its name.
name | Entity's name. |
std::vector< std::shared_ptr< Component > > Environment::getComponents | ( | int | entity | ) |
Return all the components from an entity, with its ID.
entity | Entity's ID. |
int Environment::getEntity | ( | const std::string & | name | ) |
Return an entity's ID from its name.
name | Entity's name. |
std::shared_ptr< EntityManager > Environment::getEntityManager | ( | ) |
Return the EntityManager.
std::shared_ptr< ComponentManager > Environment::getManager | ( | const std::string & | name | ) |
Return a specific ComponentManager.
name | The name of the desired ComponentManager. |
std::vector< std::shared_ptr< ComponentManager > > Environment::getManagers | ( | ) |
Return all the ComponentManagers.
const std::string & Environment::getName | ( | int | entity | ) |
Return an entity's name from its ID.
entity | Entity's ID. |
bool Environment::getState | ( | const std::string & | name, |
const std::string & | compName ) |
Return the state of an entity's component, with its name.
entityName | Entity's name. |
compName | The name of the component. |
bool Environment::getState | ( | int | entity, |
const std::string & | compName ) |
Return the state of an entity's component, with its ID.
entity | Entity's ID. |
compName | The name of the component. |
void Environment::give | ( | const std::string & | component, |
int | giver, | ||
int | receiver, | ||
bool | copy, | ||
bool | share = true ) |
Give the ownership, or make a copy, of an entity's component to another component.
component | Name of the component to give. |
giver | The ID of the entity which give its component. |
receiver | The ID of the entity which take the component. |
copy | If true the component is just copied, otherwise the giver doesn't have the component anymore. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
bool Environment::hasComponent | ( | const std::string & | name, |
const std::string & | compName ) |
Return true if the given entity possess the given component, false otherwise.
name | Entity's name. |
compName | Component's name. |
bool Environment::hasComponent | ( | int | entity, |
const std::string & | compName ) |
Return true if the given entity possess the given component, false otherwise.
entity | Entity's ID. |
compName | Component's name. |
bool Environment::hasTag | ( | const std::string & | name, |
const std::string & | tagName ) |
Return true if the entity have the given tag, false otherwise.
name | Entity's name. |
tag | The tag to search for. |
bool Environment::hasTag | ( | int | entity, |
const std::string & | tagName ) |
Return true if the entity have the given tag, false otherwise.
entity | Entity's ID. |
tag | The tag to search for. |
void Environment::join | ( | std::function< void(int)> | callback, |
size_t | ID ) |
Let you join the Environment's update list.
This callback will be called every time a notification is send.
callback | Function which take an entity's ID and decide if it should be added to a system or not. |
ID | System's ID, to identify its callback. |
void Environment::loadSnapshot | ( | const std::string & | snapshotName | ) |
Load the snapshot from the given name if it exist.
All the entities saved and the components saved of the snapshot will replace the current ones.
snapshotName | Name of the snapshot. |
void Environment::makeSnapshot | ( | const std::string & | snapshotName, |
const std::vector< std::string > & | toSave = {}, | ||
const std::vector< std::string > & | components = {} ) |
Make and store a snapshot of the desired entities and components.
By default, toSave and components are empty, this means that every entities and every components should be saved.
The snapshot will be saved with the name "snapshotName", if it already exist the old snapshot is replaced.
snapshotName | Name of the snapshot. |
toSave | List of entities to save, empty means all. |
components | List of components to save, empty means all those of the entities. |
void Environment::notify | ( | int | entity | ) |
Will notify every callbacks of an update in the environment.
Only the updated entity is concerned.
entity | The updated entity to share. |
void Environment::notify | ( | size_t | ID | ) |
Will share with a specific system all the entities currently in the environment.
If the callback doesn't exist, do nothing.
Let you update entirely (or resync) a system's entities list.
ID | System's ID, identify its callback. |
void Environment::removeEntity | ( | const std::string & | name, |
bool | share = true ) |
Remove an entity from the EntityManager.
name | Entity's name. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
void Environment::save | ( | const std::string & | name | ) |
Let you save the subscription of an entity in a file, it will preserve the current values of the components, therefore it can be used as a saving system.
If the file is already present in the directory folder or its subfolders, it will be replaced, otherwise it will be created in the directory folder of the subscriptions.
name | The name of the entity to save. |
void Environment::save | ( | int | entity | ) |
Let you save the subscription of an entity in a file, it will preserve the current values of the components, therefore it can be used as a saving system.
If the file is already present in the directory folder or its subfolders, it will be replaced, otherwise it will be created in the directory folder of the subscriptions.
entity | The ID of the entity to save. |
void Environment::setEntitiesState | ( | const std::string & | prefixOrTag, |
bool | state, | ||
bool | share = true, | ||
bool | isPrefix = true ) |
Let you update the state of all entities with a certain prefix in their name or with a certain tag.
Apply this state to every components of these entities.
prefixOrTag | Prefix or tag for the research of entities. |
state | The new state to apply. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
isPrefix | Tells if the first parameter should be considered as a prefix or a tag. |
void Environment::setEntityState | ( | const std::string & | name, |
bool | state, | ||
bool | share = true ) |
Let you set an entity's state with its name.
Apply this state to every components of this entity.
name | Entity's name. |
state | The new state to apply. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
void Environment::setEntityState | ( | int | entity, |
bool | state, | ||
bool | share = true ) |
Let you set an entity's state with its ID.
Apply this state to every components of this entity.
entity | Entity's ID. |
state | The new state to apply. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
void Environment::setState | ( | const std::string & | name, |
const std::string & | compName, | ||
bool | state, | ||
bool | share = true ) |
Set the state of a specific component for an entity, with its name.
name | Entity's name. |
compName | The name of the component. |
state | The new state to apply. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
void Environment::setState | ( | int | entity, |
const std::string & | compName, | ||
bool | state, | ||
bool | share = true ) |
Set the state of a specific component for an entity, with its ID.
entity | Entity's ID. |
compName | The name of the component. |
state | The new state to apply. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
void Environment::setStates | ( | const std::string & | prefixOrTag, |
const std::string & | compName, | ||
bool | state, | ||
bool | share = true, | ||
bool | isPrefix = true ) |
Set the state of a set of entities for a specific component.
The entities can be gathered from a prefix or from a tag.
prefixOrTag | Prefix or tag for the research of entities. |
compName | The name of the component. |
state | The new state to apply. |
share | Tells the method if you want the update to be shared to the systems. (default : true) |
isPrefix | Tells if the first parameter should be considered as a prefix or a tag. |