Skip to content

Commit

Permalink
Small fixes + Debug renderer batching
Browse files Browse the repository at this point in the history
  • Loading branch information
jmorton06 committed Feb 12, 2024
1 parent 3dd7cb5 commit b911f5a
Show file tree
Hide file tree
Showing 72 changed files with 1,649 additions and 794 deletions.
13 changes: 12 additions & 1 deletion Editor/Source/ApplicationInfoPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Lumos

ApplicationInfoPanel::ApplicationInfoPanel()
{
m_Name = "Application Info##ApplicationInfo";
m_Name = "Application Info###appinfo";
m_SimpleName = "Application Info";
}

Expand Down Expand Up @@ -133,6 +133,17 @@ namespace Lumos
Application::Get().GetWindow()->GetSwapChain()->SetVSync(VSync);
Graphics::Renderer::GetRenderer()->OnResize(Application::Get().GetWindow()->GetWidth(), Application::Get().GetWindow()->GetHeight()); });
}

QualitySettings& qs = Application::Get().GetQualitySettings();
int shadowQuality = (int)qs.ShadowQuality;
int shadowRes = (int)qs.ShadowResolution;

if (ImGuiUtilities::Property("Shadow Quality", shadowQuality, 0, 3))
qs.ShadowQuality = (ShadowQualitySetting)shadowQuality;

if (ImGuiUtilities::Property("Shadow Resolution", shadowRes, 0, 3))
qs.ShadowResolution = (ShadowResolutionSetting)shadowRes;

ImGui::Columns(1);
ImGui::Text("FPS : %5.2i", Engine::Get().Statistics().FramesPerSecond);
ImGui::Text("UPS : %5.2i", Engine::Get().Statistics().UpdatesPerSecond);
Expand Down
64 changes: 57 additions & 7 deletions Editor/Source/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <Lumos/Core/String.h>
#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 @@ -892,6 +893,7 @@ namespace Lumos
Application::Get().GetSystem<AudioManager>()->UpdateListener(Application::Get().GetCurrentScene());
Application::Get().GetSystem<AudioManager>()->SetPaused(selected);
Application::Get().SetEditorState(selected ? EditorState::Preview : EditorState::Play);
ImGui::SetWindowFocus(ICON_MDI_GAMEPAD_VARIANT " Game###game");

m_SelectedEntities.clear();
// m_SelectedEntity = entt::null;
Expand Down Expand Up @@ -1134,7 +1136,7 @@ namespace Lumos
if(defaultSetup)
{
auto light = scene->GetEntityManager()->Create("Light");
auto lightComp = light.AddComponent<Graphics::Light>();
auto& lightComp = light.AddComponent<Graphics::Light>();
glm::mat4 lightView = glm::inverse(glm::lookAt(glm::vec3(30.0f, 9.0f, 50.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)));
light.GetTransform().SetLocalTransform(lightView);

Expand Down Expand Up @@ -1177,7 +1179,7 @@ namespace Lumos
locationPopupOpened = true;

// Set filePath to working directory
const auto& path = OS::Instance()->GetExecutablePath();
const auto& path = OS::Instance()->GetExecutablePath();
auto& browserPath = m_FileBrowserPanel.GetPath();
browserPath = std::filesystem::path(path);
m_FileBrowserPanel.SetFileTypeFilters({ ".lmproj" });
Expand Down Expand Up @@ -1611,7 +1613,7 @@ namespace Lumos
ImGui::DockBuilderDockWindow("###resources", DockingBottomLeftChild);
ImGui::DockBuilderDockWindow("Dear ImGui Demo", DockLeft);
ImGui::DockBuilderDockWindow("###GraphicsInfo", DockLeft);
ImGui::DockBuilderDockWindow("###ApplicationInfo", DockLeft);
ImGui::DockBuilderDockWindow("###appinfo", DockLeft);
ImGui::DockBuilderDockWindow("###hierarchy", DockLeft);
ImGui::DockBuilderDockWindow("###textEdit", DockMiddleLeft);
ImGui::DockBuilderDockWindow("###scenesettings", DockLeft);
Expand Down Expand Up @@ -1715,9 +1717,9 @@ namespace Lumos
return;
}

DebugRenderer::DrawHairLine(glm::vec3(-5000.0f, 0.0f, 0.0f), glm::vec3(5000.0f, 0.0f, 0.0f), glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
DebugRenderer::DrawHairLine(glm::vec3(0.0f, -5000.0f, 0.0f), glm::vec3(0.0f, 5000.0f, 0.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f));
DebugRenderer::DrawHairLine(glm::vec3(0.0f, 0.0f, -5000.0f), glm::vec3(0.0f, 0.0f, 5000.0f), glm::vec4(0.0f, 0.0f, 1.0f, 1.0f));
DebugRenderer::DrawHairLine(glm::vec3(-5000.0f, 0.0f, 0.0f), glm::vec3(5000.0f, 0.0f, 0.0f), true, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
DebugRenderer::DrawHairLine(glm::vec3(0.0f, -5000.0f, 0.0f), glm::vec3(0.0f, 5000.0f, 0.0f), true, glm::vec4(0.0f, 1.0f, 0.0f, 1.0f));
DebugRenderer::DrawHairLine(glm::vec3(0.0f, 0.0f, -5000.0f), glm::vec3(0.0f, 0.0f, 5000.0f), true, glm::vec4(0.0f, 0.0f, 1.0f, 1.0f));

m_GridRenderer->OnImGui();

Expand Down Expand Up @@ -1941,11 +1943,57 @@ namespace Lumos
}
}

static float m_SceneSavePopupTimer = -1.0f;
static bool popupopen = false;

if(m_SceneSavePopupTimer > 0.0f)
{
{
ImGui::OpenPopup("Scene Save");
ImVec2 size = ImGui::GetMainViewport()->Size;
ImGui::SetNextWindowSize({ size.x * 0.65f, size.y * 0.25f });
ImGui::SetNextWindowPos({ size.x / 2.0f, size.y / 2.5f }, 0, { 0.5, 0.5 });
popupopen = true;
}
}

if(ImGui::BeginPopupModal("Scene Save", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar))
{
ArenaTemp scratch = ScratchBegin(nullptr, 0);
String8 savedText = PushStr8F(scratch.arena, "Scene Saved - %s/Assets/Scenes", m_ProjectSettings.m_ProjectRoot.c_str());
ImVec2 textSize = ImGui::CalcTextSize((const char*)savedText.str);

// Calculate the position to center the text horizontally
ImVec2 windowSize = ImGui::GetWindowSize();
float posX = (windowSize.x - textSize.x) * 0.5f;
float posY = (windowSize.y - textSize.y) * 0.5f;

// Set the cursor position to the calculated position
ImGui::SetCursorPosX(posX);
ImGui::SetCursorPosY(posY);

// Display the centered text
ImGui::TextUnformatted((const char*)savedText.str);

if(m_SceneSavePopupTimer < 0.0f)
{
popupopen = false;
ImGui::CloseCurrentPopup();
}

ScratchEnd(scratch);
ImGui::EndPopup();
}

if(m_SceneSavePopupTimer > 0.0f)
m_SceneSavePopupTimer -= Engine::GetTimeStep().GetSeconds();

if((Input::Get().GetKeyHeld(InputCode::Key::LeftSuper) || (Input::Get().GetKeyHeld(InputCode::Key::LeftControl))))
{
if(Input::Get().GetKeyPressed(InputCode::Key::S) && Application::Get().GetSceneActive())
{
Application::Get().GetSceneManager()->GetCurrentScene()->Serialise(m_ProjectSettings.m_ProjectRoot + "Assets/scenes/", false);
m_SceneSavePopupTimer = 2.0f;
}

if(Input::Get().GetKeyPressed(InputCode::Key::O))
Expand Down Expand Up @@ -2133,7 +2181,7 @@ namespace Lumos
{
Entity e = { entity, GetCurrentScene() };
{
DebugRenderer::DrawTextWsNDT(e.GetTransform().GetWorldPosition(), 20.0f, glm::vec4(1.0f), e.GetName());
DebugRenderer::DrawTextWs(e.GetTransform().GetWorldPosition(), 20.0f, false, glm::vec4(1.0f), 0.0f, e.GetName());
}
}
}
Expand Down Expand Up @@ -2360,6 +2408,8 @@ namespace Lumos
m_Panels.emplace_back(CreateSharedPtr<TextEditPanel>(physicalPath));
m_Panels.back().As<TextEditPanel>()->SetOnSaveCallback(callback);
m_Panels.back()->SetEditor(this);

ImGui::SetWindowFocus(m_Panels.back()->GetName().c_str());
}

EditorPanel* Editor::GetTextEditPanel()
Expand Down
2 changes: 2 additions & 0 deletions Editor/Source/EditorPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ namespace Lumos
bool m_Active = true;
std::string m_Name;
std::string m_SimpleName;
std::string m_ChangedName;

Editor* m_Editor = nullptr;
};
}
8 changes: 5 additions & 3 deletions Editor/Source/GameViewPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ namespace Lumos
m_SimpleName = "Game";
m_CurrentScene = nullptr;

m_Width = 1280;
m_Height = 800;
m_Width = 800;
m_Height = 600;

m_RenderPasses = CreateUniquePtr<Graphics::RenderPasses>(m_Width, m_Height);
m_RenderPasses->GetSettings().DebugPass = false;
m_RenderPasses->m_DebugRenderEnabled = false;
}

Expand Down Expand Up @@ -281,6 +280,9 @@ namespace Lumos
bool resize = false;

LUMOS_ASSERT(width > 0 && height > 0, "Game View Dimensions 0");
const QualitySettings& qs = Application::Get().GetQualitySettings();
width *= qs.RendererScale;
height *= qs.RendererScale;

if(m_Width != width || m_Height != height)
{
Expand Down
2 changes: 1 addition & 1 deletion Editor/Source/GraphicsInfoPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Lumos
{
GraphicsInfoPanel::GraphicsInfoPanel()
{
m_Name = "Graphics Info##GraphicsInfo";
m_Name = "Graphics Info###GraphicsInfo";
m_SimpleName = "Graphics Info";
}

Expand Down
4 changes: 2 additions & 2 deletions Editor/Source/InspectorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ end
{
using namespace Lumos;
LUMOS_PROFILE_FUNCTION();
ImGuiUtilities::ScopedStyle(ImGuiStyleVar_FramePadding, ImVec2(2, 2));
ImGuiUtilities::ScopedStyle frameStyle(ImGuiStyleVar_FramePadding, ImVec2(2, 2));

ImGui::Columns(2);
ImGui::Separator();
Expand Down Expand Up @@ -800,7 +800,7 @@ end
LUMOS_PROFILE_FUNCTION();
auto& camera = reg.get<Lumos::Camera>(e);

Lumos::ImGuiUtilities::ScopedStyle(ImGuiStyleVar_FramePadding, ImVec2(2, 2));
Lumos::ImGuiUtilities::ScopedStyle frameStyle(ImGuiStyleVar_FramePadding, ImVec2(2, 2));
ImGui::Columns(2);
ImGui::Separator();

Expand Down
2 changes: 1 addition & 1 deletion Editor/Source/ProjectSettingsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Lumos
ImGuiUtilities::PushID();

ImGui::Columns(2);
Lumos::ImGuiUtilities::ScopedStyle(ImGuiStyleVar_FramePadding, ImVec2(2, 2));
Lumos::ImGuiUtilities::ScopedStyle frameStyle(ImGuiStyleVar_FramePadding, ImVec2(2, 2));

{
auto& projectSettings = Application::Get().GetProjectSettings();
Expand Down
2 changes: 1 addition & 1 deletion Editor/Source/ResourcePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace Lumos
desc.minFilter = Graphics::TextureFilter::LINEAR;
desc.magFilter = Graphics::TextureFilter::LINEAR;
desc.wrap = Graphics::TextureWrap::CLAMP;

Graphics::TextureLoadOptions options;
options.flipY = true;
m_FileIcon = Graphics::Texture2D::CreateFromSource(browserFileWidth, browserFileHeight, (void*)browserFile, desc, options);
Expand Down
6 changes: 3 additions & 3 deletions Editor/Source/SceneSettingsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Lumos

if(ImGui::Begin(m_Name.c_str(), &m_Active, 0))
{
Lumos::ImGuiUtilities::ScopedStyle(ImGuiStyleVar_FramePadding, ImVec2(2, 2));
Lumos::ImGuiUtilities::ScopedStyle frameStyle(ImGuiStyleVar_FramePadding, ImVec2(2, 2));
Lumos::ImGuiUtilities::PushID();
{
const auto& sceneName = m_CurrentScene->GetSceneName();
Expand Down Expand Up @@ -133,7 +133,7 @@ namespace Lumos
ImGui::TreePop();
}

ImGui::BeginDisabled();
//ImGui::BeginDisabled();
open = postprocessSetting("SSAO", "##SSAO", sceneSettings.RenderSettings.SSAOEnabled, false);
if(open)
{
Expand All @@ -144,7 +144,7 @@ namespace Lumos
ImGui::TreePop();
}

ImGui::EndDisabled();
//ImGui::EndDisabled();
ImGui::Columns(1);
ImGui::TreePop();
}
Expand Down
10 changes: 7 additions & 3 deletions Editor/Source/SceneViewPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace Lumos
m_ShowComponentGizmoMap[typeid(Camera).hash_code()] = true;
m_ShowComponentGizmoMap[typeid(SoundComponent).hash_code()] = true;

m_Width = 1280;
m_Height = 800;
m_Width = 800;
m_Height = 600;

Application::Get().GetRenderPasses()->SetDisablePostProcess(false);
}
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace Lumos
offset = ImGui::GetCursorPos(); // Usually ImVec2(0.0f, 50.0f);
}

if(!camera)
if(!camera || !transform)
{
ImGui::End();
return;
Expand Down Expand Up @@ -586,6 +586,10 @@ namespace Lumos

LUMOS_ASSERT(width > 0 && height > 0, "Scene View Dimensions 0");

const QualitySettings& qs = Application::Get().GetQualitySettings();
width *= qs.RendererScale;
height *= qs.RendererScale;

Application::Get().SetSceneViewDimensions(width, height);

if(m_Width != width || m_Height != height)
Expand Down
44 changes: 26 additions & 18 deletions Editor/Source/TextEditPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

namespace Lumos
{
static bool JustOpenedFile = false;
TextEditPanel::TextEditPanel(const std::string& filePath)
: m_FilePath(filePath)
{
m_Name = "Text Editor###textEdit";
m_ChangedName = "Text Editor *###textEdit";
m_SimpleName = "TextEdit";
m_OnSaveCallback = NULL;
m_TextUnsaved = false;
editor.SetCustomIdentifiers({});

auto extension = StringUtilities::GetFilePathExtension(m_FilePath);
Expand Down Expand Up @@ -50,6 +53,7 @@ namespace Lumos
auto string = FileSystem::ReadTextFile(m_FilePath);
editor.SetText(string);
editor.SetShowWhitespaces(false);
JustOpenedFile = true;
}

void TextEditPanel::SetErrors(const std::map<int, std::string>& errors)
Expand All @@ -59,18 +63,10 @@ namespace Lumos

void TextEditPanel::OnImGui()
{
if((Input::Get().GetKeyHeld(InputCode::Key::LeftSuper) || (Input::Get().GetKeyHeld(InputCode::Key::LeftControl))))
{
if(Input::Get().GetKeyPressed(InputCode::Key::S))
{
auto textToSave = editor.GetText();
FileSystem::WriteTextFile(m_FilePath, textToSave);
}
}

auto cpos = editor.GetCursorPosition();
ImGui::SetWindowSize(ImVec2(800, 600), ImGuiCond_FirstUseEver);
if(ImGui::Begin(m_Name.c_str(), &m_Active, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar))
std::string& windowName = m_TextUnsaved ? m_ChangedName : m_Name;
if(ImGui::Begin(windowName.c_str(), &m_Active, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar))
{
if(ImGui::BeginMenuBar())
{
Expand All @@ -82,6 +78,8 @@ namespace Lumos
FileSystem::WriteTextFile(m_FilePath, textToSave);
if(m_OnSaveCallback)
m_OnSaveCallback();

m_TextUnsaved = false;
}
ImGui::EndMenu();
}
Expand Down Expand Up @@ -140,16 +138,26 @@ namespace Lumos

ImGui::Text("%6d/%-6d %6d lines | %s | %s | %s | %s", cpos.mLine + 1, cpos.mColumn + 1, editor.GetTotalLines(), editor.IsOverwrite() ? "Ovr" : "Ins", editor.CanUndo() ? "*" : " ", editor.GetLanguageDefinition().mName.c_str(), Lumos::StringUtilities::GetFileName(m_FilePath).c_str());

if(ImGui::IsItemActive())
{
if(Input::Get().GetKeyHeld(InputCode::Key::LeftControl) && Input::Get().GetKeyPressed(InputCode::Key::S))
{
auto textToSave = editor.GetText();
FileSystem::WriteTextFile(m_FilePath, textToSave);
}
}
if(editor.IsTextChanged() && !JustOpenedFile)
m_TextUnsaved = true;

editor.Render(m_Name.c_str());

if(ImGui::IsWindowFocused(ImGuiHoveredFlags_ChildWindows))
{
if((Input::Get().GetKeyHeld(InputCode::Key::LeftSuper) || Input::Get().GetKeyHeld(InputCode::Key::LeftControl)) &&
Input::Get().GetKeyPressed(InputCode::Key::S))
{
auto textToSave = editor.GetText();
FileSystem::WriteTextFile(m_FilePath, textToSave);
if(m_OnSaveCallback)
m_OnSaveCallback();

m_TextUnsaved = false;
}
}
JustOpenedFile = false;

}
ImGui::End();
}
Expand Down
4 changes: 4 additions & 0 deletions Editor/Source/TextEditPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ namespace Lumos
std::string m_FilePath;
TextEditor editor;
std::function<void()> m_OnSaveCallback;

bool m_TextUnsaved = false;

float m_SavedTimer = -1.0f;
};
}

0 comments on commit b911f5a

Please sign in to comment.