10#include <unordered_map>
41 if (
const auto it = _components.find(typeId); it != _components.end()) {
45 auto* raw = component.get();
46 _components[typeId] = raw;
47 _componentStorage.push_back(std::move(component));
56 template <
class ComponentType>
60 if (
const auto it = _components.find(typeId); it != _components.end()) {
64 if (!_engine || !_engine->systems()) {
68 auto* system = _engine->systems()->template getByComponentType<ComponentType>();
73 auto component = system->addComponent(
this);
78 auto* raw = component.get();
79 _components[typeId] = raw;
80 _componentStorage.push_back(std::move(component));
82 if constexpr (std::is_same_v<ComponentType, ScriptComponent>) {
94 requires std::derived_from<T, Component>
98 if (it == _components.end()) {
101 return static_cast<T*
>(it->second);
108 requires std::derived_from<T, Component>
111 std::vector<T*> result;
113 if (it == _components.end())
117 result.push_back(
static_cast<T*
>(it->second));
145 const std::unordered_map<ComponentTypeID, Component*>&
components()
const {
return _components; }
155 Engine* _engine =
nullptr;
158 std::unordered_map<ComponentTypeID, Component*> _components;
159 std::vector<std::unique_ptr<Component>> _componentStorage;
Base class for ECS components that attach functionality to entities.
Central application orchestrator managing scenes, rendering, input, and resource loading.
ECS entity — a GraphNode that hosts components defining its behavior.
void setEngine(Engine *engine)
Component * addComponent()
ScriptComponent * script() const
void onHierarchyStateChanged(bool enabled) override
const std::unordered_map< ComponentTypeID, Component * > & components() const
Component * addComponentInstance(std::unique_ptr< Component > component, ComponentTypeID typeId)
Engine * findEngine() const
std::vector< T * > findComponents()
GraphNode(const std::string &name="Untitled")
ComponentTypeID componentTypeID()
std::size_t ComponentTypeID