VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
scriptComponentSystem.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
#pragma once
7
8
#include "
core/sortedLoopArray.h
"
9
#include "
scriptComponent.h
"
10
#include "
framework/components/componentSystem.h
"
11
12
namespace
visutwin::canvas
13
{
14
/*
15
* Allows scripts to be attached to an Entity and executed
16
*/
17
class
ScriptComponentSystem
:
public
ComponentSystem
<ScriptComponent, ScriptComponentData>
18
{
19
public
:
20
ScriptComponentSystem
(
Engine
*
engine
)
21
:
ComponentSystem
(
engine
,
"script"
),
22
_components(
SortedLoopArrayOptions
<
ScriptComponent
*>{
23
.keyExtractor = [](
ScriptComponent
* component) {
24
return
component ?
static_cast<
float
>
(component->executionOrder()) : 0.0f;
25
}
26
})
27
{
28
}
29
30
std::unique_ptr<Component>
addComponent
(
Entity
* entity)
override
31
{
32
auto
component = std::make_unique<ScriptComponent>(
this
, entity);
33
component->initializeComponentData();
34
component->setExecutionOrder(_executionCounter++);
35
_components.append(component.get());
36
return
component;
37
}
38
39
void
fixedUpdate
(
float
fixedDt)
40
{
41
for
(_components.loopIndex = 0; _components.loopIndex <
static_cast<
int
>
(_components.length); _components.loopIndex++) {
42
auto
* component = _components.items[_components.loopIndex];
43
if
(component) {
44
component->fixedUpdateScripts(fixedDt);
45
}
46
}
47
}
48
49
void
update
(
float
dt)
50
{
51
for
(_components.loopIndex = 0; _components.loopIndex <
static_cast<
int
>
(_components.length); _components.loopIndex++) {
52
auto
* component = _components.items[_components.loopIndex];
53
if
(component) {
54
component->updateScripts(dt);
55
}
56
}
57
}
58
59
void
postUpdate
(
float
dt)
60
{
61
for
(_components.loopIndex = 0; _components.loopIndex <
static_cast<
int
>
(_components.length); _components.loopIndex++) {
62
auto
* component = _components.items[_components.loopIndex];
63
if
(component) {
64
component->postUpdateScripts(dt);
65
}
66
}
67
}
68
69
private
:
70
SortedLoopArray<ScriptComponent*>
_components;
71
int
_executionCounter = 0;
72
};
73
}
visutwin::canvas::ComponentSystem< ScriptComponent, ScriptComponentData >::ComponentSystem
ComponentSystem(Engine *engine, const std::string &id)
Definition
componentSystem.h:42
visutwin::canvas::Engine
Central application orchestrator managing scenes, rendering, input, and resource loading.
Definition
engine.h:38
visutwin::canvas::Entity
ECS entity — a GraphNode that hosts components defining its behavior.
Definition
entity.h:32
visutwin::canvas::IComponentSystem::engine
Engine * engine() const
Definition
componentSystem.h:27
visutwin::canvas::ScriptComponent
Definition
scriptComponent.h:29
visutwin::canvas::ScriptComponentSystem::ScriptComponentSystem
ScriptComponentSystem(Engine *engine)
Definition
scriptComponentSystem.h:20
visutwin::canvas::ScriptComponentSystem::fixedUpdate
void fixedUpdate(float fixedDt)
Definition
scriptComponentSystem.h:39
visutwin::canvas::ScriptComponentSystem::addComponent
std::unique_ptr< Component > addComponent(Entity *entity) override
Definition
scriptComponentSystem.h:30
visutwin::canvas::ScriptComponentSystem::update
void update(float dt)
Definition
scriptComponentSystem.h:49
visutwin::canvas::ScriptComponentSystem::postUpdate
void postUpdate(float dt)
Definition
scriptComponentSystem.h:59
visutwin::canvas::SortedLoopArray
Definition
sortedLoopArray.h:19
componentSystem.h
visutwin::canvas
Definition
eventHandler.cpp:9
scriptComponent.h
sortedLoopArray.h
visutwin::canvas::SortedLoopArrayOptions
Definition
sortedLoopArray.h:13
framework
components
script
scriptComponentSystem.h
Generated by
1.16.1