Toast Engine
Loading...
Searching...
No Matches
play_workspace.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include "tick_scheduler.hpp"
12#include "workspace.hpp"
13
14#include <atomic>
15
16namespace toast {
25class PlayWorkspace : public Workspace {
26public:
27 PlayWorkspace(UID handle, assets::Prefab& prefab);
28
29 ~PlayWorkspace() override;
30
31 auto name() -> std::string override;
32
33 void registerDependency(Node& from, Node& to) override;
34 void unregisterDependency(Node& from, Node& to) override;
35 void registerInteraction(Node& first, Node& second) override;
36
37 void tick() override;
38
39 [[nodiscard]]
40 auto participatesIn(NodeOwnerParticipation use) const noexcept -> bool override;
41
42 [[nodiscard]]
43 auto receivesEvents() const noexcept -> bool override {
44 // The play workspace is the one running so it always receives events
45 return true;
46 }
47
48 [[nodiscard]]
49 auto paused() const noexcept -> bool {
50 return m_paused.load(std::memory_order_acquire);
51 }
52
53 [[nodiscard]]
54 static auto exists() noexcept -> bool {
55 // True while any PlayWorkspace exists
56 return s_instances.load(std::memory_order_acquire) > 0;
57 }
58
59protected:
61 [[nodiscard]]
62 auto isPlaying() const -> bool override {
63 return true;
64 }
65
66private:
67 static inline std::atomic<int> s_instances = 0;
68
69 TickScheduler m_scheduler;
70 std::atomic<bool> m_paused = false;
71 bool m_started = false;
72 std::atomic<bool> m_schedule_dirty = true; // scripts register dependencies from init(), possibly on a loader thread
73 void computeSchedule();
74};
75}
Definition prefab.hpp:54
Definition node.hpp:81
auto receivesEvents() const noexcept -> bool override
Definition play_workspace.hpp:43
auto isPlaying() const -> bool override
Playmode state.
Definition play_workspace.hpp:62
auto participatesIn(NodeOwnerParticipation use) const noexcept -> bool override
Determines if this owner is elegible for runtime systems.
Definition play_workspace.cpp:129
Definition tick_scheduler.hpp:74
void tick() override
Editor-only per-frame work: camera preview, animation preview, editorTick lifecycle,...
Definition workspace.cpp:2601
Workspace(std::string_view type, UID handle)
Creates a new workspace rooted at a single fresh node of the given type.
Definition workspace.cpp:352
Definition uid.hpp:20
Dependency-graph tick scheduling shared by World and PlayWorkspace.