Maintenance
- Mirror project maintenance and tidying - General maintenance
This commit is contained in:
parent
e02a4850e0
commit
7ec9690f52
15 changed files with 342 additions and 229 deletions
|
@ -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)
|
||||
|
|
|
@ -110,8 +110,6 @@ namespace Light {
|
|||
|
||||
void Application::OnEvent(const Event& event)
|
||||
{
|
||||
LT_ENGINE_TRACE(event.GetInfoLog());
|
||||
|
||||
// window
|
||||
if (event.HasCategory(WindowEventCategory))
|
||||
{
|
||||
|
|
41
Engine/src/Engine/Math/TempExtensions.cpp
Normal file
41
Engine/src/Engine/Math/TempExtensions.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include "ltpch.h"
|
||||
#include "TempExtensions.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
20
Engine/src/Engine/Math/TempExtensions.h
Normal file
20
Engine/src/Engine/Math/TempExtensions.h
Normal file
|
@ -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 <glm/glm.hpp>
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
}
|
|
@ -11,7 +11,7 @@ namespace Light {
|
|||
TagComponent() = default;
|
||||
TagComponent(const TagComponent&) = default;
|
||||
|
||||
TagComponent(const char* _tag)
|
||||
TagComponent(const std::string& _tag)
|
||||
: tag(_tag)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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<TagComponent>(name);
|
||||
entity.AddComponent<TransformComponent>(transform);
|
||||
|
||||
return entity;
|
||||
|
|
|
@ -20,11 +20,12 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
UserInterface* UserInterface::s_Context = nullptr;
|
||||
|
||||
Scope<UserInterface> UserInterface::Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
||||
{
|
||||
Scope<UserInterface> 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> 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "Base/Base.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
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<UserInterface> Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
|
||||
|
||||
|
@ -23,6 +30,9 @@ namespace Light {
|
|||
|
||||
void Init(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
|
||||
|
||||
static void DockspaceBegin();
|
||||
static void DockspaceEnd();
|
||||
|
||||
virtual void PlatformImplementation(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext) = 0;
|
||||
|
||||
virtual void Begin() = 0;
|
||||
|
@ -31,7 +41,7 @@ namespace Light {
|
|||
virtual void LogDebugData() = 0;
|
||||
|
||||
protected:
|
||||
UserInterface() = default;
|
||||
UserInterface();
|
||||
|
||||
private:
|
||||
void SetDarkThemeColors();
|
||||
|
|
|
@ -45,6 +45,9 @@
|
|||
// third party
|
||||
#include <imgui.h>
|
||||
|
||||
// math
|
||||
#include "Math/TempExtensions.h"
|
||||
|
||||
// scene
|
||||
#include "Scene/Scene.h"
|
||||
#include "Scene/Entity.h"
|
||||
|
|
|
@ -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);
|
||||
|
|
9
Mirror/imgui_log.txt
Normal file
9
Mirror/imgui_log.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
(?)
|
||||
[ Copy "Hello, world!" to clipboard ]
|
||||
### Window options ###
|
||||
### Widgets ###
|
||||
### Layout & Scrolling ###
|
||||
### Popups & Modal windows ###
|
||||
### Tables & Columns ###
|
||||
### Filtering ###
|
||||
### Inputs, Navigation & Focus ###
|
98
Mirror/src/EditorLayer.cpp
Normal file
98
Mirror/src/EditorLayer.cpp
Normal file
|
@ -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<Scene>();
|
||||
m_PropertiesPanel = CreateRef<PropertiesPanel>();
|
||||
m_SceneHierarchyPanel = CreateRef<SceneHierarchyPanel>(m_Scene, m_PropertiesPanel);
|
||||
SummonAwesomeness();
|
||||
|
||||
m_CameraEntity = m_Scene->CreateEntity("Camera", TransformComponent(glm::vec3(0.0f, 0.0f, 1000.0f)));
|
||||
m_CameraEntity.AddComponent<CameraComponent>(SceneCamera(), true);
|
||||
|
||||
m_Framebuffer = std::shared_ptr<Framebuffer>(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<TransformComponent>();
|
||||
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<CameraComponent>();
|
||||
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<SpriteRendererComponent>(texture);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
43
Mirror/src/EditorLayer.h
Normal file
43
Mirror/src/EditorLayer.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <LightEngine.h>
|
||||
|
||||
#include "Panels/SceneHierarchyPanel.h"
|
||||
#include "Panels/PropertiesPanel.h"
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
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<Scene> m_Scene;
|
||||
|
||||
Ref<SceneHierarchyPanel> m_SceneHierarchyPanel;
|
||||
Ref<PropertiesPanel> m_PropertiesPanel;
|
||||
|
||||
Ref<Framebuffer> 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();
|
||||
};
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
#define LIGHT_ENTRY_POINT
|
||||
#include <LightEngine.h>
|
||||
|
||||
#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>(("MirrorLayer"));
|
||||
}
|
||||
|
||||
~Mirror()
|
||||
{
|
||||
LT_CLIENT_TRACE("Mirror::~Mirror");
|
||||
LayerStack::EmplaceLayer<EditorLayer>(("MirrorLayer"));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,189 +0,0 @@
|
|||
#include <LightEngine.h>
|
||||
|
||||
#include "Panels/SceneHierarchyPanel.h"
|
||||
#include "Panels/PropertiesPanel.h"
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace Light {
|
||||
|
||||
class MirrorLayer : public Layer
|
||||
{
|
||||
private:
|
||||
Ref<Texture> m_AwesomefaceTexture;
|
||||
|
||||
glm::vec2 m_Direction;
|
||||
float m_Speed = 1000.0f;
|
||||
|
||||
Ref<Framebuffer> m_Framebuffer;
|
||||
|
||||
Ref<Scene> m_Scene;
|
||||
Ref<SceneHierarchyPanel> m_SceneHierarchyPanel;
|
||||
Ref<PropertiesPanel> 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>(Framebuffer::Create({ 800u, 600u, 1u }, GraphicsContext::GetSharedContext()));
|
||||
|
||||
m_Scene = CreateRef<Scene>();
|
||||
|
||||
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<SpriteRendererComponent>(m_AwesomefaceTexture);
|
||||
quad.AddComponent<TagComponent>("quad");
|
||||
|
||||
}
|
||||
|
||||
m_CameraEntity = m_Scene->CreateEntity("camera", TransformComponent(glm::vec3(0.0f, 0.0f, 1000.0f)));
|
||||
m_CameraEntity.AddComponent<CameraComponent>(SceneCamera(), true);
|
||||
m_CameraEntity.AddComponent<TagComponent>("Camera");
|
||||
|
||||
m_NativeScriptEntity = m_Scene->CreateEntity("nsc");
|
||||
m_NativeScriptEntity.AddComponent<SpriteRendererComponent>(m_AwesomefaceTexture);
|
||||
m_NativeScriptEntity.AddComponent<TagComponent>("NativeScript");
|
||||
|
||||
class SampleNativeScript : public Light::NativeScript
|
||||
{
|
||||
private:
|
||||
void OnUpdate(float deltaTime)
|
||||
{
|
||||
}
|
||||
};
|
||||
m_NativeScriptEntity.AddComponent<NativeScriptComponent>().Bind<SampleNativeScript>();
|
||||
|
||||
|
||||
// create native scripts
|
||||
m_Scene->OnCreate();
|
||||
|
||||
m_PropertiesPanel = CreateRef<PropertiesPanel>();
|
||||
m_SceneHierarchyPanel = CreateRef<SceneHierarchyPanel>(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<TransformComponent>();
|
||||
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<CameraComponent>();
|
||||
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();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue