Toast Engine
Loading...
Searching...
No Matches
toast::Node Class Reference
Inheritance diagram for toast::Node:
Collaboration diagram for toast::Node:

Public Member Functions

auto uid () const noexcept -> const UID &
 Stable unique identifier, assigned at construction or deserialization. Never changes.
auto rid () const noexcept -> std::uintptr_t
 Runtime identifier for this node, guaranteed to be unique but changes every time.
auto name () const noexcept -> std::string_view
 Display name. Siblings may share one - this is not an identifier.
void name (std::string_view name) noexcept
 Sets the display name.
auto enabled () const noexcept -> bool
 Whether this node is currently active.
auto participatesIn (NodeOwnerParticipation use) const noexcept -> bool
auto owner () const noexcept -> INodeOwner *
 The World or Workspace this node belongs to.
void enabled (bool value) noexcept
 Sets the local enabled flag and propagates the change to all children.
auto box () const noexcept -> Box< Node >
 Returns an owning handle to this node.
auto info () const -> const NodeInfo *
 Reflection metadata registered by the code generator.
auto sourcePrefab () const noexcept -> const assets::Handle< assets::Prefab > &
 The prefab this node was instantiated from.
auto isInstanceRoot () const noexcept -> bool
 Whether this node is the root of a prefab instance.
auto root () const noexcept -> Box< Node >
 The topmost ancestor that is not the world root.
auto state () const noexcept -> NodeState
auto type () const noexcept -> NodeType
auto listener () noexcept -> event::Listener &
 The event Listener owned by this node. Lazy-allocated, freed only with the node.
auto parent () noexcept -> Box< Node >
 The immediate parent of this node.
auto children () const noexcept -> const std::vector< Box< Node > > &
 The ordered list of direct children.
auto childrenSnapshot () const -> std::vector< Box< Node > >
auto create (std::string_view type="toast::Node") noexcept -> Box< Node >
 Creates a new child node of the given type and attaches it to this node.
auto spawn (UID uid) noexcept -> Box< Node >
 Asynchronously instantiates a prefab as a child of this node.
auto spawn (std::string_view uri) noexcept -> Box< Node >
 Asynchronously instantiates a prefab as a child of this node.
auto find (std::string_view query) -> Box< Node >
 Depth-first search for a single descendant.
auto find (const UID &uid) -> Box< Node >
 Looks up a node by UID within this node's local root.
auto search (std::string_view query) -> std::vector< Box< Node > >
 Depth-first search for all matching descendants.
auto childrenOfType (const NodeInfo *type) const -> std::vector< Box< Node > >
auto searchType (const NodeInfo *type) const -> std::vector< Box< Node > >
void addDependsOn (Node &other)
void removeDependsOn (Node &other)
void interactsWith (Node &other)
 Declares that the scripts of this node and of other call each other.
auto scriptRuntime () noexcept -> scripting::ScriptRuntime *
auto hasTickFunction (TickFunctionList mask) const noexcept -> bool
auto scriptVm (TickFunctionList func) const noexcept -> std::optional< size_t >
 The interpreter this node runs Lua on while it executes func, empty when it runs none.
auto scriptVmAny () const noexcept -> std::optional< size_t >
 The interpreter the scripts of this node live on whatever phase they define.
auto hasCallable (std::string_view name) const noexcept -> bool
void reloadScripts () noexcept
 Rebuilds the script runtime after a script asset changed (hot reload or attach).
auto scripts () const noexcept -> const std::vector< assets::Handle< assets::Script > > &
void setScripts (std::vector< assets::Handle< assets::Script > > scripts) noexcept
void addScript (const assets::Handle< assets::Script > &script) noexcept
template<typename R = void, typename... Args>
auto call (std::string_view name, Args &&... args) -> R
 Invokes all C++ reflected implementations of name (base→derived) and all same-named Lua functions across every attached script, forwarding args.
template<typename T>
auto get (std::string_view name) const -> T
 Reads a named value: reflected C++ field first, then the first matching Lua instance variable.
template<typename T>
void set (std::string_view name, const T &value)
 Writes a named value: reflected C++ field if present and every Lua instance variable of that name that already exists.
auto isRecursivePrefab () const noexcept -> bool

Public Attributes

signals::Signal< Box< Node > > on_enable
signals::Signal< Box< Node > > on_disable
signals::Signal< Box< Node > > on_begin
signals::Signal< Box< Node > > on_end

Protected Member Functions

virtual void onReflectedFieldChanged (std::string_view)
virtual void onScriptsReloaded ()
virtual void onScriptsReloading ()
virtual auto luaAffinity () const noexcept -> std::optional< size_t >
virtual void onScriptVarChanged (std::string_view path)
virtual void updateInspectorMessages ()
void addInspectorMessage (const NodeMessage &message)
void removeInspectorMessage (const NodeMessage &message)

Protected Attributes

INodeOwner * m_owner = nullptr

Friends

class INodeOwner
class World
class Workspace
class PlayWorkspace
class TickScheduler
class Node3D
class assets::Prefab
struct _detail::ControlBox
struct _detail::NodeCluster
struct toast::_detail::WorldTestAccess
class physics::Collider

Member Function Documentation

◆ addScript()

void toast::Node::addScript ( const assets::Handle< assets::Script > & script)
inlinenoexcept

Attaches a script at the end and rebuilds the script runtime

◆ box()

auto toast::Node::box ( ) const -> Box< Node >
nodiscardnoexcept

Returns an owning handle to this node.

Returns
A Box<Node> that shares ownership; always valid while the node exists; safe to store
Here is the caller graph for this function:

◆ call()

template<typename R = void, typename... Args>
auto toast::Node::call ( std::string_view name,
Args &&... args ) -> R
inline

Invokes all C++ reflected implementations of name (base→derived) and all same-named Lua functions across every attached script, forwarding args.

Template Parameters
RReturn type, for non-void the most-derived C++ return value is returned

◆ children()

auto toast::Node::children ( ) const -> const std::vector< Box< Node > > &
inlinenodiscardnoexcept

The ordered list of direct children.

Returns
Const reference to the internal children vector
Warning
Do not store raw pointers or references into this vector; it may reallocate when children are added or removed
Here is the caller graph for this function:

◆ create()

auto toast::Node::create ( std::string_view type = "toast::Node") -> Box< Node >
inlinenoexcept

Creates a new child node of the given type and attaches it to this node.

Parameters
typeFully-qualified C++ class name, e.g. "toast::Node3D"; defaults to "toast::Node"
Returns
The new child node, or an empty box if the type is not registered
Note
Only valid on nodes in the root or global state; calls the child's init lifecycle
Here is the caller graph for this function:

◆ enabled() [1/2]

auto toast::Node::enabled ( ) const -> bool
nodiscardnoexcept

Whether this node is currently active.

Returns
false if either the local enabled flag or any ancestor's flag is false; nodes in the cached state are always disabled
Here is the caller graph for this function:

◆ enabled() [2/2]

void toast::Node::enabled ( bool value)
noexcept

Sets the local enabled flag and propagates the change to all children.

Parameters
valuePassing false disables the entire subtree without unregistering event callbacks

◆ find() [1/2]

auto toast::Node::find ( const UID & uid) -> Box< Node >
nodiscard

Looks up a node by UID within this node's local root.

Parameters
uidUID of the node to find
Returns
The match, or an empty box if nothing was found
Note
Scoped to the nearest instance-root ancestor

◆ find() [2/2]

auto toast::Node::find ( std::string_view query) -> Box< Node >
nodiscard

Depth-first search for a single descendant.

Parameters
queryA bare name, a slash-separated path, or a node:// URI with namespace keywords: root, world, global
Returns
The first match, or an empty box if nothing was found
Note
Traversal stops at prefab-instance boundaries; interior nodes are opaque to find()
See also
search()
Here is the caller graph for this function:

◆ get()

template<typename T>
auto toast::Node::get ( std::string_view name) const -> T
inlinenodiscard

Reads a named value: reflected C++ field first, then the first matching Lua instance variable.

Returns
The field/variable value cast to T, or T{} on void

◆ hasCallable()

auto toast::Node::hasCallable ( std::string_view name) const -> bool
nodiscardnoexcept
Returns
true when a reflected C++ or Lua function exists

◆ hasTickFunction()

auto toast::Node::hasTickFunction ( TickFunctionList mask) const -> bool
nodiscardnoexcept
Returns
true if this node implements any of the given tick functions in C++ or Lua

◆ info()

auto toast::Node::info ( ) const -> const NodeInfo *
nodiscard

Reflection metadata registered by the code generator.

Returns
Pointer to the static NodeInfo for this type, or nullptr for a bare Node instance that was never registered with NodeRegistry
See also
NodeRegistry::reflect()

◆ isInstanceRoot()

auto toast::Node::isInstanceRoot ( ) const -> bool
nodiscardnoexcept

Whether this node is the root of a prefab instance.

Note
find() stops traversal here so the outer tree cannot reach into a prefab's interior
See also
find()

◆ luaAffinity()

virtual auto toast::Node::luaAffinity ( ) const -> std::optional< size_t >
inlinenodiscardprotectedvirtualnoexcept

Reimplemented in toast::StateMachine.

◆ name()

void toast::Node::name ( std::string_view name)
noexcept

Sets the display name.

Parameters
nameNew name; copied internally

◆ onScriptsReloading()

virtual void toast::Node::onScriptsReloading ( )
inlineprotectedvirtual

Runs right before the script runtime is torn down and built again

Reimplemented in toast::VoxelPiece.

◆ onScriptVarChanged()

virtual void toast::Node::onScriptVarChanged ( std::string_view path)
inlineprotectedvirtual

A script variable was edited from outside the script, path is "<instance>:<group/name>"

Reimplemented in toast::VoxelPiece.

◆ owner()

auto toast::Node::owner ( ) const -> INodeOwner *
inlinenodiscardnoexcept

The World or Workspace this node belongs to.

Tells whose tree a node came from without downcasting. Proxies land in one global list regardless of owner, so the renderer needs this to keep one workspace out of another's viewport

Here is the caller graph for this function:

◆ parent()

auto toast::Node::parent ( ) -> Box< Node >
nodiscardnoexcept

The immediate parent of this node.

Returns
An empty box if this node is a root or world root

◆ root()

auto toast::Node::root ( ) const -> Box< Node >
nodiscardnoexcept

The topmost ancestor that is not the world root.

Returns
An empty box if this node itself is a root node

◆ scripts()

auto toast::Node::scripts ( ) const -> const std::vector< assets::Handle< assets::Script > > &
inlinenodiscardnoexcept

The scripts attached to this node in call order

Here is the caller graph for this function:

◆ scriptVm()

auto toast::Node::scriptVm ( TickFunctionList func) const -> std::optional< size_t >
nodiscardnoexcept

The interpreter this node runs Lua on while it executes func, empty when it runs none.

That is the interpreter of its own scripts when they define func, or, for a C++ node that calls functions a script gave it, the one those functions live on, see luaAffinity()

The scheduler keeps everything that shares an interpreter so two threads dont want the same interpreter

◆ search()

auto toast::Node::search ( std::string_view query) -> std::vector< Box< Node > >
nodiscard

Depth-first search for all matching descendants.

Parameters
querySame syntax as find()
Returns
All matches in depth-first order; may be empty
Note
Unlike find(), search() crosses prefab-instance boundaries
See also
find()

◆ setScripts()

void toast::Node::setScripts ( std::vector< assets::Handle< assets::Script > > scripts)
inlinenoexcept

Replaces every script and rebuilds the script runtime

Here is the caller graph for this function:

◆ sourcePrefab()

auto toast::Node::sourcePrefab ( ) const -> const assets::Handle< assets::Prefab > &
nodiscardnoexcept

The prefab this node was instantiated from.

Returns
An empty Handle for nodes created at runtime

◆ spawn() [1/2]

auto toast::Node::spawn ( std::string_view uri) -> Box< Node >
inlinenoexcept

Asynchronously instantiates a prefab as a child of this node.

Parameters
uriVirtual URI of the prefab asset, e.g. "assets://characters/knight.node"
Returns
An empty box immediately; the child appears at the start of the next frame
Note
Only valid on root or global nodes; each instance receives a fresh UID

◆ spawn() [2/2]

auto toast::Node::spawn ( UID uid) -> Box< Node >
inlinenoexcept

Asynchronously instantiates a prefab as a child of this node.

Parameters
uidUID of the prefab asset to load
Returns
An empty box immediately; the child appears at the start of the next frame
Note
Only valid on root or global nodes; each instance receives a fresh UID

◆ state()

auto toast::Node::state ( ) const -> NodeState
inlinenodiscardnoexcept
Returns
The current NodeState (null, loading, cached, root, global, or destroy)
Here is the caller graph for this function:

◆ type()

auto toast::Node::type ( ) const -> NodeType
inlinenodiscardnoexcept
Returns
The current NodeType (null, child, root, or world_root)
Here is the caller graph for this function:

The documentation for this class was generated from the following files:
  • engine/src/toast/world/node.hpp
  • engine/src/toast/world/node.cpp