VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
script.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 28.12.2025
5//
6#pragma once
7
8#include <core/eventHandler.h>
9
10#define SCRIPT_NAME(Name) \
11 static constexpr const char* scriptName() { return Name; }
12
13namespace visutwin::canvas
14{
15 class Entity;
16 class ScriptComponent;
17
37 class Script: public EventHandler
38 {
39 public:
44 virtual void initialize() {}
45
50 virtual void postInitialize() {}
51
52 /*
53 * Called at a fixed interval for deterministic simulation (physics, etc.).
54 * The fixedDt is constant across calls (default 1/60s).
55 */
56 virtual void fixedUpdate(float fixedDt) {}
57
58 /*
59 * Called for enabled (running state) scripts on each tick
60 */
61 virtual void update(float dt) {}
62
63 /*
64 * Called after all scripts update on each tick.
65 */
66 virtual void postUpdate(float dt) {}
67
68 bool enabled() const;
69
70 protected:
71 Entity* entity() const { return _entity; }
72
73 private:
74 friend class ScriptComponent;
75
76 bool _enabled = true;
77 bool _initialized = false;
78 bool _postInitialized = false;
79 Entity* _entity = nullptr;
80 };
81}
ECS entity — a GraphNode that hosts components defining its behavior.
Definition entity.h:32
virtual void fixedUpdate(float fixedDt)
Definition script.h:56
virtual void postUpdate(float dt)
Definition script.h:66
friend class ScriptComponent
Definition script.h:74
virtual void postInitialize()
Definition script.h:50
bool enabled() const
Definition script.cpp:13
virtual void initialize()
Definition script.h:44
virtual void update(float dt)
Definition script.h:61
Entity * entity() const
Definition script.h:71