2021-08-14 16:17:33 +04:30
|
|
|
#include "EditorLayer.h"
|
|
|
|
|
|
|
|
namespace Light {
|
|
|
|
|
|
|
|
EditorLayer::EditorLayer(const std::string& name)
|
2021-08-16 16:21:03 +04:30
|
|
|
: Layer(name)
|
2021-08-14 16:17:33 +04:30
|
|
|
{
|
|
|
|
m_Scene = CreateRef<Scene>();
|
2021-08-16 16:21:03 +04:30
|
|
|
|
2021-08-14 16:17:33 +04:30
|
|
|
m_PropertiesPanel = CreateRef<PropertiesPanel>();
|
|
|
|
m_SceneHierarchyPanel = CreateRef<SceneHierarchyPanel>(m_Scene, m_PropertiesPanel);
|
2021-09-11 11:29:44 +04:30
|
|
|
|
2021-08-14 16:17:33 +04:30
|
|
|
SummonAwesomeness();
|
|
|
|
|
2021-08-16 16:21:03 +04:30
|
|
|
m_Framebuffer = Framebuffer::Create({ 1, 1, 1 }, GraphicsContext::GetSharedContext());
|
|
|
|
|
|
|
|
m_CameraEntity = m_Scene->CreateEntity("Game Camera", TransformComponent({0.0f, 0.0f, 1000.0f}));
|
2021-08-14 16:17:33 +04:30
|
|
|
m_CameraEntity.AddComponent<CameraComponent>(SceneCamera(), true);
|
|
|
|
|
2021-08-16 16:21:03 +04:30
|
|
|
// for native script components
|
2021-08-14 16:17:33 +04:30
|
|
|
m_Scene->OnCreate();
|
2021-08-16 16:21:03 +04:30
|
|
|
}
|
|
|
|
|
2021-08-14 16:17:33 +04:30
|
|
|
void EditorLayer::OnUpdate(float deltaTime)
|
|
|
|
{
|
|
|
|
m_Scene->OnUpdate(deltaTime);
|
|
|
|
|
2021-08-16 16:21:03 +04:30
|
|
|
m_Direction.x = Input::GetKeyboardKey(Key::A) ? -1.0f :
|
|
|
|
Input::GetKeyboardKey(Key::D) ? 1.0f : 0.0f;
|
|
|
|
|
|
|
|
m_Direction.y = Input::GetKeyboardKey(Key::S) ? -1.0f :
|
|
|
|
Input::GetKeyboardKey(Key::W) ? 1.0f : 0.0f;
|
|
|
|
|
|
|
|
auto& cameraTranslation = m_CameraEntity.GetComponent<TransformComponent>().translation;
|
|
|
|
cameraTranslation += glm::vec3(m_Direction * m_Speed * deltaTime, 0.0f);
|
2021-10-02 08:51:54 +03:30
|
|
|
|
|
|
|
if (Input::GetKeyboardKey(Key::Escape))
|
|
|
|
Application::Quit();
|
2021-08-16 16:21:03 +04:30
|
|
|
}
|
|
|
|
|
2021-08-14 16:17:33 +04:30
|
|
|
void EditorLayer::OnRender()
|
|
|
|
{
|
|
|
|
m_Scene->OnRender(m_Framebuffer);
|
|
|
|
}
|
2021-08-16 16:21:03 +04:30
|
|
|
|
2021-08-14 16:17:33 +04:30
|
|
|
void EditorLayer::OnUserInterfaceUpdate()
|
|
|
|
{
|
|
|
|
UserInterface::DockspaceBegin();
|
|
|
|
ImGui::ShowDemoWindow();
|
|
|
|
|
2021-08-16 16:21:03 +04:30
|
|
|
if (ImGui::Begin("Game"))
|
2021-08-14 16:17:33 +04:30
|
|
|
{
|
|
|
|
Input::ReceiveGameEvents(ImGui::IsWindowFocused());
|
|
|
|
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
|
|
|
|
2021-09-09 19:46:02 +04:30
|
|
|
if (m_AvailableContentRegionPrev != regionAvail)
|
2021-08-14 16:17:33 +04:30
|
|
|
{
|
|
|
|
m_Framebuffer->Resize({ regionAvail.x, regionAvail.y });
|
2021-08-16 16:21:03 +04:30
|
|
|
auto& camera = m_CameraEntity.GetComponent<CameraComponent>().camera;
|
2021-09-09 19:46:02 +04:30
|
|
|
camera.SetViewportSize(regionAvail.x, regionAvail.y);
|
2021-08-14 16:17:33 +04:30
|
|
|
|
2021-08-16 16:21:03 +04:30
|
|
|
m_AvailableContentRegionPrev = regionAvail;
|
2021-08-14 16:17:33 +04:30
|
|
|
}
|
|
|
|
|
2021-09-09 19:46:02 +04:30
|
|
|
if (GraphicsContext::GetGraphicsAPI() == GraphicsAPI::DirectX)
|
2021-08-14 16:17:33 +04:30
|
|
|
ImGui::Image(m_Framebuffer->GetColorAttachment(), regionAvail);
|
2021-08-16 16:21:03 +04:30
|
|
|
else
|
2021-08-14 16:17:33 +04:30
|
|
|
ImGui::Image(m_Framebuffer->GetColorAttachment(), regionAvail, ImVec2(0, 1), ImVec2(1, 0));
|
|
|
|
} ImGui::End();
|
|
|
|
|
|
|
|
m_SceneHierarchyPanel->OnUserInterfaceUpdate();
|
|
|
|
m_PropertiesPanel->OnUserInterfaceUpdate();
|
|
|
|
|
|
|
|
UserInterface::DockspaceEnd();
|
|
|
|
}
|
2021-08-16 16:21:03 +04:30
|
|
|
|
2021-08-14 16:17:33 +04:30
|
|
|
void EditorLayer::SummonAwesomeness()
|
|
|
|
{
|
2021-09-09 19:46:02 +04:30
|
|
|
ResourceManager::LoadTexture("awesomeface", "../../Mirror/res/Textures/awesomeface.png");
|
2021-08-14 16:17:33 +04:30
|
|
|
auto texture = ResourceManager::GetTexture("awesomeface");
|
|
|
|
|
2021-08-16 16:21:03 +04:30
|
|
|
for(unsigned int i = 0; i < 250; i++)
|
2021-08-14 16:17:33 +04:30
|
|
|
{
|
|
|
|
const glm::vec3 translation = Math::RandVec3(-500, 500);
|
2021-08-16 16:21:03 +04:30
|
|
|
const glm::vec3 scale = glm::vec3(Math::Rand(125, 200));
|
2021-09-09 19:46:02 +04:30
|
|
|
const glm::vec3 rotation = glm::vec3(0.0f, 0.0f, glm::radians(Math::Rand(0, 359)));
|
2021-08-14 16:17:33 +04:30
|
|
|
|
2021-08-16 16:21:03 +04:30
|
|
|
const glm::vec4 tint = glm::vec4(Math::RandVec3(0, 1, 2), 1.0f);
|
|
|
|
|
2021-09-23 11:20:57 +03:30
|
|
|
auto entity = m_Scene->CreateEntity("quad" + std::to_string(i), { translation, scale, rotation });
|
2021-08-16 16:21:03 +04:30
|
|
|
entity.AddComponent<SpriteRendererComponent>(texture, tint);
|
2021-08-14 16:17:33 +04:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|