13#include "node_owner.hpp"
24#include <toast/assets/prefab.hpp>
25#include <toast/events/listener.hpp>
27#include <toast/reflect/reflect.hpp>
29#include <unordered_map>
30#include <unordered_set>
38class World final :
public INodeOwner {
43 auto name() -> std::string
override {
return "World"; }
48 auto participatesIn(NodeOwnerParticipation )
const noexcept ->
bool override {
59 void unregisterDependency(
Node& from,
Node& to)
override;
60 void registerInteraction(
Node& first,
Node& second)
override;
74 static void loadNode(std::string_view uri);
76 auto findFrom(
const Node& origin, std::string_view query) ->
Box<Node> override;
78 auto searchFrom(
const Node& origin, std::string_view query) -> std::vector<Box<Node>>
override;
123 static auto graphviz() -> std::string;
137 auto dependencyGraphGraphviz() const -> std::
string;
140 inline static
World* instance =
nullptr;
143 void computeDependencyGraph();
144 void applyActiveCamera() override;
159 void detachFromParent(
Node& node);
162 void drainLoadQueue();
165 void drainDestroyQueue();
168 void drainSpawnQueue();
171 static
void spawn(
UID prefab,
Node& parent);
175 static auto findNode(const
UID& uid,
Node* scope =
nullptr) ->
Box<
Node>;
179 static auto findNode(std::string_view path) ->
Box<
Node>;
183 static auto uidPath(const
Node& node) -> std::
string;
187 static auto findScoped(
Node& scope, std::string_view seg) ->
Box<
Node>;
190 static
void searchScoped(
Node& scope, std::string_view seg, std::vector<
Box<
Node>>& out);
194 std::mutex load_mutex;
195 std::vector<std::future<void>> load_futures;
196 std::vector<std::pair<Box<Node>,
Box<Node>>> spawn_queue;
201 std::vector<Box<Node>> global;
202 std::vector<Box<Node>> cached;
203 std::vector<Box<Node>> load_queue;
204 std::vector<Box<Node>> destroy_queue;
207 using DependencyGraph = TickScheduler::DependencyGraph;
208 TickScheduler m_scheduler;
211 friend struct toast::_detail::WorldTestAccess;
pseudo shared pointer for Nodes
manages the lifetime, subscription, and unsubscription of callbacks
Definition listener.hpp:39
Intrusive reference-counted handle to a Node.
Definition box.hpp:35
static auto setRoot(Node &node) -> Box< Node >
Promotes a cached or global node to be the active world root.
Definition world.cpp:611
auto participatesIn(NodeOwnerParticipation) const noexcept -> bool override
Determines if this owner is elegible for runtime systems.
Definition world.hpp:48
void registerDependency(Node &from, Node &to) override
Records a tick ordering constraint between two active nodes.
Definition world.cpp:123
static auto graphviz() -> std::string
Serializes the current tick schedule as a Graphviz DOT string.
Definition world.cpp:668
static auto cacheNode(Node &node) -> Box< Node >
Moves an active node back to the cached state, disabling it and calling its end() lifecycle.
Definition world.cpp:615
static void loadNode(UID uid)
Begins asynchronous loading of a prefab into the cache.
Definition world.cpp:135
static auto findCached(std::string_view name) -> Box< Node >
Linear search for a cached root node by display name.
Definition world.cpp:619
static void hotReloadScripts(toast::UID script_uid)
Recomputes the tick schedule after the script runtimes using the given script asset were rebuilt.
Definition world.cpp:658
static void destroyNode(Node &node)
Schedules a cached node for destruction at the start of the next tick.
Definition world.cpp:672
static void hotReload()
Refreshes the NodeInfo pointers on every live node after a game library hot reload.
Definition world.cpp:633
Control block for the pseudo shared pointer Box<Node>.
Public logging interface for the engine.
Base object type for the scene graph.
Dependency-graph tick scheduling shared by World and PlayWorkspace.
Events that allow client code to interact with the World class.