From f298c7ada5b0127321cf16d9748149cc1a94c71d Mon Sep 17 00:00:00 2001 From: Bram Verhulst Date: Sun, 9 Aug 2026 02:53:17 +0200 Subject: [PATCH] feat: add scene loading imgui testing things --- .../destrum/Components/Physics/BoxCollider.h | 2 +- .../Components/Physics/CapsuleCollider.h | 2 +- .../destrum/Components/Physics/Rigidbody.h | 2 +- .../Components/Physics/SphereCollider.h | 2 +- lightkeeper/include/Lightkeeper.h | 6 ++ lightkeeper/src/Lightkeeper.cpp | 76 +++++++++++++++++++ tests/destrum_tests.cpp | 2 +- 7 files changed, 87 insertions(+), 5 deletions(-) diff --git a/destrum/include/destrum/Components/Physics/BoxCollider.h b/destrum/include/destrum/Components/Physics/BoxCollider.h index 4945cf4..79f9e8f 100644 --- a/destrum/include/destrum/Components/Physics/BoxCollider.h +++ b/destrum/include/destrum/Components/Physics/BoxCollider.h @@ -9,7 +9,7 @@ public: : Collider(owner) , m_HalfExtents(glm::max(halfExtents, glm::vec3{0.0001f})) {} - void Update(float dt) override {} + void Update(float) override {} nlohmann::json Serialize() const override; void Deserialize(const nlohmann::json& data) override; diff --git a/destrum/include/destrum/Components/Physics/CapsuleCollider.h b/destrum/include/destrum/Components/Physics/CapsuleCollider.h index c502cb5..15b2879 100644 --- a/destrum/include/destrum/Components/Physics/CapsuleCollider.h +++ b/destrum/include/destrum/Components/Physics/CapsuleCollider.h @@ -11,7 +11,7 @@ public: , m_Radius(std::max(radius, 0.0f)) , m_Height(std::max(height, std::max(radius, 0.0f) * 2.0f)) {} - void Update(float dt) override {} + void Update(float) override {} std::string GetTypeName() const override { return "CapsuleCollider"; diff --git a/destrum/include/destrum/Components/Physics/Rigidbody.h b/destrum/include/destrum/Components/Physics/Rigidbody.h index 9d61565..45752ff 100644 --- a/destrum/include/destrum/Components/Physics/Rigidbody.h +++ b/destrum/include/destrum/Components/Physics/Rigidbody.h @@ -15,7 +15,7 @@ public: ~Rigidbody() override; - void Update(float dt) override {} + void Update(float) override {} void Start() override; void Destroy() override; diff --git a/destrum/include/destrum/Components/Physics/SphereCollider.h b/destrum/include/destrum/Components/Physics/SphereCollider.h index 467b2c2..a550f43 100644 --- a/destrum/include/destrum/Components/Physics/SphereCollider.h +++ b/destrum/include/destrum/Components/Physics/SphereCollider.h @@ -10,7 +10,7 @@ public: : Collider(owner) , m_Radius(std::max(radius, 0.0001f)) {} - void Update(float dt) override {} + void Update(float) override {} nlohmann::json Serialize() const override; void Deserialize(const nlohmann::json& data) override; diff --git a/lightkeeper/include/Lightkeeper.h b/lightkeeper/include/Lightkeeper.h index 84bdcfa..c29faec 100644 --- a/lightkeeper/include/Lightkeeper.h +++ b/lightkeeper/include/Lightkeeper.h @@ -1,6 +1,8 @@ #ifndef LIGHTKEEPER_H #define LIGHTKEEPER_H +#include + #include #include #include @@ -28,6 +30,10 @@ private: std::unique_ptr skyboxCubemap; GameObject* capybara = nullptr; + + char scenePath[512]{"game://scenes/debug_scene.json"}; + char newSceneName[128]{"EmptyScene"}; + std::string sceneStatus; }; #endif //LIGHTKEEPER_H diff --git a/lightkeeper/src/Lightkeeper.cpp b/lightkeeper/src/Lightkeeper.cpp index 6932074..80a1de8 100644 --- a/lightkeeper/src/Lightkeeper.cpp +++ b/lightkeeper/src/Lightkeeper.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "destrum/Components/MeshRendererComponent.h" #include "destrum/Components/Rotator.h" @@ -17,12 +18,27 @@ #include +#include #include +#include #include "imgui.h" #include "destrum/Components/Physics/SphereCollider.h" #include "destrum/Util/ModelDocUtils.h" +namespace { + std::filesystem::path ResolveScenePath(std::string_view value) { + if (value.empty()) { + throw std::invalid_argument("Scene path cannot be empty"); + } + + if (value.find("://") != std::string_view::npos) { + return AssetFS::GetInstance().GetFullPath(value); + } + + return std::filesystem::path{value}; + } +} LightKeeper::LightKeeper() : App() { @@ -478,6 +494,66 @@ void LightKeeper::customUpdate(float dt) SceneManager::GetInstance().GetCurrentScene().GetPhysics().RefreshGameObject(*sphere); } ImGui::End(); + + ImGui::Begin("Scene Debug"); + ImGui::InputText("Scene path", scenePath, sizeof(scenePath)); + ImGui::InputText("New scene name", newSceneName, sizeof(newSceneName)); + + if (ImGui::Button("Save Current Scene")) { + try { + const auto path = ResolveScenePath(scenePath); + const auto parent = path.parent_path(); + if (!parent.empty()) { + std::filesystem::create_directories(parent); + } + + if (SceneSerializer::Save( + SceneManager::GetInstance().GetCurrentScene(), + path)) { + sceneStatus = "Saved scene to " + path.string(); + } else { + sceneStatus = "Failed to save scene to " + path.string(); + } + } catch (const std::exception& exception) { + sceneStatus = std::string{"Save failed: "} + exception.what(); + } + } + + ImGui::SameLine(); + if (ImGui::Button("Load Scene")) { + try { + const auto path = ResolveScenePath(scenePath); + if (SceneSerializer::Load( + SceneManager::GetInstance().GetCurrentScene(), + path)) { + sceneStatus = "Loaded scene from " + path.string(); + } else { + sceneStatus = "Failed to load scene from " + path.string(); + } + } catch (const std::exception& exception) { + sceneStatus = std::string{"Load failed: "} + exception.what(); + } + } + + if (ImGui::Button("New Empty Scene")) { + try { + const std::string name = newSceneName[0] != '\0' + ? newSceneName + : "EmptyScene"; + auto& sceneManager = SceneManager::GetInstance(); + const int newSceneIndex = sceneManager.GetSceneCount(); + sceneManager.CreateScene(name); + sceneManager.SwitchScene(newSceneIndex); + sceneStatus = "Created and switched to scene '" + name + "'"; + } catch (const std::exception& exception) { + sceneStatus = std::string{"New scene failed: "} + exception.what(); + } + } + + if (!sceneStatus.empty()) { + ImGui::TextWrapped("%s", sceneStatus.c_str()); + } + ImGui::End(); } void LightKeeper::customDraw() diff --git a/tests/destrum_tests.cpp b/tests/destrum_tests.cpp index 0a59ff8..b3949d7 100644 --- a/tests/destrum_tests.cpp +++ b/tests/destrum_tests.cpp @@ -24,7 +24,7 @@ namespace { public: explicit TestComponent(GameObject& owner) : Component(owner, "TestComponent") {} - void Update() override {} + void Update(float) override {} std::string GetTypeName() const override { return "TestComponent"; } };