Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
T-rvw committed Nov 6, 2023
1 parent d0d34ad commit ed4482f
Show file tree
Hide file tree
Showing 15 changed files with 346 additions and 247 deletions.
50 changes: 13 additions & 37 deletions Engine/Source/Editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "Application/Engine.h"
#include "Display/CameraController.h"
#include "ECWorld/SceneWorld.h"
#include "ImGui/EditorImGuiViewport.h"
#include "ImGui/ImGuiContextInstance.h"
#include "ImGui/Localization.h"
#include "ImGui/UILayers/DebugPanel.h"
Expand Down Expand Up @@ -48,6 +47,7 @@
#include "UILayers/TestNodeEditor.h"
#include "Window/Input.h"
#include "Window/Window.h"
#include "Window/WindowManager.h"

#include <imgui/imgui.h>
#define IMGUI_DEFINE_MATH_OPERATORS
Expand Down Expand Up @@ -80,6 +80,8 @@ void EditorApp::Init(engine::EngineInitArgs initArgs)
CD_ERROR("Failed to open CSV file");
}

m_pWindowManager = std::make_unique<engine::WindowManager>();

// Phase 1 - Splash
// * Compile uber shader permutations automatically when initialization or detect changes
// * Show compile progresses so it still needs to update ui
Expand All @@ -94,7 +96,7 @@ void EditorApp::Init(engine::EngineInitArgs initArgs)

pSplashWindow->OnResize.Bind<engine::RenderContext, &engine::RenderContext::OnResize>(m_pRenderContext.get());
m_pMainWindow = pSplashWindow.get();
AddWindow(cd::MoveTemp(pSplashWindow));
m_pWindowManager->AddWindow(cd::MoveTemp(pSplashWindow));

InitEditorRenderers();
EditorRenderersWarmup();
Expand Down Expand Up @@ -124,23 +126,6 @@ void EditorApp::Shutdown()
{
}

engine::Window* EditorApp::GetWindow(void* handle) const
{
auto itWindow = m_mapWindows.find(handle);
return itWindow != m_mapWindows.end() ? itWindow->second.get() : nullptr;
}

void EditorApp::AddWindow(std::unique_ptr<engine::Window> pWindow)
{
m_mapWindows[pWindow->GetHandle()] = cd::MoveTemp(pWindow);
}

void EditorApp::RemoveWindow(void* handle)
{
assert(handle != m_pMainWindow->GetHandle());
m_mapWindows.erase(handle);
}

void EditorApp::InitEditorImGuiContext(engine::Language language)
{
assert(GetMainWindow() && "Init window before imgui context");
Expand All @@ -163,12 +148,12 @@ void EditorApp::InitEditorImGuiContext(engine::Language language)
// Init viewport settings.
if (enableViewport)
{
m_pEditorImGuiViewport = std::make_unique<EditorImGuiViewport>(this, m_pRenderContext.get());
m_pEditorImGuiContext->InitViewport(m_pWindowManager.get(), m_pRenderContext.get());
ImGuiViewport* pMainViewport = ImGui::GetMainViewport();
assert(pMainViewport);
pMainViewport->PlatformHandle = GetMainWindow();
pMainViewport->PlatformHandleRaw = GetMainWindow()->GetHandle();
m_pEditorImGuiViewport->Update();
m_pEditorImGuiContext->UpdateViewport();
}
}

Expand Down Expand Up @@ -601,22 +586,7 @@ bool EditorApp::Update(float deltaTime)
InitEngineUILayers();
}

for (auto& [_, pWindow] : m_mapWindows)
{
pWindow->Update();
if (pWindow->IsFocused())
{
m_pFocusedWindow = pWindow.get();
}
}

if (m_pEditorImGuiContext->IsViewportEnable())
{
m_pEditorImGuiViewport->Update();
auto position = engine::Input::Get().GetGloalMousePosition();
engine::Input::Get().SetMousePositionX(position.first);
engine::Input::Get().SetMousePositionY(position.second);
}
m_pWindowManager->Update();
m_pEditorImGuiContext->Update(deltaTime);
m_pSceneWorld->Update();

Expand All @@ -637,6 +607,12 @@ bool EditorApp::Update(float deltaTime)
}
}

if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}

if (m_pEngineImGuiContext)
{
GetMainWindow()->SetMouseVisible(m_pSceneView->IsShowMouse(), m_pSceneView->GetMouseFixedPositionX(), m_pSceneView->GetMouseFixedPositionY());
Expand Down
25 changes: 10 additions & 15 deletions Engine/Source/Editor/EditorApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
namespace engine
{

class AABBRenderer;
class CameraController;
class FlybyCamera;
class ImGuiBaseLayer;
class ImGuiContextInstance;
class Window;
class WindowManager;
class RenderContext;
class Renderer;
class AABBRenderer;
class RenderTarget;
class SceneWorld;
class ShaderCollections;
Expand All @@ -28,7 +29,6 @@ struct ImGuiContext;
namespace editor
{

class EditorImGuiViewport;
class FileWatcher;
class SceneView;

Expand All @@ -46,10 +46,8 @@ class EditorApp final : public engine::IApplication
virtual bool Update(float deltaTime) override;
virtual void Shutdown() override;

engine::Window* GetWindow(void* handle) const;
engine::Window* GetMainWindow() const { return m_pMainWindow; }
void AddWindow(std::unique_ptr<engine::Window> pWindow);
void RemoveWindow(void* handle);
engine::WindowManager* GetWindowManager() const { return m_pWindowManager.get(); }

void InitRenderContext(engine::GraphicsBackend backend, void* hwnd = nullptr);

Expand Down Expand Up @@ -90,16 +88,20 @@ class EditorApp final : public engine::IApplication

// Windows
engine::Window* m_pMainWindow = nullptr;
engine::Window* m_pFocusedWindow = nullptr;
std::map<void*, std::unique_ptr<engine::Window>> m_mapWindows;
std::unique_ptr<engine::WindowManager> m_pWindowManager;

// ImGui
std::unique_ptr<engine::ImGuiContextInstance> m_pEditorImGuiContext;
std::unique_ptr<engine::ImGuiContextInstance> m_pEngineImGuiContext;
std::unique_ptr<EditorImGuiViewport> m_pEditorImGuiViewport;

// Scene
std::unique_ptr<engine::SceneWorld> m_pSceneWorld;

// Rendering
std::unique_ptr<engine::RenderContext> m_pRenderContext;
std::unique_ptr<engine::ShaderCollections> m_pShaderCollections;
std::vector<std::unique_ptr<engine::Renderer>> m_pEditorRenderers;
std::vector<std::unique_ptr<engine::Renderer>> m_pEngineRenderers;
editor::SceneView* m_pSceneView = nullptr;
engine::Renderer* m_pSceneRenderer = nullptr;
engine::Renderer* m_pWhiteModelRenderer = nullptr;
Expand All @@ -109,13 +111,6 @@ class EditorApp final : public engine::IApplication
engine::Renderer* m_pTerrainRenderer = nullptr;
engine::Renderer* m_pAABBRenderer = nullptr;

// Rendering
std::unique_ptr<engine::RenderContext> m_pRenderContext;
std::unique_ptr<engine::ShaderCollections> m_pShaderCollections;

std::vector<std::unique_ptr<engine::Renderer>> m_pEditorRenderers;
std::vector<std::unique_ptr<engine::Renderer>> m_pEngineRenderers;

// Controllers for processing input events.
std::unique_ptr<engine::CameraController> m_pViewportCameraController;

Expand Down
97 changes: 0 additions & 97 deletions Engine/Source/Editor/ImGui/EditorImGuiViewport.cpp

This file was deleted.

33 changes: 0 additions & 33 deletions Engine/Source/Editor/ImGui/EditorImGuiViewport.h

This file was deleted.

2 changes: 0 additions & 2 deletions Engine/Source/Runtime/Application/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Engine::~Engine()
void Engine::Init(EngineInitArgs args)
{
CD_ENGINE_INFO("Init engine");
Window::Init();

m_pApplication->Init(args);
}
Expand All @@ -54,7 +53,6 @@ void Engine::Run()

void Engine::Shutdown()
{
Window::Shutdown();
}

//
Expand Down
Loading

0 comments on commit ed4482f

Please sign in to comment.