Toast Engine
Loading...
Searching...
No Matches
toast::World Class Referencefinal
Inheritance diagram for toast::World:
Collaboration diagram for toast::World:

Public Member Functions

auto name () -> std::string override
void tick () override
auto participatesIn (NodeOwnerParticipation) const noexcept -> bool override
 Determines if this owner is elegible for runtime systems.
void registerDependency (Node &from, Node &to) override
 Records a tick ordering constraint between two active nodes.
void unregisterDependency (Node &from, Node &to) override
void registerInteraction (Node &first, Node &second) override
auto findFrom (const Node &origin, std::string_view query) -> Box< Node > override
auto findFrom (const Node &origin, const UID &uid) -> Box< Node > override
auto searchFrom (const Node &origin, std::string_view query) -> std::vector< Box< Node > > override
auto dependencyGraphGraphviz () const -> std::string
Public Member Functions inherited from toast::INodeOwner
virtual auto asWorkspace () -> Workspace *
 Downcast helper for owners that need Workspace-specific state.
virtual auto receivesEvents () const noexcept -> bool
void syncListenerState () noexcept
auto isEditing () noexcept -> bool
 True for a Workspace open for editing: lifecycle callbacks still run there, but the game is not running.
auto treeMutex () const noexcept -> std::shared_mutex &
virtual void nodeEnabledChanged (Node &node) noexcept
void activateCamera (Camera &camera)
void setMainCamera (Camera &camera)
 Like activateCamera(), but replaces whatever camera is currently active.
void deactivateCamera (Camera &camera)
void activateCameraController (CameraController &controller)
void deactivateCameraController (CameraController &controller)
auto requestRuntimeCreate (Node &parent, std::string_view type) -> Box< Node >
auto requestRuntimeSpawn (Node &parent, UID uid) -> Box< Node >
auto requestRuntimeSpawn (Node &parent, std::string_view) -> Box< Node >
void reloadScriptsUsing (UID script_uid) noexcept
void refreshNodeInfos () noexcept
void rebindAssetHandles (UID asset_uid) noexcept

Static Public Member Functions

static void loadNode (UID uid)
 Begins asynchronous loading of a prefab into the cache.
static void loadNode (std::string_view uri)
 Begins asynchronous loading of a prefab into the cache.
static auto setRoot (Node &node) -> Box< Node >
 Promotes a cached or global node to be the active world root.
static auto cacheNode (Node &node) -> Box< Node >
 Moves an active node back to the cached state, disabling it and calling its end() lifecycle.
static void destroyNode (Node &node)
 Schedules a cached node for destruction at the start of the next tick.
static auto findCached (std::string_view name) -> Box< Node >
 Linear search for a cached root node by display name.
static auto graphviz () -> std::string
 Serializes the current tick schedule as a Graphviz DOT string.
static void hotReload ()
 Refreshes the NodeInfo pointers on every live node after a game library hot reload.
static void hotReloadScripts (toast::UID script_uid)
 Recomputes the tick schedule after the script runtimes using the given script asset were rebuilt.
Static Public Member Functions inherited from toast::INodeOwner
static void reapOrphanedControlBoxes () noexcept

Friends

struct toast::_detail::WorldTestAccess

Additional Inherited Members

Protected Member Functions inherited from toast::INodeOwner
virtual auto owningPrefabUid () const -> UID
void seedPrefabContext (InstantiateContext &context, const Node *parent=nullptr) const
auto nodeAllocation (std::string_view type="toast::Node") noexcept -> Box< Node >
 Allocates a Node and its ControlBox in one contiguous block.
auto nodeAllocation (const assets::Prefab::BasicNode &node_data, uint64_t script_group=0, bool build_scripts=true) noexcept -> Box< Node >
 Allocates a Node and initializes its name and type from a prefab data record.
void buildLeaves (const assets::Handle< assets::Prefab > &file, uint64_t group, const std::vector< size_t > &leaf_slots, std::vector< Box< Node > > &slots)
auto buildTree (std::vector< Box< Node > > &&nodes, const assets::Handle< assets::Prefab > &file) -> Box< Node >
 Assembles a flat list of allocated nodes into a parent/child tree.
auto instantiate (const assets::Handle< assets::Prefab > &file, InstantiateContext &ctx) -> Box< Node >
 Allocates and initializes a full node tree from a prefab asset.
void applyFields (Node &node, const assets::Prefab::BasicNode &data)
 Copies reflected field values from the serialized BasicNode onto the live node; skips fields absent from NodeInfo.
void applyLuaOverrides (Node &node, const assets::Prefab::BasicNode &data, const scripting::NodeResolver &find_node)
 Restores edited Lua script variables saved in the prefab.
void releaseNode (_detail::ControlBox &control) noexcept
 Marks the ControlBox as dead and increments tombstones; does not free memory.
void reapTombstones () noexcept
 Sweeps the nodes set and erases any ControlBox whose ref count is zero; short-circuits if tombstones == 0.
void findCamera ()
void findCameraController ()
void tickActiveCameraController ()
void beginCameraShutdown () noexcept
auto activeCamera () noexcept -> Box< Camera > &
auto activeRenderCamera () noexcept -> Camera *
template<typename Fn>
void forEachNode (Fn &&fn) const
Static Protected Member Functions inherited from toast::INodeOwner
static void updateTransforms (Node &root)
static void generateUid (Node &node)
 Assigns a fresh UID to the node; called on every spawned instance to avoid UID collisions.
static auto stripNamespace (std::string_view type) -> std::string_view
 Removes the "toast::" namespace prefix from a type name; used to derive default display names.
static auto uniqueChildName (const Node &parent, std::string_view base) -> std::string
 Appends " 2", " 3", etc. to base until the name is unique among the parent's existing children.
Protected Attributes inherited from toast::INodeOwner
std::mutex nodes_mutex
size_t tombstones = 0
 short-circuits the reap sweep when there's nothing to clean
physics::Accumulator m_accumulator

Member Function Documentation

◆ cacheNode()

auto toast::World::cacheNode ( Node & node) -> Box< Node >
static

Moves an active node back to the cached state, disabling it and calling its end() lifecycle.

Parameters
nodeAny node in the root or global state
Returns
The node's own box
Note
Caching the active world root leaves the world without a root until setRoot() is called again

◆ destroyNode()

void toast::World::destroyNode ( Node & node)
static

Schedules a cached node for destruction at the start of the next tick.

Parameters
nodeMust be in the cached state; active nodes must be cached first
Note
Code holding a Box<Node> to the node remains safe until the queue is drained next frame
Warning
Only cached nodes can be destroyed; attempting to destroy an active node logs a warning and does nothing

◆ findCached()

auto toast::World::findCached ( std::string_view name) -> Box< Node >
staticnodiscard

Linear search for a cached root node by display name.

Parameters
nameThe node's display name to search for
Returns
The first cached node with a matching name, or an empty box if not found
Note
Names are not unique; returns the first match

◆ findFrom() [1/2]

auto toast::World::findFrom ( const Node & origin,
const UID & uid ) -> Box< Node >
overridevirtual

Implements toast::INodeOwner.

◆ findFrom() [2/2]

auto toast::World::findFrom ( const Node & origin,
std::string_view query ) -> Box< Node >
overridevirtual

Implements toast::INodeOwner.

◆ graphviz()

auto toast::World::graphviz ( ) -> std::string
staticnodiscard

Serializes the current tick schedule as a Graphviz DOT string.

Returns
A DOT-format string visualizing nodes, waves, and dependency edges per phase; pass to the graphviz/dot tool to render

◆ hotReloadScripts()

void toast::World::hotReloadScripts ( toast::UID script_uid)
static

Recomputes the tick schedule after the script runtimes using the given script asset were rebuilt.

Note
The runtimes themselves are rebuilt by INodeOwner::reloadScriptsUsing(), which the engine calls on every owner

◆ loadNode() [1/2]

void toast::World::loadNode ( std::string_view uri)
static

Begins asynchronous loading of a prefab into the cache.

Parameters
uriVirtual URI of the prefab, e.g. "assets://levels/lobby.node"
activate_as_rootIf true, automatically calls setRoot() once the node finishes loading
Note
Resolves the URI to a UID via the manifest, then delegates to loadNode(UID)

◆ loadNode() [2/2]

void toast::World::loadNode ( UID uid)
static

Begins asynchronous loading of a prefab into the cache.

Parameters
uidUID of the prefab asset to load
Here is the caller graph for this function:

◆ name()

auto toast::World::name ( ) -> std::string
inlineoverridevirtual

Implements toast::INodeOwner.

◆ participatesIn()

auto toast::World::participatesIn ( NodeOwnerParticipation use) const -> bool
inlinenodiscardoverridevirtualnoexcept

Determines if this owner is elegible for runtime systems.

Implements toast::INodeOwner.

◆ registerDependency()

void toast::World::registerDependency ( Node & from,
Node & to )
overridevirtual

Records a tick ordering constraint between two active nodes.

Parameters
fromNode that must be ticked before to
toNode that must be ticked after from
Note
Triggers a full rebuild of the dependency graph at the start of the next tick

Implements toast::INodeOwner.

◆ registerInteraction()

void toast::World::registerInteraction ( Node & first,
Node & second )
overridevirtual

Reimplemented from toast::INodeOwner.

◆ searchFrom()

auto toast::World::searchFrom ( const Node & origin,
std::string_view query ) -> std::vector< Box< Node > >
overridevirtual

Implements toast::INodeOwner.

◆ setRoot()

auto toast::World::setRoot ( Node & node) -> Box< Node >
static

Promotes a cached or global node to be the active world root.

Calls end() on the old root and begin() on the new one so there is never a frame with two simultaneous active roots.

Parameters
nodeMust be in the cached or global state with NodeType::root
Returns
The previous world root, now cached, or an empty box if the world was empty
Warning
Passing an already-rooted node is a no-op; a warning is logged

◆ tick()

void toast::World::tick ( )
overridevirtual

Implements toast::INodeOwner.

◆ unregisterDependency()

void toast::World::unregisterDependency ( Node & from,
Node & to )
overridevirtual

Implements toast::INodeOwner.


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