Files
XCEngine/editor/src/Application.h

93 lines
2.8 KiB
C++

#pragma once
#include "Platform/D3D12WindowRenderer.h"
#include "Scripting/EditorScriptRuntimeStatus.h"
#include "UI/ImGuiBackendBridge.h"
#include "UI/ImGuiSession.h"
#include "Viewport/ViewportHostService.h"
#include <XCEngine/Rendering/RenderContext.h>
#include <chrono>
#include <memory>
#include <string>
#include <windows.h>
#include <XCEngine/Core/LayerStack.h>
namespace XCEngine {
namespace RHI {
class RHIDevice;
class RHISwapChain;
} // namespace RHI
namespace Scripting {
#ifdef XCENGINE_ENABLE_MONO_SCRIPTING
class MonoScriptRuntime;
#endif
} // namespace Scripting
namespace Editor {
class EditorLayer;
class IEditorContext;
class Application {
public:
static Application& Get();
bool Initialize(HWND hwnd);
void Shutdown();
void Render();
void OnResize(int width, int height);
bool SwitchProject(const std::string& projectPath);
bool ReloadScriptingRuntime();
bool RebuildScriptingAssemblies();
void SaveProjectState();
Rendering::RenderContext GetMainRenderContext() const { return m_windowRenderer.GetRenderContext(); }
RHI::RHIDevice* GetMainRHIDevice() const { return m_windowRenderer.GetRHIDevice(); }
RHI::RHISwapChain* GetMainSwapChain() const { return m_windowRenderer.GetSwapChain(); }
IViewportHostService& GetViewportHostService() { return m_viewportHostService; }
bool IsRenderReady() const { return m_renderReady; }
HWND GetWindowHandle() const { return m_hwnd; }
IEditorContext& GetEditorContext() const { return *m_editorContext; }
const EditorScriptRuntimeStatus& GetScriptRuntimeStatus() const { return m_scriptRuntimeStatus; }
private:
Application() = default;
~Application() = default;
bool InitializeWindowRenderer(HWND hwnd);
void InitializeEditorContext(const std::string& projectPath);
void InitializeImGui(HWND hwnd);
void AttachEditorLayer();
void DetachEditorLayer();
void ShutdownEditorContext();
void InitializeScriptingRuntime(const std::string& projectPath);
void ShutdownScriptingRuntime();
void RenderEditorFrame();
void UpdateWindowTitle();
HWND m_hwnd = nullptr;
Core::LayerStack m_layerStack;
EditorLayer* m_editorLayer = nullptr;
std::shared_ptr<IEditorContext> m_editorContext;
Platform::D3D12WindowRenderer m_windowRenderer;
UI::ImGuiBackendBridge m_imguiBackend;
UI::ImGuiSession m_imguiSession;
ViewportHostService m_viewportHostService;
uint64_t m_exitRequestedHandlerId = 0;
std::wstring m_lastWindowTitle;
std::chrono::steady_clock::time_point m_lastFrameTime{};
bool m_hasLastFrameTime = false;
bool m_renderReady = false;
bool m_resourceManagerInitialized = false;
EditorScriptRuntimeStatus m_scriptRuntimeStatus;
#ifdef XCENGINE_ENABLE_MONO_SCRIPTING
std::unique_ptr<::XCEngine::Scripting::MonoScriptRuntime> m_scriptRuntime;
#endif
};
}
}