From 4da61fdd465bcf6f1bec9e1de74a0a406b84994f Mon Sep 17 00:00:00 2001 From: roby2014 Date: Sat, 14 Oct 2023 12:49:54 +0100 Subject: [PATCH] feat(tools): add toggleable debug camera --- .../engine/tools/debug_camera/plugin.cpp | 49 +++++++++++++++++-- tools/tesseratos/src/main.cpp | 3 ++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/engine/src/cubos/engine/tools/debug_camera/plugin.cpp b/engine/src/cubos/engine/tools/debug_camera/plugin.cpp index 2f53f0516d..73a9c99d60 100644 --- a/engine/src/cubos/engine/tools/debug_camera/plugin.cpp +++ b/engine/src/cubos/engine/tools/debug_camera/plugin.cpp @@ -1,22 +1,63 @@ #include +#include +#include +#include +#include #include +#include +using cubos::core::ecs::Commands; +using cubos::core::ecs::Entity; +using cubos::core::ecs::Read; using cubos::core::ecs::Write; using namespace cubos::engine; -static void inspector(Write settings) +struct DebugCameraInfo +{ + Entity copy[4]; // copy old camera entities to re-apply them in the next camera change + Entity ent; // debug camera entity +}; + +static void createDebugCameraSystem(Commands commands, Write debugCamera) +{ + debugCamera->ent = commands.create().add(Camera{}).add(Position{{}}).entity(); +} + +static void changeToDebugCameraSystem(Write camera, Write debugCamera) { ImGui::Begin("Debug Camera"); - printf("debug camera"); + ImGui::Text("Current camera: %s", debugCamera->ent == camera->entities[0] ? "Debug" : "Game"); + ImGui::Text("Key to change: F12"); + + if (ImGui::Button("Change camera") || ImGui::IsKeyPressed(ImGuiKey_F12)) + { + CUBOS_DEBUG("Changed camera ..."); + if (debugCamera->ent == camera->entities[0]) + { + std::copy(std::begin(debugCamera->copy), std::end(debugCamera->copy), camera->entities); + } + else + { + std::copy(std::begin(camera->entities), std::end(camera->entities), debugCamera->copy); + camera->entities[0] = debugCamera->ent; + camera->entities[1] = Entity(); + camera->entities[2] = Entity(); + camera->entities[3] = Entity(); + } + } ImGui::End(); } void cubos::engine::tools::debugCameraPlugin(Cubos& cubos) { - // cubos.addPlugin(imguiPlugin); - cubos.system(inspector).tagged("cubos.imgui"); + cubos.addPlugin(imguiPlugin); + + cubos.startupSystem(createDebugCameraSystem); + cubos.system(changeToDebugCameraSystem).tagged("cubos.imgui"); + + cubos.addResource(); } diff --git a/tools/tesseratos/src/main.cpp b/tools/tesseratos/src/main.cpp index b1fd95c70f..c84b49a796 100644 --- a/tools/tesseratos/src/main.cpp +++ b/tools/tesseratos/src/main.cpp @@ -1,12 +1,14 @@ #include #include #include +#include #include #include #include #include #include + using cubos::core::ecs::Commands; using cubos::core::ecs::Write; @@ -35,6 +37,7 @@ int main(int argc, char** argv) cubos.addPlugin(tools::entityInspectorPlugin); cubos.addPlugin(tools::worldInspectorPlugin); cubos.addPlugin(tools::assetExplorerPlugin); + cubos.addPlugin(tools::debugCameraPlugin); cubos.startupSystem(mockCamera).tagged("setup"); cubos.startupSystem(mockSettings).tagged("setup");