VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
visutwin::canvas::Script Class Reference

#include <framework/script/script.h>

Inheritance diagram for visutwin::canvas::Script:
[legend]

Public Member Functions

bool enabled () const
virtual void fixedUpdate (float fixedDt)
virtual void initialize ()
virtual void postInitialize ()
virtual void postUpdate (float dt)
virtual void update (float dt)
Public Member Functions inherited from visutwin::canvas::EventHandler
template<typename... Args>
EventHandlerfire (const std::string &name, Args &&... args)
bool hasEvent (const std::string &name) const
void initEventHandler ()
template<typename Callback>
requires (!std::is_same_v<std::decay_t<Callback>, HandleEventCallback>)
EventHandleroff (const std::string &name, Callback &&callback, void *scope=nullptr)
EventHandleroff (const std::string &name="", const HandleEventCallback &callback=HandleEventCallback(), void *scope=nullptr)
EventHandleroffByHandle (EventHandle *handle)
template<typename Callback>
requires (!std::is_same_v<std::decay_t<Callback>, HandleEventCallback>)
EventHandleon (const std::string &name, Callback &&callback, void *scope=nullptr)
EventHandleon (const std::string &name, HandleEventCallback callback, void *scope=nullptr)
template<typename Callback>
requires (!std::is_same_v<std::decay_t<Callback>, HandleEventCallback>)
EventHandleonce (const std::string &name, Callback &&callback, void *scope=nullptr)
EventHandleonce (const std::string &name, HandleEventCallback callback, void *scope=nullptr)
virtual ~EventHandler ()=default

Protected Member Functions

Entityentity () const
Protected Member Functions inherited from visutwin::canvas::EventHandler
EventHandleaddCallback (const std::string &name, HandleEventCallback callback, void *scope=nullptr, bool once=false)

Friends

class ScriptComponent

Detailed Description

The Script class is the fundamental base class for all scripts within VisuTwin Canvas. It provides the minimal interface required for a script to be compatible with both the Engine and the Editor.

At its core, a script is simply a collection of methods that are called at various points in the Engine's lifecycle. These methods are:

  • initialize() - Called once when the script is initialized.
  • postInitialize() - Called once after all scripts have been initialized.
  • update(dt) - Called every frame, if the script is enabled.
  • postUpdate(dt) - Called every frame, after all scripts have been updated.
  • swap(old) - Called when a script is redefined (hot-swapping).

These methods are entirely optional but provide a useful way to manage the lifecycle of a script and perform any necessary setup and cleanup.

Definition at line 37 of file script.h.

Member Function Documentation

◆ enabled()

◆ entity()

Entity * visutwin::canvas::Script::entity ( ) const
inlineprotected

◆ fixedUpdate()

virtual void visutwin::canvas::Script::fixedUpdate ( float fixedDt)
inlinevirtual

Definition at line 56 of file script.h.

Referenced by visutwin::canvas::ScriptComponent::fixedUpdateScripts().

◆ initialize()

virtual void visutwin::canvas::Script::initialize ( )
inlinevirtual

Called when script is about to run for the first time. Override this method in subclasses to implement custom initialization logic.

Reimplemented in visutwin::canvas::AnnotationManager, and visutwin::canvas::ShadowCatcher.

Definition at line 44 of file script.h.

◆ postInitialize()

virtual void visutwin::canvas::Script::postInitialize ( )
inlinevirtual

Called after all initialize methods are executed in the same tick or enabling chain of actions. Override this method in subclasses to implement post-initialization logic.

Definition at line 50 of file script.h.

◆ postUpdate()

virtual void visutwin::canvas::Script::postUpdate ( float dt)
inlinevirtual

Definition at line 66 of file script.h.

Referenced by visutwin::canvas::ScriptComponent::postUpdateScripts().

◆ update()

virtual void visutwin::canvas::Script::update ( float dt)
inlinevirtual

Reimplemented in visutwin::canvas::AnnotationManager.

Definition at line 61 of file script.h.

Referenced by visutwin::canvas::ScriptComponent::updateScripts().

◆ ScriptComponent

friend class ScriptComponent
friend

Definition at line 74 of file script.h.

References ScriptComponent.

Referenced by ScriptComponent.


The documentation for this class was generated from the following files: