From 7ec9690f5261e10f42b446fd896ac852d6d6c3d0 Mon Sep 17 00:00:00 2001 From: Light Date: Sat, 14 Aug 2021 16:17:33 +0430 Subject: [PATCH] Maintenance - Mirror project maintenance and tidying - General maintenance --- Engine/src/Engine/Camera/SceneCamera.cpp | 2 +- Engine/src/Engine/Core/Application.cpp | 2 - Engine/src/Engine/Math/TempExtensions.cpp | 41 ++++ Engine/src/Engine/Math/TempExtensions.h | 20 ++ .../Engine/Scene/Components/TagComponent.h | 2 +- Engine/src/Engine/Scene/Scene.cpp | 3 +- .../Engine/UserInterface/UserInterface.cpp | 135 ++++++++++--- .../src/Engine/UserInterface/UserInterface.h | 12 +- Engine/src/LightEngine.h | 3 + .../GraphicsAPI/OpenGL/glGraphicsContext.cpp | 1 + Mirror/imgui_log.txt | 9 + Mirror/src/EditorLayer.cpp | 98 +++++++++ Mirror/src/EditorLayer.h | 43 ++++ Mirror/src/MirrorApp.cpp | 11 +- Mirror/src/MirrorLayer.h | 189 ------------------ 15 files changed, 342 insertions(+), 229 deletions(-) create mode 100644 Engine/src/Engine/Math/TempExtensions.cpp create mode 100644 Engine/src/Engine/Math/TempExtensions.h create mode 100644 Mirror/imgui_log.txt create mode 100644 Mirror/src/EditorLayer.cpp create mode 100644 Mirror/src/EditorLayer.h delete mode 100644 Mirror/src/MirrorLayer.h diff --git a/Engine/src/Engine/Camera/SceneCamera.cpp b/Engine/src/Engine/Camera/SceneCamera.cpp index d7f26f7..5a963e7 100644 --- a/Engine/src/Engine/Camera/SceneCamera.cpp +++ b/Engine/src/Engine/Camera/SceneCamera.cpp @@ -6,7 +6,7 @@ namespace Light { SceneCamera::SceneCamera() - : m_OrthographicSpecification{ 10.0f, -1.0f, 10000.0f }, + : m_OrthographicSpecification{ 1000.0f, -1.0f, 10000.0f }, m_PerspectiveSpecification{ glm::radians(45.0f), 0.01f, 10000.0f }, m_AspectRatio(16.0f / 9.0f), m_ProjectionType(ProjectionType::Orthographic) diff --git a/Engine/src/Engine/Core/Application.cpp b/Engine/src/Engine/Core/Application.cpp index c4fd314..227be8f 100644 --- a/Engine/src/Engine/Core/Application.cpp +++ b/Engine/src/Engine/Core/Application.cpp @@ -110,8 +110,6 @@ namespace Light { void Application::OnEvent(const Event& event) { - LT_ENGINE_TRACE(event.GetInfoLog()); - // window if (event.HasCategory(WindowEventCategory)) { diff --git a/Engine/src/Engine/Math/TempExtensions.cpp b/Engine/src/Engine/Math/TempExtensions.cpp new file mode 100644 index 0000000..22f9f86 --- /dev/null +++ b/Engine/src/Engine/Math/TempExtensions.cpp @@ -0,0 +1,41 @@ +#include "ltpch.h" +#include "TempExtensions.h" + +#include + +namespace Light { + + float Math::Rand(int min, int max, int decimals /* = 0 */) + { + const int dec = std::pow(10, decimals); + min *= dec; + max *= dec; + + return (min + (rand() % (max)-min)) / (float)dec; + } + + glm::vec2 Math::RandVec2(int min, int max, int decimals /* = 0 */) + { + const int dec = std::pow(10, decimals); + min *= dec; + max *= dec; + + float r1 = (min + (rand() % (max)-min)) / (float)dec; + float r2 = (min + (rand() % (max)-min)) / (float)dec; + + return glm::vec2(r1, r2); + } + + glm::vec3 Math::RandVec3(int min, int max, int decimals /* = 0 */) + { + const int dec = std::pow(10, decimals); + min *= dec; + max *= dec; + + float r1 = (min + (rand() % (max)-min)) / (float)dec; + float r2 = (min + (rand() % (max)-min)) / (float)dec; + float r3 = (min + (rand() % (max)-min)) / (float)dec; + + return glm::vec3(r1, r2, r3); + } +} \ No newline at end of file diff --git a/Engine/src/Engine/Math/TempExtensions.h b/Engine/src/Engine/Math/TempExtensions.h new file mode 100644 index 0000000..9b8c717 --- /dev/null +++ b/Engine/src/Engine/Math/TempExtensions.h @@ -0,0 +1,20 @@ +#pragma once + +// #todo: make proper math stuff + +// this is a temporary header file to extend the glm math +// light engine will either have it's own math library or extend upon the glm + +#include + +namespace Light { + + class Math + { + public: + static float Rand(int min, int max, int decimals = 0); + static glm::vec2 RandVec2(int min, int max, int decimals = 0); + static glm::vec3 RandVec3(int min, int max, int decimals = 0); + }; + +} diff --git a/Engine/src/Engine/Scene/Components/TagComponent.h b/Engine/src/Engine/Scene/Components/TagComponent.h index d961482..66c8319 100644 --- a/Engine/src/Engine/Scene/Components/TagComponent.h +++ b/Engine/src/Engine/Scene/Components/TagComponent.h @@ -11,7 +11,7 @@ namespace Light { TagComponent() = default; TagComponent(const TagComponent&) = default; - TagComponent(const char* _tag) + TagComponent(const std::string& _tag) : tag(_tag) { } diff --git a/Engine/src/Engine/Scene/Scene.cpp b/Engine/src/Engine/Scene/Scene.cpp index 79428a3..0f8266e 100644 --- a/Engine/src/Engine/Scene/Scene.cpp +++ b/Engine/src/Engine/Scene/Scene.cpp @@ -85,7 +85,8 @@ namespace Light { Entity Scene::CreateEntity(const std::string& name, const TransformComponent& transform) { - Entity entity { m_Registry.create(), this } ; + Entity entity { m_Registry.create(), this }; + entity.AddComponent(name); entity.AddComponent(transform); return entity; diff --git a/Engine/src/Engine/UserInterface/UserInterface.cpp b/Engine/src/Engine/UserInterface/UserInterface.cpp index e756d03..706688f 100644 --- a/Engine/src/Engine/UserInterface/UserInterface.cpp +++ b/Engine/src/Engine/UserInterface/UserInterface.cpp @@ -20,11 +20,12 @@ namespace Light { + UserInterface* UserInterface::s_Context = nullptr; + Scope UserInterface::Create(GLFWwindow* windowHandle, Ref sharedContext) { Scope scopeUserInterface = nullptr; - switch (GraphicsContext::GetGraphicsAPI()) { case GraphicsAPI::OpenGL: @@ -44,6 +45,14 @@ namespace Light { return std::move(scopeUserInterface); } + UserInterface::UserInterface() + : m_DockspaceFlags(ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | + ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus ) + { + LT_ENGINE_ASSERT(!s_Context, "serInterface::UserInterface: an instance of 'UserInterface' already exists, do not construct this class!"); + s_Context = this; + } void UserInterface::Init(GLFWwindow* windowHandle, Ref sharedContext) { @@ -102,37 +111,113 @@ namespace Light { SetDarkThemeColors(); } + void UserInterface::DockspaceBegin() + { + ImGuiViewport* viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowPos(viewport->Pos); + ImGui::SetNextWindowSize(viewport->Size); + ImGui::SetNextWindowViewport(viewport->ID); + + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); + ImGui::Begin("Dockspace", (bool*)0, s_Context->m_DockspaceFlags); + ImGui::PopStyleVar(3); + + ImGuiStyle& style = ImGui::GetStyle(); + float minWinSizeX = style.WindowMinSize.x; + style.WindowMinSize.x = 370.0f; + ImGui::DockSpace(ImGui::GetID("MyDockSpace"), ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_None | ImGuiWindowFlags_NoBackground); + style.WindowMinSize.x = minWinSizeX; + } + + void UserInterface::DockspaceEnd() + { + ImGui::End(); + } + void UserInterface::SetDarkThemeColors() { - auto& colors = ImGui::GetStyle().Colors; - colors[ImGuiCol_WindowBg] = ImVec4{ 0.1f, 0.105f, 0.11f, 1.0f }; + ImGuiStyle& style = ImGui::GetStyle(); + ImVec4 (&colors)[55] = style.Colors; - // Headers - colors[ImGuiCol_Header] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f }; - colors[ImGuiCol_HeaderHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f }; - colors[ImGuiCol_HeaderActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; + style.WindowPadding = ImVec2(0.0f, 0.0f); - // Buttons - colors[ImGuiCol_Button] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f }; - colors[ImGuiCol_ButtonHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f }; - colors[ImGuiCol_ButtonActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; + colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); - // Frame BG - colors[ImGuiCol_FrameBg] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f }; - colors[ImGuiCol_FrameBgHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f }; - colors[ImGuiCol_FrameBgActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; + colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.11f, 1.00f); + colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f); - // Tabs - colors[ImGuiCol_Tab] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; - colors[ImGuiCol_TabHovered] = ImVec4{ 0.38f, 0.3805f, 0.381f, 1.0f }; - colors[ImGuiCol_TabActive] = ImVec4{ 0.28f, 0.2805f, 0.281f, 1.0f }; - colors[ImGuiCol_TabUnfocused] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; - colors[ImGuiCol_TabUnfocusedActive] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f }; + colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); + colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - // Title - colors[ImGuiCol_TitleBg] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; - colors[ImGuiCol_TitleBgActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; - colors[ImGuiCol_TitleBgCollapsed] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; + colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f); + colors[ImGuiCol_FrameBgHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f); + colors[ImGuiCol_FrameBgActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f); + + colors[ImGuiCol_TitleBg] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f); + colors[ImGuiCol_TitleBgActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f); + colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f); + + colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f); + + colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f); + colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f); + + colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + + colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f); + colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + + colors[ImGuiCol_Button] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f); + colors[ImGuiCol_ButtonHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f); + colors[ImGuiCol_ButtonActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f); + + colors[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f); + colors[ImGuiCol_HeaderHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f); + colors[ImGuiCol_HeaderActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f); + + colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); + colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f); + colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f); + + colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.20f); + colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); + colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); + + colors[ImGuiCol_Tab] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f); + colors[ImGuiCol_TabHovered] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f); + colors[ImGuiCol_TabActive] = ImVec4(0.28f, 0.28f, 0.28f, 1.00f); + colors[ImGuiCol_TabUnfocused] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f); + colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f); + + colors[ImGuiCol_DockingPreview] = ImVec4(0.26f, 0.59f, 0.98f, 0.70f); + colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); + + colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); + colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); + colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); + colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); + + colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f); + colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f); + colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f); + colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f); + + colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); + + colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); + + colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); + colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); + + colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); } } \ No newline at end of file diff --git a/Engine/src/Engine/UserInterface/UserInterface.h b/Engine/src/Engine/UserInterface/UserInterface.h index 4a7f9d4..0189481 100644 --- a/Engine/src/Engine/UserInterface/UserInterface.h +++ b/Engine/src/Engine/UserInterface/UserInterface.h @@ -2,6 +2,8 @@ #include "Base/Base.h" +#include + struct GLFWwindow; namespace Light { @@ -13,6 +15,11 @@ namespace Light { // #todo: fix the UserIntreface mess!! class UserInterface { + private: + static UserInterface* s_Context; + + ImGuiWindowFlags m_DockspaceFlags; + public: static Scope Create(GLFWwindow* windowHandle, Ref sharedContext); @@ -23,6 +30,9 @@ namespace Light { void Init(GLFWwindow* windowHandle, Ref sharedContext); + static void DockspaceBegin(); + static void DockspaceEnd(); + virtual void PlatformImplementation(GLFWwindow* windowHandle, Ref sharedContext) = 0; virtual void Begin() = 0; @@ -31,7 +41,7 @@ namespace Light { virtual void LogDebugData() = 0; protected: - UserInterface() = default; + UserInterface(); private: void SetDarkThemeColors(); diff --git a/Engine/src/LightEngine.h b/Engine/src/LightEngine.h index 05fab01..a1ad896 100644 --- a/Engine/src/LightEngine.h +++ b/Engine/src/LightEngine.h @@ -45,6 +45,9 @@ // third party #include +// math +#include "Math/TempExtensions.h" + // scene #include "Scene/Scene.h" #include "Scene/Entity.h" diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp index 523638f..8e845f7 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp @@ -46,6 +46,7 @@ namespace Light { void glGraphicsContext::SetDebugMessageCallback() { // determine log level + // #todo: set filters from config.h #if defined(LIGHT_DEBUG) glEnable(GL_DEBUG_OUTPUT); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr , GL_TRUE); diff --git a/Mirror/imgui_log.txt b/Mirror/imgui_log.txt new file mode 100644 index 0000000..c9370eb --- /dev/null +++ b/Mirror/imgui_log.txt @@ -0,0 +1,9 @@ +(?) +[ Copy "Hello, world!" to clipboard ] +### Window options ### +### Widgets ### +### Layout & Scrolling ### +### Popups & Modal windows ### +### Tables & Columns ### +### Filtering ### +### Inputs, Navigation & Focus ### diff --git a/Mirror/src/EditorLayer.cpp b/Mirror/src/EditorLayer.cpp new file mode 100644 index 0000000..4c8d6a1 --- /dev/null +++ b/Mirror/src/EditorLayer.cpp @@ -0,0 +1,98 @@ +#include "EditorLayer.h" + +namespace Light { + + EditorLayer::EditorLayer(const std::string& name) + : Layer(name), m_Direction(glm::vec2(0.0f, 0.0f)) + { + m_Scene = CreateRef(); + m_PropertiesPanel = CreateRef(); + m_SceneHierarchyPanel = CreateRef(m_Scene, m_PropertiesPanel); + SummonAwesomeness(); + + m_CameraEntity = m_Scene->CreateEntity("Camera", TransformComponent(glm::vec3(0.0f, 0.0f, 1000.0f))); + m_CameraEntity.AddComponent(SceneCamera(), true); + + m_Framebuffer = std::shared_ptr(Framebuffer::Create({ 1u, 1u, 1u }, GraphicsContext::GetSharedContext())); + + + // for native scripts + m_Scene->OnCreate(); + } + + void EditorLayer::OnUpdate(float deltaTime) + { + if (Input::GetKeyboardKey(Key::A)) + m_Direction.x = -1.0f; + else if (Input::GetKeyboardKey(Key::D)) + m_Direction.x = 1.0f; + else + m_Direction.x = 0.0f; + + if (Input::GetKeyboardKey(Key::W)) + m_Direction.y = 1.0f; + else if (Input::GetKeyboardKey(Key::S)) + m_Direction.y = -1.0f; + else + m_Direction.y = 0.0f; + + auto& transform = m_CameraEntity.GetComponent(); + transform.translation += glm::vec3(m_Direction * m_Speed * deltaTime, 0.0); + + m_Scene->OnUpdate(deltaTime); + } + + void EditorLayer::OnRender() + { + m_Scene->OnRender(m_Framebuffer); + } + + void EditorLayer::OnUserInterfaceUpdate() + { + UserInterface::DockspaceBegin(); + ImGui::ShowDemoWindow(); + + if (ImGui::Begin("GameView")) + { + Input::ReceiveGameEvents(ImGui::IsWindowFocused()); + + ImVec2 regionAvail = ImGui::GetContentRegionAvail(); + + if (m_AvailableContentRegionPrev != regionAvail) + { + m_AvailableContentRegionPrev = regionAvail; + m_Framebuffer->Resize({ regionAvail.x, regionAvail.y }); + + auto& cameraComp = m_CameraEntity.GetComponent(); + cameraComp.camera.SetViewportSize(regionAvail.x, regionAvail.y); + } + + if (GraphicsContext::GetGraphicsAPI() == GraphicsAPI::DirectX) + ImGui::Image(m_Framebuffer->GetColorAttachment(), regionAvail); + else // opengl + ImGui::Image(m_Framebuffer->GetColorAttachment(), regionAvail, ImVec2(0, 1), ImVec2(1, 0)); + } ImGui::End(); + + m_SceneHierarchyPanel->OnUserInterfaceUpdate(); + m_PropertiesPanel->OnUserInterfaceUpdate(); + + UserInterface::DockspaceEnd(); + } + + void EditorLayer::SummonAwesomeness() + { + ResourceManager::LoadTexture("awesomeface", "res/Textures/awesomeface.png"); + auto texture = ResourceManager::GetTexture("awesomeface"); + + for (int i = 0; i < 420; i++) + { + const glm::vec3 translation = Math::RandVec3(-500, 500); + const glm::vec3 scale = glm::vec3(Math::Rand(250, 350)); + const glm::vec3 rotation = glm::radians(Math::RandVec3(0, 360, 2));; + + Entity quad = m_Scene->CreateEntity("quad" + std::to_string(i), { translation, scale, rotation }); + quad.AddComponent(texture); + } + } + +} \ No newline at end of file diff --git a/Mirror/src/EditorLayer.h b/Mirror/src/EditorLayer.h new file mode 100644 index 0000000..d246cd9 --- /dev/null +++ b/Mirror/src/EditorLayer.h @@ -0,0 +1,43 @@ +#pragma once + +#include + +#include "Panels/SceneHierarchyPanel.h" +#include "Panels/PropertiesPanel.h" + +#include + +namespace Light { + + class EditorLayer : public Layer + { + private: + // #todo: add camera controller class to the engine + glm::vec2 m_Direction; + float m_Speed = 1000.0f; + + Ref m_Scene; + + Ref m_SceneHierarchyPanel; + Ref m_PropertiesPanel; + + Ref m_Framebuffer; + + Entity m_CameraEntity; + + ImVec2 m_AvailableContentRegionPrev; + + public: + EditorLayer(const std::string& name); + + void OnUpdate(float deltaTime) override; + + void OnRender() override; + + void OnUserInterfaceUpdate() override; + + private: + void SummonAwesomeness(); + }; + +} \ No newline at end of file diff --git a/Mirror/src/MirrorApp.cpp b/Mirror/src/MirrorApp.cpp index 73348c2..06e5a7e 100644 --- a/Mirror/src/MirrorApp.cpp +++ b/Mirror/src/MirrorApp.cpp @@ -1,7 +1,7 @@ #define LIGHT_ENTRY_POINT #include -#include "MirrorLayer.h" +#include "EditorLayer.h" namespace Light { @@ -10,8 +10,6 @@ namespace Light { public: Mirror() { - LT_CLIENT_TRACE("Mirror::Mirror"); - // Set window properties Light::WindowProperties properties; properties.title = "Mirror"; @@ -21,12 +19,7 @@ namespace Light { m_Window->SetProperties(properties); // Attach the sandbox layer - LayerStack::EmplaceLayer(("MirrorLayer")); - } - - ~Mirror() - { - LT_CLIENT_TRACE("Mirror::~Mirror"); + LayerStack::EmplaceLayer(("MirrorLayer")); } }; diff --git a/Mirror/src/MirrorLayer.h b/Mirror/src/MirrorLayer.h deleted file mode 100644 index e18b19a..0000000 --- a/Mirror/src/MirrorLayer.h +++ /dev/null @@ -1,189 +0,0 @@ -#include - -#include "Panels/SceneHierarchyPanel.h" -#include "Panels/PropertiesPanel.h" - -#include - -namespace Light { - - class MirrorLayer : public Layer - { - private: - Ref m_AwesomefaceTexture; - - glm::vec2 m_Direction; - float m_Speed = 1000.0f; - - Ref m_Framebuffer; - - Ref m_Scene; - Ref m_SceneHierarchyPanel; - Ref m_PropertiesPanel; - - Entity m_CameraEntity; - Entity m_NativeScriptEntity; - - public: - MirrorLayer(const std::string& name) - : Layer(name), m_Direction(glm::vec2(0.0f, 0.0f)) - { - ResourceManager::LoadTexture("awesomeface", "res/Textures/awesomeface.png"); - m_AwesomefaceTexture = ResourceManager::GetTexture("awesomeface"); - - m_Framebuffer = std::shared_ptr(Framebuffer::Create({ 800u, 600u, 1u }, GraphicsContext::GetSharedContext())); - - m_Scene = CreateRef(); - - for (int i = 0; i < 250; i++) - { - glm::vec3 position = glm::vec3(rand() % 3000 - 1400.0f, rand() % 3000 - 1400.0f, 0.0f); - glm::vec2 size = glm::vec2(250.0f, 250.0f); - - Entity quad = m_Scene->CreateEntity("quad", TransformComponent(glm::vec3(position.x, position.y, 0.0f), glm::vec3(size.x, size.y, 1.0f))); - quad.AddComponent(m_AwesomefaceTexture); - quad.AddComponent("quad"); - - } - - m_CameraEntity = m_Scene->CreateEntity("camera", TransformComponent(glm::vec3(0.0f, 0.0f, 1000.0f))); - m_CameraEntity.AddComponent(SceneCamera(), true); - m_CameraEntity.AddComponent("Camera"); - - m_NativeScriptEntity = m_Scene->CreateEntity("nsc"); - m_NativeScriptEntity.AddComponent(m_AwesomefaceTexture); - m_NativeScriptEntity.AddComponent("NativeScript"); - - class SampleNativeScript : public Light::NativeScript - { - private: - void OnUpdate(float deltaTime) - { - } - }; - m_NativeScriptEntity.AddComponent().Bind(); - - - // create native scripts - m_Scene->OnCreate(); - - m_PropertiesPanel = CreateRef(); - m_SceneHierarchyPanel = CreateRef(m_Scene, m_PropertiesPanel); - } - - void OnUpdate(float deltaTime) override - { - if (Input::GetKeyboardKey(Key::A)) - m_Direction.x = -1.0f; - else if (Input::GetKeyboardKey(Key::D)) - m_Direction.x = 1.0f; - else - m_Direction.x = 0.0f; - - if (Input::GetKeyboardKey(Key::W)) - m_Direction.y = 1.0f; - else if (Input::GetKeyboardKey(Key::S)) - m_Direction.y = -1.0f; - else - m_Direction.y = 0.0f; - - auto& transform = m_CameraEntity.GetComponent(); - transform.translation += glm::vec3(m_Direction * m_Speed * deltaTime, 0.0); - - m_Scene->OnUpdate(deltaTime); - } - - void OnRender() override - { - m_Scene->OnRender(m_Framebuffer); - } - - void OnUserInterfaceUpdate() - { - // Note: Switch this to true to enable dockspace - static bool dockspaceOpen = true; - static bool opt_fullscreen_persistant = true; - bool opt_fullscreen = opt_fullscreen_persistant; - static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None; - - // We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into, - // because it would be confusing to have two docking targets within each others. - ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking; - if (opt_fullscreen) - { - ImGuiViewport* viewport = ImGui::GetMainViewport(); - ImGui::SetNextWindowPos(viewport->Pos); - ImGui::SetNextWindowSize(viewport->Size); - ImGui::SetNextWindowViewport(viewport->ID); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); - window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; - window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus; - } - - // When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background and handle the pass-thru hole, so we ask Begin() to not render a background. - if (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode) - window_flags |= ImGuiWindowFlags_NoBackground; - - // Important: note that we proceed even if Begin() returns false (aka window is collapsed). - // This is because we want to keep our DockSpace() active. If a DockSpace() is inactive, - // all active windows docked into it will lose their parent and become undocked. - // We cannot preserve the docking relationship between an active window and an inactive docking, otherwise - // any change of dockspace/settings would lead to windows being stuck in limbo and never being visible. - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); - ImGui::Begin("DockSpace Demo", &dockspaceOpen, window_flags); - ImGui::PopStyleVar(); - - if (opt_fullscreen) - ImGui::PopStyleVar(2); - - // DockSpace - ImGuiIO& io = ImGui::GetIO(); - ImGuiStyle& style = ImGui::GetStyle(); - float minWinSizeX = style.WindowMinSize.x; - style.WindowMinSize.x = 370.0f; - if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable) - { - ImGuiID dockspace_id = ImGui::GetID("MyDockSpace"); - ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags); - } - - style.WindowMinSize.x = minWinSizeX; - - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0, 0 }); - if (ImGui::Begin("GameView")) - { - // #todo: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - Input::ReceiveGameEvents(ImGui::IsWindowFocused()); - - static ImVec2 regionAvailPrev = { 0, 0 }; - ImVec2 regionAvail = ImGui::GetContentRegionAvail(); - - if (regionAvail.x != regionAvailPrev.x || regionAvail.y != regionAvailPrev.y) - { - m_Framebuffer->Resize({ regionAvail.x, regionAvail.y }); - - auto& cameraComp = m_CameraEntity.GetComponent(); - cameraComp.camera.SetViewportSize(regionAvail.x, regionAvail.y); - - regionAvailPrev = regionAvail; - } - - if (GraphicsContext::GetGraphicsAPI() == GraphicsAPI::DirectX) - ImGui::Image(m_Framebuffer->GetColorAttachment(), regionAvail); - else - ImGui::Image(m_Framebuffer->GetColorAttachment(), regionAvail, ImVec2(0, 1), ImVec2(1, 0)); - } - - ImGui::ShowDemoWindow(); - - ImGui::End(); - ImGui::PopStyleVar(); - ImGui::End(); - m_SceneHierarchyPanel->OnUserInterfaceUpdate(); - m_PropertiesPanel->OnUserInterfaceUpdate(); - } - - }; - -} \ No newline at end of file