feat: add scene loading imgui testing things
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
|
||||
~Rigidbody() override;
|
||||
|
||||
void Update(float dt) override {}
|
||||
void Update(float) override {}
|
||||
void Start() override;
|
||||
void Destroy() override;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef LIGHTKEEPER_H
|
||||
#define LIGHTKEEPER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <destrum/App.h>
|
||||
#include <destrum/Scene/SceneManager.h>
|
||||
#include <destrum/Graphics/RenderResources.h>
|
||||
@@ -28,6 +30,10 @@ private:
|
||||
std::unique_ptr<CubeMap> skyboxCubemap;
|
||||
|
||||
GameObject* capybara = nullptr;
|
||||
|
||||
char scenePath[512]{"game://scenes/debug_scene.json"};
|
||||
char newSceneName[128]{"EmptyScene"};
|
||||
std::string sceneStatus;
|
||||
};
|
||||
|
||||
#endif //LIGHTKEEPER_H
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <destrum/Components/Physics/Rigidbody.h>
|
||||
#include <destrum/Components/Physics/BoxCollider.h>
|
||||
#include <destrum/Scene/Scene.h>
|
||||
#include <destrum/Serialization/SceneSerializer.h>
|
||||
|
||||
#include "destrum/Components/MeshRendererComponent.h"
|
||||
#include "destrum/Components/Rotator.h"
|
||||
@@ -17,12 +18,27 @@
|
||||
|
||||
|
||||
#include <filesystem>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#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()
|
||||
|
||||
@@ -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"; }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user