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
ComponentManager.h
Go to the documentation of this file.
1
7
8#ifndef _COMPONENTMANAGER_H
9#define _COMPONENTMANAGER_H
10#include <Component.h>
11#include <memory>
12
21
22
24public:
29 ComponentManager(const std::string& filename);
30
37 ComponentManager(std::shared_ptr<Component> component);
38
42 const std::string& getName();
43
49 const std::string& getType(const std::string& data);
50
56 void subscribe(int entity);
57
64 void subscribe(int entity, dataVector data);
65
70 void unsubscribe(int entity);
71
77 std::vector<int> getEntities(bool checkState);
78
83 std::shared_ptr<Component> getComponent(int entity);
84
89 bool hasEntity(int entity);
90
95 bool getState(int entity);
96
102 void setState(int entity, bool newState);
103
110 void give(int giver, int receiver, bool copy);
111
116 void toString(std::ostream& stream);
117
118private:
122 std::unordered_map<int, std::pair<std::shared_ptr<Component>, bool>> mapEC;
123
127 std::shared_ptr<Component> referenceComp;
128
132 std::mutex mtx;
133};
134
135#endif //_COMPONENTMANAGER_H
Project TailorMade.
std::vector< std::pair< std::string, std::variant< ECS_Types > > > dataVector
Vector of {dataType, value}.
Definition TM_Tools.h:163
void unsubscribe(int entity)
Remove the link between an entity and its component.
void toString(std::ostream &stream)
Add to the given buffer, the serialized version of this ComponentManager, which will consist of the l...
void subscribe(int entity)
Subscribe an entity to this component.
const std::string & getType(const std::string &data)
Return a string which give the type of the data.
void subscribe(int entity, dataVector data)
Subscribe an entity to this component with specific values.
bool hasEntity(int entity)
Return true if the given entity possess this component, false otherwise.
void give(int giver, int receiver, bool copy)
Give the ownership, or make a copy, of an entity's component to another component.
const std::string & getName()
Return the name of the component managed by this instance.
bool getState(int entity)
Return the actual state of the given entity's component, true or false.
ComponentManager(std::shared_ptr< Component > component)
Create a ComponentManager with a reference component.
ComponentManager(const std::string &filename)
The main constructor of the ComponentManager, created the components based of the file's description.
std::vector< int > getEntities(bool checkState)
Return the list of entities linked in this component's manager.
std::shared_ptr< Component > getComponent(int entity)
Return the component of a specific entity.
void setState(int entity, bool newState)
Set the state of the given entity's component.