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 ecb5af7
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 200 deletions.
44 changes: 7 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 Down
10 changes: 3 additions & 7 deletions Engine/Source/Editor/EditorApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class FlybyCamera;
class ImGuiBaseLayer;
class ImGuiContextInstance;
class Window;
class WindowManager;
class RenderContext;
class Renderer;
class AABBRenderer;
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,13 +88,11 @@ 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;
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 ecb5af7

Please sign in to comment.