Toast Engine
Loading...
Searching...
No Matches
world_test_access.hpp
1#pragma once
2
3#include "world.hpp"
4
5#include <any>
6#include <memory>
7#include <string_view>
9#include <toast/export.hpp>
11
12namespace toast::_detail {
13
14struct TOAST_API WorldTestAccess {
15 struct TOAST_API WorldDeleter {
16 void operator()(World* world) const noexcept;
17 };
18
19 using WorldPtr = std::unique_ptr<World, WorldDeleter>;
20
21 static auto createWorld() -> WorldPtr;
22
23 static auto createNode(World& world, std::string_view name, NodeState state = NodeState::root) -> Box<Node>;
24
25 static auto createTypedNode(World& world, std::string_view type, std::string_view name) -> Box<Node>;
26 static void callTick(Node& node, TickFunctionList stage);
27
28 // activeRenderCamera() is protected on INodeOwner
29 static auto activeRenderCamera(World& world) -> Camera*;
30 static auto hasActiveCamera(World& world) -> bool;
31
32 static void registerDependency(Node& from, Node& to);
33
34 // Test-only: make `node` participate in the given tick stage by attaching a fabricated
35 // NodeInfo (the per-instance NodeFunctionTable no longer exists).
36 static void addTickStage(Node& node, TickFunctionList stage);
37
38 // Test-only: like addTickStage(), but the fabricated NodeInfo also calls `callback` for onEnable
39 static void setEnableCallback(Node& node, void (*callback)(void*));
40
41 // Test-only: like addTickStage(tick), but the fabricated NodeInfo also calls `callback` as the C++ tick of the node
42 static void setTickCallback(Node& node, void (*callback)(void*));
43
44 // Test-only: the fabricated NodeInfo of the node calls `callback` as its C++ function for `stage` (init, begin or onEnable)
45 static void setStageCallback(Node& node, TickFunctionList stage, void (*callback)(void*));
46
47 // Test-only: TickScheduler::runLifecycle() of the world's scheduler
48 static void runLifecycle(World& world, Node& root, TickFunctionList stage);
49
50 // Test-only: the node counts as enabled, without the callbacks that enabling it would run
51 static void markEnabled(Node& node);
52
53 // Test-only: Node::propagateCallTick(), one node after the other on the calling thread
54 static void propagateCallTick(Node& node, TickFunctionList stage);
55
56 // Test-only: appends a script asset to the node and (re)builds its ScriptRuntime;
57 // requires a LuaState to exist
58 static void attachScript(Node& node, const assets::Handle<assets::Script>& script);
59
61 static void attachScriptInGroup(Node& node, const assets::Handle<assets::Script>& script, uint64_t group);
62
63 static void applyLuaOverrides(
64 World& world, Node& node, const assets::Prefab::BasicNode& data, const scripting::NodeResolver& find_node
65 );
66
67 static auto tickSchedule(World& world) noexcept -> _detail::TickSchedule&;
68
70 static auto scheduler(World& world) noexcept -> TickScheduler&;
71
73 static void runTickFrame(World& world);
74
75 static auto dependencyGraph(World& world) noexcept -> World::DependencyGraph&;
76
77 static void computeDependencyGraph(World& world);
78
79 static auto instantiate(World& world, const assets::Handle<assets::Prefab>& file, INodeOwner::InstantiateContext& ctx)
80 -> Box<Node>;
81
82 static auto childrenOf(const Node& node) -> const std::vector<Box<Node>>&;
83 static auto changeField(Node& node, std::string_view name, const std::any& value) -> bool;
84 static auto setScriptVar(Node& node, std::string_view path, const std::any& value) -> bool;
85 static void attachChild(Node& parent, Node& child);
86 static auto isPrefabInterior(const Node& node) -> bool;
87
88 static void initThreadPool();
89
90 static void setWorldRoot(World& world, Node& node);
91
93 static auto moveToChild(World& world, Node& node, Node& parent) -> Box<Node>;
94
95 // Moves a freshly instantiated tree to the cache, then World::swapRoot() it so begin/onEnable run
96 static auto activateLoadedRoot(World& world, Node& node) -> Box<Node>;
97
98 static auto
99 spawnSync(World& world, const assets::Handle<assets::Prefab>& file, Node& parent, INodeOwner::InstantiateContext& ctx)
100 -> Box<Node>;
101
102 static void initAssetManager(std::string_view assets_dir, std::string_view cache_dir);
103
104 static void waitForLoads(World& world);
105
106 static void drainLoadQueue(World& world);
107
108 static auto dependencyGraphGraphviz(const World& world) -> std::string;
109
110 static void loadNode(toast::UID uid);
111 static auto findCached(std::string_view name) -> Box<Node>;
112 static auto findNode(const UID& uid, Node* scope = nullptr) -> Box<Node>;
113 static auto findNode(std::string_view path) -> Box<Node>;
114 static auto uidPath(const Node& node) -> std::string;
115};
116
117}
Type-safe smart pointer for assets.
Definition core_types.hpp:149
Intrusive reference-counted handle to a Node.
Definition box.hpp:35
Definition camera.hpp:25
Definition node.hpp:81
Definition tick_scheduler.hpp:74
Definition world.hpp:38
Converts exported Lua script variable values to/from the engine's text encoding.
std::function< toast::Box< toast::Node >(std::string_view)> NodeResolver
Resolves a node UID to a node reference.
Definition lua_value_codec.hpp:24
Member-robber pattern used by the generated reflection code.
Definition defer.hpp:16
NodeState
Definition node.hpp:53
@ root
The node is currently in use within world::root_node.
Definition node.hpp:55
TickFunctionList
Bit-flag set describing which lifecycle phases a Node type implements.
Definition reflect_node.hpp:36
Lua source asset attached to nodes through Node::m_scripts.
One node entry in a prefab file.
Definition prefab.hpp:232
Definition node_owner.hpp:97
Definition uid.hpp:20
Definition tick_scheduler.hpp:51
Definition world_test_access.hpp:15
Definition world_test_access.hpp:14
static auto scheduler(World &world) noexcept -> TickScheduler &
Test-only: the world's scheduler, so tests can run tick phases without the physics step.
Definition world.cpp:1298
static void runTickFrame(World &world)
Test-only: one frame of the scheduled phases (early tick, tick, post physics, late tick).
Definition world.cpp:1302
static void attachScriptInGroup(Node &node, const assets::Handle< assets::Script > &script, uint64_t group)
Like attachScript(), with the runtime placed together with the other nodes of the script group.
Definition world.cpp:1283
static auto moveToChild(World &world, Node &node, Node &parent) -> Box< Node >
Test-only: World::moveToChild(), which the engine reaches through events.
Definition world.cpp:1362