Toast Engine
Loading...
Searching...
No Matches
toast::Workspace Class Reference

Single-viewport node owner used by the editor. More...

#include <workspace.hpp>

Inheritance diagram for toast::Workspace:
Collaboration diagram for toast::Workspace:

Classes

struct  SizeHandlePoint
struct  EmptyTag
 disambiguates the protected ctor from Workspace(UID) More...
struct  SnapSetting
struct  VoxelToolState
struct  GizmoRenderState

Public Member Functions

 Workspace (std::string_view type, UID handle)
 Creates a new workspace rooted at a single fresh node of the given type.
 Workspace (UID uid)
 Opens an existing workspace by loading the prefab at the given UID.
 Workspace (UID uid, std::string_view source_uri)
 Opens a workspace bound to the given asset UID but loading its content from another file.
auto name () -> std::string override
auto asWorkspace () -> Workspace *override
 Downcast helper for owners that need Workspace-specific state.
void registerDependency (Node &from, Node &to) override
 No-op; Workspace has no tick scheduler and never registers dependencies.
void unregisterDependency (Node &from, Node &to) override
void nodeEnabledChanged (Node &node) noexcept override
auto participatesIn (NodeOwnerParticipation use) const noexcept -> bool override
 Determines if this owner is elegible for runtime systems.
auto receivesEvents () const noexcept -> bool override
auto findFrom (const Node &origin, std::string_view query) -> Box< Node > override
 Name lookup over origin's subtree.
auto findFrom (const Node &origin, const UID &uid) -> Box< Node > override
 UID lookup over origin's subtree.
auto searchFrom (const Node &origin, std::string_view query) -> std::vector< Box< Node > > override
 Same query grammar as World::searchFrom(); searches only within m_root_node.
virtual auto isPlaying () const -> bool
 True for PlayWorkspace, gates gizmo interaction off so it can never run against a live game.
auto usesGameCamera () const noexcept -> bool
void inheritEditorCamera (const Workspace &source)
void preparePrefabReload (UID uid)
void finishPrefabReload ()
void tick () override
 Editor-only per-frame work: camera preview, animation preview, editorTick lifecycle, inspector streaming.
auto rootNode () const -> const Node &
auto isValid () const -> bool
auto findPrefabInstance (UID prefab, UID instance) -> Box< Node >
auto gizmoRenderState () const -> GizmoRenderState
 snapshot of the active gizmo's transform/highlight state, resolved on the main thread for Engine::tick() to hand to VulkanRenderer
Public Member Functions inherited from toast::INodeOwner
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 registerInteraction (Node &, Node &)
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 Attributes

static constexpr size_t k_max_size_handles = 6

Protected Member Functions

auto owningPrefabUid () const -> UID override
 Workspace (UID handle, EmptyTag)
 Sets only the handle and subscribes to editor events; used by PlayWorkspace.
void sendEnabledChanges ()
auto isActiveWorkspace () const noexcept -> bool
auto gizmoOrigin () const -> glm::vec3
auto gizmoOrientation () const -> glm::quat
auto gizmoScale () const -> float
auto gizmoInteractionAllowed () const -> bool
auto collectSizeHandles () const -> std::pair< std::array< SizeHandlePoint, k_max_size_handles >, uint32_t >
void gizmoApplySizeDrag (float delta)
void gizmoUpdateHover ()
void gizmoBeginDrag (GizmoHandle handle)
void gizmoUpdateDrag ()
void gizmoEndDrag ()
void eventSubscriptions ()
void initializeHistory (bool available, bool initially_saved)
auto restoreHistorySnapshot (const assets::Prefab &snapshot) -> bool
void destroyOwnedTree (Box< Node > &root)
auto duplicateNode (Box< Node > src, Box< Node > par, bool after_source) -> Box< Node >
void subscribeVoxelEditing ()
void voxelUpdatePreview (uint8_t kind)
void voxelReparent (Box< Node > node, Box< Node > parent, size_t index)
auto voxelWrapInGroup (Box< Node > node, std::string_view name) -> Box< Node >
auto voxelToolShape () -> ProceduralVoxel *
void voxelToolMouseMove ()
auto voxelToolMouseButton (uint32_t button, bool pressed, int mods) -> bool
void voxelToolCancel ()
auto pickNodeUnderMouse () -> Box< Node >
auto retypeNode (Box< Node > &target, std::string_view type, bool keep_fields) -> Box< Node >
void promoteNode (Box< Node > &target, std::string_view path)
template<typename F>
void recordHistory (WorkspaceHistory::Context context, F &&mutation)
void initFromPrefab (const assets::Handle< assets::Prefab > &file)
 instantiates the prefab and sets up the root node
void applyActiveCamera () override
Protected Member Functions inherited from toast::INodeOwner
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

Protected Attributes

UID m_handle
std::unique_ptr< assets::Prefab > m_owned_source_prefab
Box< Node > m_root_node
Box< Node > m_focused_node
event::Listener m_listener
GizmoTool m_gizmo_tool = GizmoTool::select
bool m_world_space = false
 false = local coordinates
SnapSetting m_translate_snap {true, 0.10f}
SnapSetting m_rotate_snap {true, 30.0f}
SnapSetting m_scale_snap {true, 0.10f}
bool m_game_camera = false
 false = editor camera
std::unique_ptr< Camera > m_editor_camera
EditorCameraController m_editor_camera_controller
 drives m_editor_camera; ticked from tick() below
std::unique_ptr< WorkspaceHistory > m_history
std::mutex m_enabled_changes_mutex
std::vector< Box< Node > > m_enabled_changes
glm::vec2 m_gizmo_mouse_pos {0.0f, 0.0f}
 The gizmo's current state.
GizmoHandle m_gizmo_hover = GizmoHandle::none
GizmoHandle m_gizmo_drag = GizmoHandle::none
glm::vec3 m_gizmo_drag_start_world_pos {0.0f}
glm::quat m_gizmo_drag_start_rotation {1.0f, 0.0f, 0.0f, 0.0f}
glm::vec3 m_gizmo_drag_start_scale {1.0f}
glm::vec3 m_gizmo_drag_anchor {0.0f}
 closest-point-on-axis or ray-plane hit at drag start
glm::vec3 m_gizmo_drag_axis {0.0f}
 world-space axis direction, for axis/ring drags
glm::vec3 m_gizmo_drag_plane_normal {0.0f}
 world-space plane normal, for plane/center/ring drags
float m_gizmo_drag_start_angle = 0.0f
 radians, for rotate drags
float m_gizmo_drag_current_factor = 1.0f
 live scale factor, for the scale feedback stretch
glm::vec3 m_gizmo_drag_start_size {0.0f}
glm::vec3 m_gizmo_drag_start_local_pos {0.0f}
glm::quat m_gizmo_drag_start_local_rot {1.0f, 0.0f, 0.0f, 0.0f}
std::optional< std::string > m_gizmo_history_start
 dragged field's value at drag start, set while the drag owns the open history transaction
VoxelToolState m_voxel_tool
Box< Node > m_voxel_preview
std::optional< glm::vec2 > m_pick_press
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

Additional Inherited Members

Static Public Member Functions inherited from toast::INodeOwner
static void reapOrphanedControlBoxes () noexcept
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.

Detailed Description

Single-viewport node owner used by the editor.

A lightweight alternative to World: owns a node tree through the INodeOwner interface but never ticks nodes, never builds a dependency graph, and never runs lifecycle functions beyond those triggered by instantiation. Use it to display or edit a node tree without running any game logic

See also
World, INodeOwner

Constructor & Destructor Documentation

◆ Workspace() [1/3]

toast::Workspace::Workspace ( std::string_view type,
UID handle )

Creates a new workspace rooted at a single fresh node of the given type.

Parameters
typeFully-qualified C++ class name for the root node, e.g. "toast::Node3D"
handleUID the editor assigned to this workspace; stored for round-trip serialization
Here is the caller graph for this function:

◆ Workspace() [2/3]

toast::Workspace::Workspace ( UID uid)

Opens an existing workspace by loading the prefab at the given UID.

Parameters
uidAsset UID of a previously saved workspace prefab

◆ Workspace() [3/3]

toast::Workspace::Workspace ( UID uid,
std::string_view source_uri )

Opens a workspace bound to the given asset UID but loading its content from another file.

Parameters
uidAsset UID of the workspace prefab; used as the workspace handle
source_uriVirtual path to read the prefab bytes from

Used to recover autosaves

Member Function Documentation

◆ applyActiveCamera()

void toast::Workspace::applyActiveCamera ( )
overrideprotectedvirtual

Implements toast::INodeOwner.

◆ asWorkspace()

auto toast::Workspace::asWorkspace ( ) -> Workspace *
inlineoverridevirtual

Downcast helper for owners that need Workspace-specific state.

Reimplemented from toast::INodeOwner.

◆ findFrom() [1/2]

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

UID lookup over origin's subtree.

Implements toast::INodeOwner.

◆ findFrom() [2/2]

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

Name lookup over origin's subtree.

Implements toast::INodeOwner.

Here is the caller graph for this function:

◆ gizmoRenderState()

auto toast::Workspace::gizmoRenderState ( ) const -> GizmoRenderState
nodiscard

snapshot of the active gizmo's transform/highlight state, resolved on the main thread for Engine::tick() to hand to VulkanRenderer

Note
See docs/renderer.md RenderFrame pattern

◆ isPlaying()

virtual auto toast::Workspace::isPlaying ( ) const -> bool
inlinenodiscardvirtual

True for PlayWorkspace, gates gizmo interaction off so it can never run against a live game.

Reimplemented in toast::PlayWorkspace.

Here is the caller graph for this function:

◆ name()

auto toast::Workspace::name ( ) -> std::string
overridevirtual

Implements toast::INodeOwner.

◆ nodeEnabledChanged()

void toast::Workspace::nodeEnabledChanged ( Node & node)
overridevirtualnoexcept

Reimplemented from toast::INodeOwner.

◆ owningPrefabUid()

auto toast::Workspace::owningPrefabUid ( ) const -> UID
inlinenodiscardoverrideprotectedvirtual

Reimplemented from toast::INodeOwner.

◆ participatesIn()

auto toast::Workspace::participatesIn ( NodeOwnerParticipation use) const -> bool
nodiscardoverridevirtualnoexcept

Determines if this owner is elegible for runtime systems.

Implements toast::INodeOwner.

Here is the caller graph for this function:

◆ receivesEvents()

auto toast::Workspace::receivesEvents ( ) const -> bool
nodiscardoverridevirtualnoexcept
Returns
false when silenced

Reimplemented from toast::INodeOwner.

◆ registerDependency()

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

No-op; Workspace has no tick scheduler and never registers dependencies.

Implements toast::INodeOwner.

◆ searchFrom()

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

Same query grammar as World::searchFrom(); searches only within m_root_node.

Implements toast::INodeOwner.

◆ subscribeVoxelEditing()

void toast::Workspace::subscribeVoxelEditing ( )
protected

Listens to the VoxelEditor commands, lives in workspace_voxel.cpp

◆ tick()

void toast::Workspace::tick ( )
overridevirtual

Editor-only per-frame work: camera preview, animation preview, editorTick lifecycle, inspector streaming.

Not the gameplay tick scheduler - only what the viewport needs to stay live. See PlayWorkspace::tick()

Implements toast::INodeOwner.

◆ unregisterDependency()

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

Implements toast::INodeOwner.


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