Editor toolbar gains Play/Stop (Ctrl+P) with UE semantics: - Play: serialize current scene to an in-memory YAML snapshot via new SceneSerializer::SerializeToString, switch display to kDisplayDirect (primary camera entity renders), unfreeze time (timeScale 0 -> 1) - Stop: DeserializeFromString atomically rebuilds the pre-play scene, back to kDisplayViewport (editor camera), refreeze time; selection cleared and gizmo drag reset since all entity handles dangle - SceneSerializer refactored: SerializeDoc/ParseRoot shared by file and memory variants; file Save/Load behavior unchanged - Running state disables gizmo + editor hotkeys in the viewport (input goes to game scripts), draws yellow PLAYING hint and a no-camera warning; File->Save/Load disabled while playing (UE behavior) Physics bodies/constraints/characters and script instances are reconciled automatically by the existing per-frame sync on restore.
54 lines
2.0 KiB
C++
54 lines
2.0 KiB
C++
//
|
||
// EditorContext:Editor 层与 SandboxApp 之间的桥接上下文。
|
||
//
|
||
// Editor 是 App 层代码(不属于引擎),它需要的引擎门面与沙盒能力
|
||
// 全部经此聚合注入——面板只认识 EditorContext,不反向依赖 main.cpp。
|
||
//
|
||
|
||
#ifndef HELLOVULKAN_EDITORCONTEXT_H
|
||
#define HELLOVULKAN_EDITORCONTEXT_H
|
||
|
||
#include <Engine/Core/Application.h>
|
||
#include <Engine/ECS/Scene.h>
|
||
#include <Engine/Assets/AssetManager.h>
|
||
#include <Engine/Renderer/Renderer.h>
|
||
#include <Engine/Renderer/EditorCamera.h>
|
||
#include <Engine/Renderer/SceneTypes.h> // kDisplayViewport / kDisplayDirect
|
||
|
||
#include <functional>
|
||
|
||
// 可切换环境(IBL 动态切换):StatsPanel 的 Combo 与 SandboxApp 的
|
||
// 加载逻辑共用这一张表(下标即身份)。
|
||
inline constexpr const char *kEnvPaths[] = {
|
||
"assets/textures/venice_dawn_1_4k.hdr",
|
||
"assets/textures/rooitou_park_4k.hdr",
|
||
"assets/textures/pink_sunrise_4k.hdr",
|
||
"assets/textures/birchwood_4k.hdr",
|
||
};
|
||
inline constexpr const char *kEnvNames[] = {
|
||
"Venice Dawn", "Rooitou Park", "Pink Sunrise", "Birchwood",
|
||
};
|
||
inline constexpr int kEnvCount = 4;
|
||
inline constexpr int kDefaultEnv = 0;
|
||
|
||
// 沙盒特有状态(面板可选读取,空指针 = 该面板区块不显示)
|
||
struct EditorContext {
|
||
// 引擎门面
|
||
Engine::Renderer *renderer = nullptr;
|
||
Engine::ECS::Scene *scene = nullptr;
|
||
Engine::Assets::AssetManager *assets = nullptr;
|
||
Engine::Application *app = nullptr;
|
||
// 编辑器相机(Scene view 专用,归 Renderer 持有——与场景相机实体
|
||
// 无关;面板经此做 F 焦点/Gizmo 视图/对齐跳转)
|
||
Engine::EditorCamera *editorCamera = nullptr;
|
||
|
||
// PIE 运行态(Play-In-Editor):Editor 持有,只读指针。
|
||
// 面板门控用——运行态禁 Gizmo/编辑器热键,渲染源已是 primary 相机
|
||
const bool *playState = nullptr;
|
||
|
||
std::function<int()> getEnvIndex; // 当前环境表下标
|
||
std::function<void(int)> setEnvIndex;
|
||
};
|
||
|
||
#endif //HELLOVULKAN_EDITORCONTEXT_H
|