VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
componentSystem.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4// Created by Arnis Lektauers on 05.09.2025.
5//
6
7#pragma once
8
9#include <string>
10#include <typeinfo>
11
12#include "component.h"
13#include "framework/engine.h"
14#include "framework/entity.h"
15
16namespace visutwin::canvas
17{
19 {
20 public:
21 virtual ~IComponentSystem() = default;
22 IComponentSystem(Engine* engine, const std::string& id) : _engine(engine), _id(id) {}
23
24 virtual std::unique_ptr<Component> addComponent(Entity* entity) = 0;
25
26 [[nodiscard]] const std::string& id() const { return _id; }
27 Engine* engine() const { return _engine; }
28
29 virtual const std::type_info& componentType() const = 0;
30 protected:
31 std::string _id;
33 };
34
35 /*
36 * Component Systems contain the logic and functionality to update all Components of a particular type
37 */
38 template <class ComponentType, class DataType>
40 {
41 public:
42 ComponentSystem(Engine* engine, const std::string& id) : IComponentSystem(engine, id) {}
43
44 // Create new Component and component data instances and attach them to the entity.
45 std::unique_ptr<Component> addComponent(Entity* entity) override;
46
47 const std::type_info& componentType() const override { return typeid(ComponentType); }
48 };
49}
50
51#include "componentSystem.inl"
ComponentSystem(Engine *engine, const std::string &id)
const std::type_info & componentType() const override
std::unique_ptr< Component > addComponent(Entity *entity) override
Central application orchestrator managing scenes, rendering, input, and resource loading.
Definition engine.h:38
ECS entity — a GraphNode that hosts components defining its behavior.
Definition entity.h:32
IComponentSystem(Engine *engine, const std::string &id)
virtual std::unique_ptr< Component > addComponent(Entity *entity)=0
virtual const std::type_info & componentType() const =0
const std::string & id() const