From 313bd7377f9db9f226993de3e72602ab135b4a0d Mon Sep 17 00:00:00 2001 From: Xein Date: Sun, 29 Nov 2026 19:55:49 +0100 Subject: [PATCH 1/3] renderer.pass command --- engine/src/toast/console/console.cpp | 5 + engine/src/toast/console/console.hpp | 2 + engine/src/toast/console/model.cpp | 148 ++++++++++++++++++-- engine/src/toast/console/model.hpp | 10 ++ engine/src/toast/engine.cpp | 11 ++ engine/src/toast/renderer/render_events.cpp | 22 ++- engine/src/toast/renderer/render_events.hpp | 6 + 7 files changed, 188 insertions(+), 16 deletions(-) diff --git a/engine/src/toast/console/console.cpp b/engine/src/toast/console/console.cpp index a623b4b3f..1d3b23f11 100644 --- a/engine/src/toast/console/console.cpp +++ b/engine/src/toast/console/console.cpp @@ -113,6 +113,11 @@ void Console::setNodeRoot(std::function()> root) { m_model.setNodeRoot(std::move(root)); } +void Console::setPassControl(PassControl control) { + const std::lock_guard lock(m_mutex); + m_model.setPassControl(std::move(control)); +} + void Console::setAssetCheck(std::function check) { const std::lock_guard lock(m_mutex); m_model.setAssetCheck(std::move(check)); diff --git a/engine/src/toast/console/console.hpp b/engine/src/toast/console/console.hpp index 012051787..f9073e352 100644 --- a/engine/src/toast/console/console.hpp +++ b/engine/src/toast/console/console.hpp @@ -71,6 +71,8 @@ class TOAST_API Console { void setNodeRoot(std::function()> root); + void setPassControl(PassControl control); + private: void handleKey(int key, int mods); void execute(); diff --git a/engine/src/toast/console/model.cpp b/engine/src/toast/console/model.cpp index f24d0e6cc..ed7b05718 100644 --- a/engine/src/toast/console/model.cpp +++ b/engine/src/toast/console/model.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -19,6 +20,12 @@ using namespace toast::params; constexpr std::string_view k_whitespace = " \t"; +auto lowered(std::string_view text) -> std::string { + std::string out {text}; + std::ranges::transform(out, out.begin(), [](unsigned char c) { return static_cast(std::tolower(c)); }); + return out; +} + auto trim(std::string_view text) -> std::string_view { const size_t first = text.find_first_not_of(k_whitespace); if (first == std::string_view::npos) { @@ -108,7 +115,58 @@ auto valueNames(const ParamBase& param) -> std::vector { return names; } -auto completeSet(std::string_view line, size_t cursor) -> Completion { +constexpr std::string_view k_pass_scope = "renderer.pass"; + +struct PassEntry { + std::string slug; + bool enabled = true; +}; + +auto slugOf(std::string_view name) -> std::string { + std::string out; + for (const unsigned char c : name) { + if (std::isalnum(c) != 0) { + out += static_cast(std::tolower(c)); + } else if (!out.empty() && out.back() != '_') { + out += '_'; + } + } + while (!out.empty() && out.back() == '_') { + out.pop_back(); + } + return out; +} + +auto passEntries(const PassControl& control) -> std::vector { + std::vector out; + if (!control.list) { + return out; + } + for (const auto& [name, enabled] : control.list()) { + std::string slug = slugOf(name); + if (slug.empty()) { + continue; + } + const auto same = std::ranges::find_if(out, [&](const PassEntry& entry) { return entry.slug == slug; }); + if (same != out.end()) { + same->enabled = same->enabled || enabled; + } else { + out.push_back({std::move(slug), enabled}); + } + } + return out; +} + +auto passSlugOf(std::string_view path) -> std::optional { + for (const std::string_view prefix : {"renderer.pass.", "render.pass."}) { + if (path.size() >= prefix.size() && lowered(path.substr(0, prefix.size())) == prefix) { + return lowered(path.substr(prefix.size())); + } + } + return std::nullopt; +} + +auto completeSet(std::string_view line, size_t cursor, const std::vector& passes) -> Completion { cursor = std::min(cursor, line.size()); Completion completion; @@ -119,11 +177,22 @@ auto completeSet(std::string_view line, size_t cursor) -> Completion { } if (cursor > word_end) { - const ParamBase* param = Registry::get().find(line.substr(word_begin, word_end - word_begin)); - if (param == nullptr) { + const std::string_view path = line.substr(word_begin, word_end - word_begin); + const ParamBase* param = Registry::get().find(path); + std::vector names; + if (param != nullptr) { + completion.hint = currentText(*param); + names = valueNames(*param); + } else if (const auto slug = passSlugOf(path)) { + const auto pass = std::ranges::find_if(passes, [&](const PassEntry& entry) { return entry.slug == *slug; }); + if (pass == passes.end()) { + return completion; + } + completion.hint = pass->enabled ? "true" : "false"; + names = {"true", "false"}; + } else { return completion; } - completion.hint = currentText(*param); const size_t argument_begin = std::min(line.find_first_not_of(k_whitespace, word_end), line.size()); const size_t partial_end = std::max(cursor, argument_begin); const std::string_view partial = line.substr(argument_begin, partial_end - argument_begin); @@ -131,7 +200,7 @@ auto completeSet(std::string_view line, size_t cursor) -> Completion { completion.replace_end = partial_end; std::vector scored; - for (const auto& name : valueNames(*param)) { + for (const auto& name : names) { if (const auto score = fuzzyScore(partial, name)) { scored.push_back({ {name, name, {}, EntryKind::value}, @@ -170,6 +239,20 @@ auto completeSet(std::string_view line, size_t cursor) -> Completion { return completion; } + if (lowered(scope) == k_pass_scope) { + std::vector entries; + for (const PassEntry& pass : passes) { + if (const auto score = fuzzyScore(partial, pass.slug)) { + entries.push_back({ + {pass.slug, pass.slug, pass.enabled ? "true" : "false", EntryKind::variable}, + *score + }); + } + } + append(completion.entries, entries); + return completion; + } + const size_t group_dot = scope.find('.'); const GroupBase* group = Registry::get().findGroup(scope.substr(0, group_dot)); if (group == nullptr) { @@ -205,6 +288,14 @@ auto completeSet(std::string_view line, size_t cursor) -> Completion { } } } + if (lowered(scope) == "renderer" && !passes.empty()) { + if (const auto score = fuzzyScore(partial, "pass"); score && seen.insert("pass").second) { + subgroups.push_back({ + {"pass", "pass.", {}, EntryKind::subgroup}, + *score + }); + } + } append(completion.entries, variables); append(completion.entries, subgroups); return completion; @@ -248,7 +339,7 @@ auto Model::complete(std::string_view line, size_t cursor) const -> Completion { return completeHide(line, cursor, first_end); } if (command == "set") { - completion = completeSet(line.substr(first_end), cursor - first_end); + completion = completeSet(line.substr(first_end), cursor - first_end, passEntries(m_passes)); completion.replace_begin += first_end; completion.replace_end += first_end; } @@ -293,6 +384,10 @@ auto Model::execute(std::string_view raw) -> Result { const std::string_view path = arguments.substr(0, path_end); const std::string_view value_text = path_end == std::string_view::npos ? std::string_view {} : trim(arguments.substr(path_end)); + if (passSlugOf(path)) { + return executePass(path, value_text); + } + ParamBase* param = registry.find(path); if (param == nullptr && path.starts_with("render.")) { // `render.view_mode` for `renderer.view_mode` @@ -360,14 +455,45 @@ auto Model::execute(std::string_view raw) -> Result { return {true, std::format("{} = {}", path, shown)}; } -namespace { +auto Model::executePass(std::string_view path, std::string_view value_text) -> Result { + const std::string slug = *passSlugOf(path); + const std::vector passes = passEntries(m_passes); + const auto pass = std::ranges::find_if(passes, [&](const PassEntry& entry) { return entry.slug == slug; }); + if (pass == passes.end()) { + if (passes.empty()) { + return {false, "no render passes yet; the renderer is not running"}; + } + std::string names; + for (const PassEntry& entry : passes) { + names += names.empty() ? "" : ", "; + names += entry.slug; + } + return {false, std::format("no render pass '{}'; there are {}", slug, names)}; + } -auto lowered(std::string_view text) -> std::string { - std::string out {text}; - std::ranges::transform(out, out.begin(), [](unsigned char c) { return static_cast(std::tolower(c)); }); - return out; + const std::string canonical = "renderer.pass." + slug; + if (value_text.empty()) { + return {true, std::format("{} = {}", canonical, pass->enabled)}; + } + + const std::string word = lowered(value_text); + bool enabled = false; + if (word == "true" || word == "on" || word == "1") { + enabled = true; + } else if (word != "false" && word != "off" && word != "0") { + return {false, std::format("{}: '{}' is not true or false", canonical, value_text)}; + } + + for (const auto& [name, was_enabled] : m_passes.list()) { + if (slugOf(name) == slug) { + m_passes.set(name, enabled); + } + } + return {true, std::format("{} = {}", canonical, enabled)}; } +void Model::setPassControl(PassControl control) { + m_passes = std::move(control); } auto Model::describe(const Pin& pin) const -> std::pair { diff --git a/engine/src/toast/console/model.hpp b/engine/src/toast/console/model.hpp index 8159d3cb0..4754495a2 100644 --- a/engine/src/toast/console/model.hpp +++ b/engine/src/toast/console/model.hpp @@ -52,6 +52,11 @@ struct Result { std::string message; }; +struct PassControl { + std::function>()> list; + std::function set; +}; + class TOAST_API Model { public: [[nodiscard]] @@ -68,7 +73,11 @@ class TOAST_API Model { void setAssetCheck(std::function check); + void setPassControl(PassControl control); + private: + auto executePass(std::string_view path, std::string_view value_text) -> Result; + struct Pin { std::string spec; bool parameter = false; @@ -83,6 +92,7 @@ class TOAST_API Model { std::function m_asset_check; std::function()> m_node_root; + PassControl m_passes; std::vector m_pins; }; diff --git a/engine/src/toast/engine.cpp b/engine/src/toast/engine.cpp index 6fd085674..84ad8d58c 100644 --- a/engine/src/toast/engine.cpp +++ b/engine/src/toast/engine.cpp @@ -337,6 +337,17 @@ void Engine::init() { console::Console::get().setAssetCheck([](std::string_view uri) { return !assets::AssetManager::isInitialized() || assets::AssetManager::resolveURI(uri).has_value(); }); + console::Console::get().setPassControl({ + .list = + [] { + std::vector> passes; + for (const auto& pass : renderer::listRenderPasses()) { + passes.emplace_back(pass.name, pass.enabled); + } + return passes; + }, + .set = [](std::string_view name, bool enabled) { renderer::setRenderPassEnabled(name, enabled); }, + }); console::Console::get().setNodeRoot([this]() -> Box { { std::scoped_lock lock(m->owners_mutex); diff --git a/engine/src/toast/renderer/render_events.cpp b/engine/src/toast/renderer/render_events.cpp index 44e89c6b4..fcea1f59a 100644 --- a/engine/src/toast/renderer/render_events.cpp +++ b/engine/src/toast/renderer/render_events.cpp @@ -138,14 +138,29 @@ void sendPassList() { if (VulkanRenderer::instance == nullptr) { return; } + event::send(listRenderPasses()); +} + +} +auto listRenderPasses() -> std::vector { std::vector passes; + if (VulkanRenderer::instance == nullptr) { + return passes; + } for (const auto& pass : VulkanRenderer::instance->listPasses()) { passes.push_back(event::RenderPassList::PassInfo {.name = pass.name, .enabled = pass.enabled}); } - event::send(std::move(passes)); + return passes; } +auto setRenderPassEnabled(std::string_view name, bool enabled) -> bool { + if (VulkanRenderer::instance == nullptr) { + return false; + } + VulkanRenderer::instance->setPassEnabled(name, enabled); + sendPassList(); + return true; } void registerRenderEvents() { @@ -163,10 +178,7 @@ void registerRenderEvents() { }); listener.subscribe([](const event::SetRenderPassEnabled& e) { - if (VulkanRenderer::instance != nullptr) { - VulkanRenderer::instance->setPassEnabled(e.name, e.enabled); - sendPassList(); - } + setRenderPassEnabled(e.name, e.enabled); return false; }); diff --git a/engine/src/toast/renderer/render_events.hpp b/engine/src/toast/renderer/render_events.hpp index d80b5d2a7..cf753d924 100644 --- a/engine/src/toast/renderer/render_events.hpp +++ b/engine/src/toast/renderer/render_events.hpp @@ -6,7 +6,9 @@ #pragma once #include +#include #include +#include #include namespace event { @@ -62,4 +64,8 @@ namespace renderer { void registerRenderEvents(); +TOAST_API auto listRenderPasses() -> std::vector; + +TOAST_API auto setRenderPassEnabled(std::string_view name, bool enabled) -> bool; + } From 6c8b473f4e6866de364190f78c95af143ccd401f Mon Sep 17 00:00:00 2001 From: Xein Date: Mon, 30 Nov 2026 19:21:39 +0100 Subject: [PATCH 2/3] Restart --- engine/src/toast/console/console.cpp | 5 +++++ engine/src/toast/console/console.hpp | 2 ++ engine/src/toast/console/model.cpp | 17 ++++++++++++++--- engine/src/toast/console/model.hpp | 3 +++ engine/src/toast/engine.cpp | 23 +++++++++++++++++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/engine/src/toast/console/console.cpp b/engine/src/toast/console/console.cpp index 1d3b23f11..6123922fa 100644 --- a/engine/src/toast/console/console.cpp +++ b/engine/src/toast/console/console.cpp @@ -118,6 +118,11 @@ void Console::setPassControl(PassControl control) { m_model.setPassControl(std::move(control)); } +void Console::setRestart(std::function restart) { + const std::lock_guard lock(m_mutex); + m_model.setRestart(std::move(restart)); +} + void Console::setAssetCheck(std::function check) { const std::lock_guard lock(m_mutex); m_model.setAssetCheck(std::move(check)); diff --git a/engine/src/toast/console/console.hpp b/engine/src/toast/console/console.hpp index f9073e352..d25641307 100644 --- a/engine/src/toast/console/console.hpp +++ b/engine/src/toast/console/console.hpp @@ -73,6 +73,8 @@ class TOAST_API Console { void setPassControl(PassControl control); + void setRestart(std::function restart); + private: void handleKey(int key, int mods); void execute(); diff --git a/engine/src/toast/console/model.cpp b/engine/src/toast/console/model.cpp index ed7b05718..5f80842cc 100644 --- a/engine/src/toast/console/model.cpp +++ b/engine/src/toast/console/model.cpp @@ -319,10 +319,11 @@ auto Model::complete(std::string_view line, size_t cursor) const -> Completion { completion.replace_begin = first; completion.replace_end = first_end; std::vector commands; - for (const std::string_view name : {"set", "node", "show", "hide", "restore"}) { + for (const std::string_view name : {"set", "node", "show", "hide", "restore", "reload"}) { if (const auto score = fuzzyScore(typed, name)) { + const bool bare = name == "restore" || name == "reload"; commands.push_back({ - {std::string {name}, name == "restore" ? std::string {name} : std::string {name} + " ", {}, EntryKind::command}, + {std::string {name}, bare ? std::string {name} : std::string {name} + " ", {}, EntryKind::command}, *score }); } @@ -361,6 +362,12 @@ auto Model::execute(std::string_view raw) -> Result { registry.requestRestore(); return {true, "restoring everything from disk"}; } + if (command == "reload" && arguments.empty()) { + if (!m_restart) { + return {false, "reload is not available yet"}; + } + return m_restart(); + } if (command == "node") { return executeNode(m_node_root, arguments); } @@ -374,7 +381,7 @@ auto Model::execute(std::string_view raw) -> Result { if (registry.find(command) != nullptr) { return {false, std::format("did you mean 'set {}'?", line)}; } - return {false, std::format("no command '{}'; there are set, node, show, hide and restore", command)}; + return {false, std::format("no command '{}'; there are set, node, show, hide, restore and reload", command)}; } if (arguments.empty()) { return {false, "usage: set [value]"}; @@ -496,6 +503,10 @@ void Model::setPassControl(PassControl control) { m_passes = std::move(control); } +void Model::setRestart(std::function restart) { + m_restart = std::move(restart); +} + auto Model::describe(const Pin& pin) const -> std::pair { if (pin.parameter) { const ParamBase* param = Registry::get().find(pin.spec); diff --git a/engine/src/toast/console/model.hpp b/engine/src/toast/console/model.hpp index 4754495a2..526bf8cd3 100644 --- a/engine/src/toast/console/model.hpp +++ b/engine/src/toast/console/model.hpp @@ -75,6 +75,8 @@ class TOAST_API Model { void setPassControl(PassControl control); + void setRestart(std::function restart); + private: auto executePass(std::string_view path, std::string_view value_text) -> Result; @@ -93,6 +95,7 @@ class TOAST_API Model { std::function m_asset_check; std::function()> m_node_root; PassControl m_passes; + std::function m_restart; std::vector m_pins; }; diff --git a/engine/src/toast/engine.cpp b/engine/src/toast/engine.cpp index 84ad8d58c..0e79bbd32 100644 --- a/engine/src/toast/engine.cpp +++ b/engine/src/toast/engine.cpp @@ -348,6 +348,29 @@ void Engine::init() { }, .set = [](std::string_view name, bool enabled) { renderer::setRenderPassEnabled(name, enabled); }, }); + console::Console::get().setRestart([this]() -> console::Result { + { + std::scoped_lock lock(m->owners_mutex); + if (const auto it = m->owners.find(m->active_workspace); it != m->owners.end()) { + if (Workspace* workspace = it->second->asWorkspace(); workspace != nullptr && workspace->isValid()) { + return {false, "reload not available on Editor"}; + } + } + } + const Box root = World::root(); + if (!root.exists()) { + return {false, "there is no root node to restart"}; + } + const UID prefab = root->sourcePrefab().uid(); + if (prefab.data() == 0) { + return {false, std::format("'{}' was not loaded from a prefab, so it cannot be reloaded", root->name())}; + } + const std::string name {root->name()}; // the box dies with the node + World::cacheNode(*root); + World::destroyNode(*root); + World::loadNode(prefab); + return {true, std::format("reloading '{}'", name)}; + }); console::Console::get().setNodeRoot([this]() -> Box { { std::scoped_lock lock(m->owners_mutex); From 134629b857ae488456fc2c969a0fc46aeb760945 Mon Sep 17 00:00:00 2001 From: Xein Date: Tue, 1 Dec 2026 08:29:59 +0100 Subject: [PATCH 3/3] woops --- engine/src/toast/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/toast/engine.cpp b/engine/src/toast/engine.cpp index 0e79bbd32..a3e090fe0 100644 --- a/engine/src/toast/engine.cpp +++ b/engine/src/toast/engine.cpp @@ -357,7 +357,7 @@ void Engine::init() { } } } - const Box root = World::root(); + Box root = World::root(); if (!root.exists()) { return {false, "there is no root node to restart"}; }