Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jmorton06 committed Jun 2, 2024
1 parent c79b917 commit b80264b
Show file tree
Hide file tree
Showing 73 changed files with 1,442 additions and 1,525 deletions.
5 changes: 4 additions & 1 deletion Editor/Source/ConsolePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Lumos
bool ConsolePanel::s_AllowScrollingToBottom = true;
bool ConsolePanel::s_RequestScrollToBottom = false;
std::mutex ConsolePanel::m_MessageBufferMutex;
Vector<ConsoleMessage> ConsolePanel::m_MessageBuffer = Vector<ConsoleMessage>(2000);
TDArray<ConsoleMessage> ConsolePanel::m_MessageBuffer = TDArray<ConsoleMessage>(2000);

const char* GetLevelIcon(ConsoleLogLevel level)
{
Expand Down Expand Up @@ -254,6 +254,9 @@ namespace Lumos
for(uint32_t i = 0; i < m_MessageBuffer.Size(); i++)
{
auto& msg = m_MessageBuffer[i];

if(Filter.IsActive() && !Filter.PassFilter(msg.m_Message.c_str()))
continue;
DrawMessage(&msg);
}

Expand Down
4 changes: 2 additions & 2 deletions Editor/Source/ConsolePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <imgui/imgui.h>
#include <Lumos/Core/Reference.h>
#include <Lumos/Core/DataStructures/Vector.h>
#include <Lumos/Core/DataStructures/TDArray.h>

namespace Lumos
{
Expand Down Expand Up @@ -50,7 +50,7 @@ namespace Lumos

private:
static std::mutex m_MessageBufferMutex;
static Vector<ConsoleMessage> m_MessageBuffer;
static TDArray<ConsoleMessage> m_MessageBuffer;

static bool s_AllowScrollingToBottom;
static bool s_RequestScrollToBottom;
Expand Down
48 changes: 22 additions & 26 deletions Editor/Source/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
#include <Lumos/Core/CommandLine.h>
#include <Lumos/Core/CoreSystem.h>
#include <Lumos/Core/Thread.h>

#include <spdlog/spdlog.h>
#include <spdlog/fmt/ostr.h>

Expand Down Expand Up @@ -716,7 +715,7 @@ namespace Lumos
for(auto entity : m_CopiedEntities)
{
Application::Get().GetCurrentScene()->DuplicateEntity({ entity, Application::Get().GetCurrentScene() });
if(entity != entt::null)
if(entity.Valid())
{
/// if(entity == m_SelectedEntity)
/// m_SelectedEntity = entt::null;
Expand Down Expand Up @@ -1328,15 +1327,15 @@ namespace Lumos

if(m_SelectedEntities.size() == 1)
{
entt::entity m_SelectedEntity = entt::null;
Entity m_SelectedEntity = {};

m_SelectedEntity = m_SelectedEntities.front();
if(registry.valid(m_SelectedEntity))
if(m_SelectedEntity.Valid())
{
ImGuizmo::SetDrawlist();
ImGuizmo::SetOrthographic(m_CurrentCamera->IsOrthographic());

auto transform = registry.try_get<Maths::Transform>(m_SelectedEntity);
auto transform = m_SelectedEntity.TryGetComponent<Maths::Transform>();
if(transform != nullptr)
{
glm::mat4 model = transform->GetWorldMatrix();
Expand All @@ -1354,7 +1353,7 @@ namespace Lumos

if(ImGuizmo::IsUsing())
{
Entity parent = Entity(m_SelectedEntity, m_SceneManager->GetCurrentScene()).GetParent(); // m_CurrentScene->TryGetEntityWithUUID(entity.GetParentUUID());
Entity parent = m_SelectedEntity.GetParent(); // m_CurrentScene->TryGetEntityWithUUID(entity.GetParentUUID());
if(parent && parent.HasComponent<Maths::Transform>())
{
glm::mat4 parentTransform = parent.GetTransform().GetWorldMatrix();
Expand All @@ -1369,7 +1368,7 @@ namespace Lumos
{
transform->SetLocalTransform(model);

RigidBody2DComponent* rigidBody2DComponent = registry.try_get<Lumos::RigidBody2DComponent>(m_SelectedEntity);
RigidBody2DComponent* rigidBody2DComponent = m_SelectedEntity.TryGetComponent<Lumos::RigidBody2DComponent>();

if(rigidBody2DComponent)
{
Expand All @@ -1378,7 +1377,7 @@ namespace Lumos
}
else
{
Lumos::RigidBody3DComponent* rigidBody3DComponent = registry.try_get<Lumos::RigidBody3DComponent>(m_SelectedEntity);
Lumos::RigidBody3DComponent* rigidBody3DComponent = m_SelectedEntity.TryGetComponent<Lumos::RigidBody3DComponent>();
if(rigidBody3DComponent)
{
rigidBody3DComponent->GetRigidBody()->SetPosition(model[3]);
Expand Down Expand Up @@ -1993,9 +1992,7 @@ namespace Lumos
glm::mix(
cameraCurrentPosition,
m_CameraDestination,
glm::clamp(m_CameraTransitionSpeed * kSpeedBaseFactor * static_cast<float>(ts.GetSeconds()), 0.0f, 1.0f)
)
);
glm::clamp(m_CameraTransitionSpeed * kSpeedBaseFactor * static_cast<float>(ts.GetSeconds()), 0.0f, 1.0f)));

auto distanceToDestination = glm::distance(cameraCurrentPosition, m_CameraDestination);

Expand Down Expand Up @@ -2108,7 +2105,7 @@ namespace Lumos
for(auto entity : m_CopiedEntities)
{
Application::Get().GetCurrentScene()->DuplicateEntity({ entity, Application::Get().GetCurrentScene() });
if(entity != entt::null)
if(entity.Valid())
{
// if(m_CopiedEntity == m_SelectedEntity)
// m_SelectedEntity = entt::null;
Expand All @@ -2130,19 +2127,17 @@ namespace Lumos
Application::OnUpdate(ts);
}

void Editor::SetSelected(entt::entity entity)
void Editor::SetSelected(Entity entity)
{
auto& registry = Application::Get().GetSceneManager()->GetCurrentScene()->GetRegistry();

if(!registry.valid(entity))
if(!entity.Valid())
return;
if(std::find(m_SelectedEntities.begin(), m_SelectedEntities.end(), entity) != m_SelectedEntities.end())
return;

m_SelectedEntities.push_back(entity);
}

void Editor::UnSelect(entt::entity entity)
void Editor::UnSelect(Entity entity)
{
auto it = std::find(m_SelectedEntities.begin(), m_SelectedEntities.end(), entity);

Expand All @@ -2167,8 +2162,8 @@ namespace Lumos
{
m_TransitioningCamera = true;

m_CameraDestination = point + m_EditorCameraTransform.GetForwardDirection() * distance;
m_CameraTransitionSpeed = speed;
m_CameraDestination = point + m_EditorCameraTransform.GetForwardDirection() * distance;
m_CameraTransitionSpeed = speed;
}
}

Expand Down Expand Up @@ -2430,9 +2425,10 @@ namespace Lumos
void Editor::SelectObject(const Maths::Ray& ray, bool hoveredOnly)
{
LUMOS_PROFILE_FUNCTION();
auto& registry = Application::Get().GetSceneManager()->GetCurrentScene()->GetRegistry();
auto scene = Application::Get().GetSceneManager()->GetCurrentScene();
auto& registry = scene->GetRegistry();
float closestEntityDist = Maths::M_INFINITY;
entt::entity currentClosestEntity = entt::null;
Entity currentClosestEntity = {};

auto group = registry.group<Graphics::ModelComponent>(entt::get<Maths::Transform>);

Expand Down Expand Up @@ -2460,7 +2456,7 @@ namespace Lumos
if(distance < closestEntityDist)
{
closestEntityDist = distance;
currentClosestEntity = entity;
currentClosestEntity = { entity, scene };
}
}
}
Expand Down Expand Up @@ -2514,7 +2510,7 @@ namespace Lumos
if(distance < closestEntityDist)
{
closestEntityDist = distance;
currentClosestEntity = entity;
currentClosestEntity = { entity, scene };
}
}
}
Expand All @@ -2535,7 +2531,7 @@ namespace Lumos
if(distance < closestEntityDist)
{
closestEntityDist = distance;
currentClosestEntity = entity;
currentClosestEntity = { entity, scene };
}
}
}
Expand Down Expand Up @@ -2733,7 +2729,7 @@ namespace Lumos
modelEntity.AddComponent<Graphics::ModelComponent>(path);

m_SelectedEntities.clear();
SetSelected(modelEntity.GetHandle());
SetSelected(modelEntity);
}
else if(IsAudioFile(path))
{
Expand All @@ -2754,7 +2750,7 @@ namespace Lumos
Entity entity = Application::Get().GetSceneManager()->GetCurrentScene()->GetEntityManager()->Create(StringUtilities::GetFileName(path));
entity.AddComponent<SoundComponent>(soundNode);
entity.GetOrAddComponent<Maths::Transform>();
SetSelected(entity.GetHandle());
SetSelected(entity);
}
else if(IsSceneFile(path))
{
Expand Down
36 changes: 19 additions & 17 deletions Editor/Source/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "FileBrowserPanel.h"
#include "PreviewDraw.h"

#include <Lumos/Maths/Ray.h>
#include <Lumos/Maths/Transform.h>
#include <Lumos/Utilities/IniFile.h>
#include <Lumos/Graphics/Camera/EditorCamera.h>
Expand All @@ -13,7 +12,6 @@
#include <Lumos/Core/Application.h>
#include <Lumos/Scene/Entity.h>
#include <imgui/imgui.h>
#include <entt/entt.hpp>

namespace Lumos
{
Expand All @@ -27,6 +25,7 @@ namespace Lumos
class WindowResizeEvent;
class WindowFileEvent;
class TimeStep;
class Entity;

namespace Graphics
{
Expand All @@ -37,6 +36,11 @@ namespace Lumos
class RenderPasses;
}

namespace Maths
{
class Ray;
}

enum EditorDebugFlags : uint32_t
{
Grid = 1,
Expand Down Expand Up @@ -136,32 +140,32 @@ namespace Lumos
m_SelectedEntities.clear();
}

void SetSelected(entt::entity entity);
void UnSelect(entt::entity entity);
void SetSelected(Entity entity);
void UnSelect(Entity entity);
void SetHoveredEntity(Entity entity) { m_HoveredEntity = entity; }
Entity GetHoveredEntity() { return m_HoveredEntity; }
const std::vector<entt::entity>& GetSelected() const
const std::vector<Entity>& GetSelected() const
{
return m_SelectedEntities;
}

bool IsSelected(entt::entity entity)
bool IsSelected(Entity entity)
{
if(std::find(m_SelectedEntities.begin(), m_SelectedEntities.end(), entity) != m_SelectedEntities.end())
return true;

return false;
}

bool IsCopied(entt::entity entity)
bool IsCopied(Entity entity)
{
if(std::find(m_CopiedEntities.begin(), m_CopiedEntities.end(), entity) != m_CopiedEntities.end())
return true;

return false;
}

void SetCopiedEntity(entt::entity entity, bool cut = false)
void SetCopiedEntity(Entity entity, bool cut = false)
{
if(std::find(m_CopiedEntities.begin(), m_CopiedEntities.end(), entity) != m_CopiedEntities.end())
return;
Expand All @@ -170,7 +174,7 @@ namespace Lumos
m_CutCopyEntity = cut;
}

const std::vector<entt::entity>& GetCopiedEntity() const
const std::vector<Entity>& GetCopiedEntity() const
{
return m_CopiedEntities;
}
Expand Down Expand Up @@ -292,15 +296,13 @@ namespace Lumos
Application* m_Application;

uint32_t m_ImGuizmoOperation = 14463;
std::vector<entt::entity> m_SelectedEntities;
std::vector<entt::entity> m_CopiedEntities;

std::vector<Entity> m_SelectedEntities;
std::vector<Entity> m_CopiedEntities;
Entity m_HoveredEntity;
bool m_CutCopyEntity = false;
float m_CurrentSceneAspectRatio = 0.0f;
float m_CameraTransitionSpeed = 0.0f;
bool m_TransitioningCamera = false;

bool m_CutCopyEntity = false;
float m_CurrentSceneAspectRatio = 0.0f;
float m_CameraTransitionSpeed = 0.0f;
bool m_TransitioningCamera = false;
glm::vec3 m_CameraDestination;
bool m_SceneViewActive = false;
bool m_NewProjectPopupOpen = false;
Expand Down
2 changes: 1 addition & 1 deletion Editor/Source/GameViewPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ namespace Lumos
bool resize = false;

LUMOS_ASSERT(width > 0 && height > 0, "Game View Dimensions 0");
;
Application::Get().SetSceneViewDimensions(width, height);

if(m_Width != width || m_Height != height)
{
Expand Down
Loading

0 comments on commit b80264b

Please sign in to comment.