TailorMade 2.0
Tailor Made is a high-performance C++20 ECS library with on-the-fly entity creation and JSON-based definitions for entities, components, and their relationships.
 
Loading...
Searching...
No Matches
Environment.h
Go to the documentation of this file.
1
7
8
9#ifndef _ENVIRONMENT_H
10#define _ENVIRONMENT_H
11
12#include <ComponentManager.h>
13#include <EntityManager.h>
14#include <Subscription.h>
15
20typedef struct Snapshot {
22 std::unordered_map<std::string, std::vector<std::pair<std::string, dataVector>>> entities;
24
33
34
36public:
41 Environment(std::shared_ptr<EntityManager> entityManager);
42
50 Environment(const std::string& entitiesPath, const std::string& componentsPath, const std::string& subscriptionsPath);
51
56 void addManager(std::shared_ptr<ComponentManager> manager);
57
61 std::vector<std::shared_ptr<ComponentManager>> getManagers();
62
67 std::shared_ptr<ComponentManager> getManager(const std::string& name);
68
72 std::shared_ptr<EntityManager> getEntityManager();
73
81 void setEntityState(const std::string& name, bool state, bool share = true);
82
90 void setEntityState(int entity, bool state, bool share = true);
91
100 void setEntitiesState(const std::string& prefixOrTag, bool state, bool share = true, bool isPrefix = true);
101
109 void setState(int entity, const std::string& compName, bool state, bool share = true);
110
118 void setState(const std::string& name, const std::string& compName, bool state, bool share = true);
119
129 void setStates(const std::string& prefixOrTag, const std::string& compName, bool state, bool share = true, bool isPrefix = true);
130
136 bool getState(int entity, const std::string& compName);
137
143 bool getState(const std::string& name, const std::string& compName);
144
149 int getEntity(const std::string& name);
150
155 const std::string& getName(int entity);
156
164 int createEntity(const std::string& name, bool createFile = false, bool share = true);
165
172 void removeEntity(const std::string& name, bool share = true);
173
178 std::vector<std::shared_ptr<Component>> getComponents(int entity);
179
184 std::vector<std::shared_ptr<Component>> getComponents(const std::string& name);
185
191 std::shared_ptr<Component> getComponent(int entity, const std::string& name);
192
198 std::shared_ptr<Component> getComponent(const std::string& entityName, const std::string& name);
199
205 bool hasComponent(const std::string& name, const std::string& compName);
206
212 bool hasComponent(int entity, const std::string& compName);
213
219 bool hasTag(int entity, const std::string& tagName);
220
226 bool hasTag(const std::string& name, const std::string& tagName);
227
234 void addTag(int entity, const std::string& tag, bool share = true);
235
242 void addTag(const std::string& entity, const std::string& tag, bool share = true);
243
249 void save(int entity);
250
256 void save(const std::string& name);
257
264 void join(std::function<void(int)> callback, size_t ID);
265
271 void notify(int entity);
272
279 void notify(size_t ID);
280
289 int copy(const std::string& original, const std::string& copy, bool createFile = false, bool share = true);
290
299 void give(const std::string& component, int giver, int receiver, bool copy, bool share = true);
300
309 void makeSnapshot(const std::string& snapshotName, const std::vector<std::string>& toSave = {}, const std::vector<std::string>& components = {});
310
316 void loadSnapshot(const std::string& snapshotName);
317
322 void clearSnapshot(const std::string& snapshotName);
323
324private:
328 std::unordered_map<std::string, std::shared_ptr<ComponentManager>> mapNC;
329
333 std::shared_ptr<EntityManager> entityManager;
334
338 std::shared_ptr<Subscription> subscription;
339
343 std::unordered_map<size_t, std::function<void(int)>> notifiers;
344
348 std::unordered_map<std::string, Snapshot> snapshots;
349};
350
351#endif //_ENVIRONMENT_H
Project TailorMade.
Project TailorMade.
Project TailorMade.
std::shared_ptr< Component > getComponent(int entity, const std::string &name)
Return the component of a specific entity, with its ID.
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.
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 comp...
const std::string & getName(int entity)
Return an entity's name from its ID.
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 addTag(const std::string &entity, const std::string &tag, bool share=true)
Add a tag to an entity.
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.
std::shared_ptr< ComponentManager > getManager(const std::string &name)
Return a specific ComponentManager.
std::vector< std::shared_ptr< ComponentManager > > getManagers()
Return all the ComponentManagers.
Environment(std::shared_ptr< EntityManager > entityManager)
Constructor of an Environment without files, the only need is an EntityManager.
bool getState(const std::string &name, const std::string &compName)
Return the state of an entity's component, with its name.
std::shared_ptr< Component > getComponent(const std::string &entityName, const std::string &name)
Return the component of a specific entity, with its name.
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 subscripti...
bool hasComponent(const std::string &name, const std::string &compName)
Return true if the given entity possess the given component, false otherwise.
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 save(int entity)
Let you save the subscription of an entity in a file, it will preserve the current values of the comp...
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.
std::shared_ptr< EntityManager > getEntityManager()
Return the EntityManager.
void removeEntity(const std::string &name, bool share=true)
Remove an entity from the EntityManager.
bool hasComponent(int entity, const std::string &compName)
Return true if the given entity possess the given component, false otherwise.
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 addTag(int entity, const std::string &tag, bool share=true)
Add a tag to an entity.
int getEntity(const std::string &name)
Return an entity's ID from its name.
void join(std::function< void(int)> callback, size_t ID)
Let you join the Environment's update list.
int 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.
bool hasTag(const std::string &name, const std::string &tagName)
Return true if the entity have the given tag, false otherwise.
int createEntity(const std::string &name, bool createFile=false, bool share=true)
Create a new entity and return its ID.
void notify(size_t ID)
Will share with a specific system all the entities currently in the environment.
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 addManager(std::shared_ptr< ComponentManager > manager)
Let you add a ComponentManager from the environment interface.
bool hasTag(int entity, const std::string &tagName)
Return true if the entity have the given tag, false otherwise.
bool getState(int entity, const std::string &compName)
Return the state of an entity's component, with its ID.
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.
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.
void notify(int entity)
Will notify every callbacks of an update in the environment.
Structure of the Snapshot, store the data of the desired components on a subset of entities.
Definition Environment.h:20
std::unordered_map< std::string, std::vector< std::pair< std::string, dataVector > > > entities
Contain every data of the desired components for the registered entities.
Definition Environment.h:22