VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
scriptComponent.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 10.09.2025.
5//
6#pragma once
7
8#include <memory>
9#include <string>
10#include <unordered_map>
11#include <vector>
12
15
16namespace visutwin::canvas
17{
19 {
20 };
21
23 {
24 bool enabled = true;
25 bool preloading = false;
26 };
27
29 {
30 public:
32
33 Script* create(const std::string& name, const ScriptCreateOptions& options = {});
34
35 template<typename T>
36 T* create() {
37 static_assert(std::is_base_of_v<Script, T>, "T must derive from Script");
38 return static_cast<T*>(create(T::scriptName()));
39 }
40
41 void initializeComponentData() override {};
42
43 void setEnabled(bool value) override;
44 void fixedUpdateScripts(float fixedDt);
45 void updateScripts(float dt);
46 void postUpdateScripts(float dt);
47
48 int executionOrder() const { return _executionOrder; }
49 void setExecutionOrder(const int value) { _executionOrder = value; }
50
51 private:
52 void initializeScriptInstance(Script* script);
53
54 struct ScriptEntry
55 {
56 std::string name;
57 std::unique_ptr<Script> instance;
58 };
59
60 std::unordered_map<std::string, size_t> _scriptsIndex;
61
62 std::vector<ScriptEntry> _scripts;
63 int _executionOrder = 0;
64 };
65}
Entity * entity() const
Definition component.cpp:16
Component(IComponentSystem *system, Entity *entity)
Definition component.cpp:12
IComponentSystem * system() const
Definition component.h:47
ECS entity — a GraphNode that hosts components defining its behavior.
Definition entity.h:32
void setExecutionOrder(const int value)
ScriptComponent(IComponentSystem *system, Entity *entity)
void setEnabled(bool value) override