feat: add play / editor mode

This commit is contained in:
2026-10-22 01:25:53 +02:00
parent 3df0f89343
commit e5d37965a1
13 changed files with 304 additions and 22 deletions
+23 -1
View File
@@ -2,8 +2,12 @@
#define APP_H
#include <filesystem>
#include <chrono>
#include <memory>
#include <optional>
#include <string>
#include <nlohmann/json.hpp>
#include "glm/vec2.hpp"
#include <SDL2/SDL.h>
@@ -17,6 +21,8 @@
#include <destrum/Input/InputManager.h>
class Scene;
class App {
public:
struct AppParams {
@@ -28,6 +34,7 @@ public:
bool showDebugUi{true};
WindowMode windowMode{WindowMode::Windowed};
bool startMaximized{false};
bool startInEditMode{false};
};
App();
@@ -45,7 +52,11 @@ public:
virtual void onWindowResize(int, int) {};
// Called inside the "Windows" menu of the main menu bar, add toggles for the game's own windows here
virtual void onPlayModeChanged(bool) {}
[[nodiscard]] bool isPlaying() const { return playing; }
void requestPlayModeToggle() { playModeToggleRequested = true; }
virtual void customWindowsMenu() {}
protected:
@@ -92,6 +103,17 @@ protected:
void drawWindowsMenu();
void drawPhysicsPanel(float dt, float fixedDt, float accumulator);
private:
void drawPlayControls();
void applyPlayModeToggle();
bool enterPlayMode();
void exitPlayMode();
bool playing{true};
bool playModeToggleRequested{false};
std::optional<nlohmann::json> editSnapshot;
std::weak_ptr<Scene> editScene;
};
@@ -18,6 +18,9 @@ public:
Scene& GetCurrentScene() const;
const std::vector<std::shared_ptr<Scene>>& GetActiveScenes() const { return m_activeScenes; }
void SetPlaying(bool playing) { m_playing = playing; }
[[nodiscard]] bool IsPlaying() const { return m_playing; }
void Update(float dt);
void FixedUpdate(float dt);
void LateUpdate(float dt);
@@ -52,6 +55,7 @@ private:
std::vector<std::shared_ptr<Scene>> m_activeScenes;
std::vector<std::shared_ptr<Scene>> m_scenes;
bool m_playing{true};
};
#endif //SCENEMANAGER_H
@@ -18,10 +18,8 @@ namespace MaterialSerialization {
[[nodiscard]] std::optional<std::string> Validate(const nlohmann::json& materials);
// Materials that only exist at runtime (no source file) are stored in the scene or prefab
// file under their cache key, so the materialKeys in its objects resolve after a restart
[[nodiscard]] nlohmann::json CollectEmbedded(const nlohmann::json& objects);
void RegisterEmbedded(const nlohmann::json& materials);
void RegisterEmbedded(const nlohmann::json& materials, bool overwriteExisting = false);
}
#endif //DESTRUM_MATERIALSERIALIZATION_H
@@ -4,6 +4,7 @@
#include <filesystem>
#include <functional>
#include <future>
#include <optional>
#include <nlohmann/json.hpp>
@@ -17,8 +18,11 @@ public:
nlohmann::json root;
};
[[nodiscard]] static std::optional<nlohmann::json> Capture(Scene& scene);
static bool Save(Scene& scene, const std::filesystem::path& path);
static bool LoadFromJson(Scene& scene, const nlohmann::json& root);
static bool Load(Scene& scene, const std::filesystem::path& path,
std::function<void(float)> progressCallback = nullptr);
@@ -27,8 +31,6 @@ public:
static bool ConstructScene(Scene& scene, LoadResult& result,
std::function<void(float)> progressCallback = nullptr);
// Parse the scene file on a background thread. Call LoadFromJson on the
// main thread once the future is ready.
static std::future<LoadResult> LoadSceneFileAsync(const std::filesystem::path& path);
};