Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
String class, compile time improvements
  • Loading branch information
jmorton06 committed Oct 7, 2023
1 parent 994e2ae commit f039c3d
Show file tree
Hide file tree
Showing 210 changed files with 5,671 additions and 3,362 deletions.
2 changes: 2 additions & 0 deletions Editor/Source/ApplicationInfoPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Lumos/Scene/Scene.h>

#include <Lumos/Core/Engine.h>
#include <Lumos/Core/OS/Window.h>
#include <Lumos/Graphics/Renderers/RenderPasses.h>
#include <Lumos/ImGui/ImGuiUtilities.h>
#include <imgui/imgui.h>
Expand Down Expand Up @@ -135,6 +136,7 @@ namespace Lumos
ImGui::Text("FPS : %5.2i", Engine::Get().Statistics().FramesPerSecond);
ImGui::Text("UPS : %5.2i", Engine::Get().Statistics().UpdatesPerSecond);
ImGui::Text("Frame Time : %5.2f ms", Engine::Get().Statistics().FrameTime);
ImGui::Text("Arena Count : %i", GetArenaCount());
ImGui::NewLine();
ImGui::Text("Scene : %s", Application::Get().GetSceneManager()->GetCurrentScene()->GetSceneName().c_str());
ImGui::TreePop();
Expand Down
39 changes: 28 additions & 11 deletions Editor/Source/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <Lumos/Core/OS/OS.h>
#include <Lumos/Core/Version.h>
#include <Lumos/Core/Engine.h>
#include <Lumos/Core/OS/Window.h>
#include <Lumos/Audio/AudioManager.h>
#include <Lumos/Scene/Scene.h>
#include <Lumos/Scene/SceneManager.h>
Expand Down Expand Up @@ -54,6 +55,7 @@
#include <Lumos/Maths/Plane.h>
#include <Lumos/Maths/MathsUtilities.h>
#include <Lumos/Core/LMLog.h>
#include <Lumos/Core/String.h>

#include <spdlog/spdlog.h>
#include <spdlog/fmt/ostr.h>
Expand All @@ -63,6 +65,14 @@
#include <glm/gtx/matrix_decompose.hpp>
#include <cereal/version.hpp>

#include <ozz/animation/runtime/animation.h>
#include <ozz/animation/runtime/sampling_job.h>
#include <ozz/animation/runtime/skeleton.h>
#include <ozz/base/containers/vector.h>
#include <ozz/base/maths/soa_transform.h>
#include <ozz/base/memory/unique_ptr.h>
#include <ozz/animation/offline/raw_skeleton.h>

namespace Lumos
{
Editor* Editor::s_Editor = nullptr;
Expand All @@ -71,9 +81,11 @@ namespace Lumos
: Application()
, m_IniFile("")
{
#if LUMOS_ENABLE_LOG
spdlog::sink_ptr sink = std::make_shared<ImGuiConsoleSink_mt>();

Lumos::Debug::Log::AddSink(sink);
#endif

// Remove?
s_Editor = this;
Expand Down Expand Up @@ -700,7 +712,7 @@ namespace Lumos
{
auto scenes = Application::Get().GetSceneManager()->GetSceneNames();

for(size_t i = 0; i < scenes.size(); i++)
for(size_t i = 0; i < scenes.Size(); i++)
{
auto name = scenes[i];
if(ImGui::MenuItem(name.c_str()))
Expand Down Expand Up @@ -780,7 +792,7 @@ namespace Lumos
if(ImGui::MenuItem("Embed Shaders"))
{
std::string coreDataPath;
VFS::Get().ResolvePhysicalPath("//CoreShaders", coreDataPath, true);
FileSystem::Get().ResolvePhysicalPath("//CoreShaders", coreDataPath, true);
auto shaderPath = std::filesystem::path(coreDataPath + "/CompiledSPV/");
int shaderCount = 0;
if(std::filesystem::is_directory(shaderPath))
Expand Down Expand Up @@ -871,14 +883,18 @@ namespace Lumos
ImGui::SameLine();
ImGui::TextUnformatted(m_ProjectSettings.m_ProjectName.c_str());

ImGuiUtilities::Tooltip(("Current project (" + m_ProjectSettings.m_ProjectName + ".lmproj)").c_str());
String8 projectString = PushStr8F(GetFrameArena(), "Current project ( %s.lmproj )", m_ProjectSettings.m_ProjectName.c_str());

ImGuiUtilities::Tooltip((const char*)projectString.str);
ImGuiUtilities::DrawBorder(ImGuiUtilities::RectExpanded(ImGuiUtilities::GetItemRect(), 24.0f, 68.0f), 1.0f, 3.0f, 0.0f, -60.0f);

ImGui::SameLine();
ImGui::Separator();
ImGui::SameLine(ImGui::GetCursorPosX() + 32.0f);
ImGui::TextUnformatted(GetCurrentScene()->GetSceneName().c_str());
ImGuiUtilities::Tooltip(("Current Scene (" + GetCurrentScene()->GetSceneName() + ".lsn)").c_str());
String8 sceneString = PushStr8F(GetFrameArena(), "Current Scene ( %s.lsn )", GetCurrentScene()->GetSceneName().c_str());

ImGuiUtilities::Tooltip((const char*)sceneString.str);
ImGuiUtilities::DrawBorder(ImGuiUtilities::RectExpanded(ImGuiUtilities::GetItemRect(), 24.0f, 68.0f), 1.0f, 3.0f, 0.0f, -60.0f);
}

Expand Down Expand Up @@ -1145,7 +1161,7 @@ namespace Lumos
int sameNameCount = 0;
auto sceneNames = m_SceneManager->GetSceneNames();

while(FileSystem::FileExists("//Scenes/" + sceneName + ".lsn") || std::find(sceneNames.begin(), sceneNames.end(), sceneName) != sceneNames.end())
while(FileSystem::FileExists("//Assets/Scenes/" + sceneName + ".lsn") || m_SceneManager->ContainsScene(sceneName))
{
sameNameCount++;
sceneName = fmt::format(newSceneName + "{0}", sameNameCount);
Expand Down Expand Up @@ -1175,7 +1191,7 @@ namespace Lumos
scene->Serialise(m_ProjectSettings.m_ProjectRoot + "Assets/Scenes/");
}
Application::Get().GetSceneManager()->EnqueueScene(scene);
Application::Get().GetSceneManager()->SwitchScene((int)(Application::Get().GetSceneManager()->GetScenes().size()) - 1);
Application::Get().GetSceneManager()->SwitchScene((int)(Application::Get().GetSceneManager()->GetScenes().Size()) - 1);

ImGui::CloseCurrentPopup();
}
Expand Down Expand Up @@ -1685,9 +1701,9 @@ namespace Lumos
#ifdef LUMOS_PLATFORM_WINDOWS
Platform = "Windows";
#elif LUMOS_PLATFORM_LINUX
Platform = "Linux";
Platform = "Linux";
#elif LUMOS_PLATFORM_MACOS
Platform = "MacOS";
Platform = "MacOS";
#elif LUMOS_PLATFORM_IOS
Platform = "iOS";
#endif
Expand Down Expand Up @@ -2394,7 +2410,7 @@ namespace Lumos
{
LUMOS_PROFILE_FUNCTION();
std::string physicalPath;
if(!VFS::Get().ResolvePhysicalPath(filePath, physicalPath))
if(!FileSystem::Get().ResolvePhysicalPath(filePath, physicalPath))
{
LUMOS_LOG_ERROR("Failed to Load Lua script {0}", filePath);
return;
Expand Down Expand Up @@ -2533,7 +2549,7 @@ namespace Lumos
else if(IsAudioFile(path))
{
std::string physicalPath;
Lumos::VFS::Get().ResolvePhysicalPath(path, physicalPath);
Lumos::FileSystem::Get().ResolvePhysicalPath(path, physicalPath);
auto sound = Sound::Create(physicalPath, StringUtilities::GetFilePathExtension(path));

auto soundNode = SharedPtr<SoundNode>(SoundNode::Create());
Expand Down Expand Up @@ -2656,6 +2672,7 @@ namespace Lumos
void Editor::AddDefaultEditorSettings()
{
LUMOS_PROFILE_FUNCTION();
LUMOS_LOG_INFO("Setting default editor settings");
m_ProjectSettings.m_ProjectRoot = "../../ExampleProject/";
m_ProjectSettings.m_ProjectName = "Example";

Expand Down Expand Up @@ -2786,7 +2803,7 @@ namespace Lumos
else
{
std::string physicalPath;
if(Lumos::VFS::Get().ResolvePhysicalPath("//Scenes/" + Application::Get().GetCurrentScene()->GetSceneName() + ".lsn", physicalPath))
if(Lumos::FileSystem::Get().ResolvePhysicalPath("//Assets/Scenes/" + Application::Get().GetCurrentScene()->GetSceneName() + ".lsn", physicalPath))
{
auto newPath = StringUtilities::RemoveName(physicalPath);
Application::Get().GetCurrentScene()->Deserialise(newPath, false);
Expand Down
59 changes: 36 additions & 23 deletions Editor/Source/HierarchyPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <Lumos/Scripting/Lua/LuaScriptComponent.h>
#include <Lumos/ImGui/IconsMaterialDesignIcons.h>
#include <Lumos/Core/StringUtilities.h>
#include <Lumos/Core/String.h>

#include <typeinfo>
#include <imgui/imgui_internal.h>
Expand All @@ -28,13 +29,19 @@ namespace Lumos
: m_HadRecentDroppedEntity(entt::null)
, m_DoubleClicked(entt::null)
{
m_Name = "Hierarchy###hierarchy";
m_SimpleName = "Hierarchy";
m_Name = "Hierarchy###hierarchy";
m_SimpleName = "Hierarchy";
m_StringArena = ArenaAlloc(Megabytes(1));
}

HierarchyPanel::~HierarchyPanel()
{
ArenaRelease(m_StringArena);
}

void HierarchyPanel::DrawNode(entt::entity node, entt::registry& registry)
{
LUMOS_PROFILE_FUNCTION();
LUMOS_PROFILE_FUNCTION_LOW();
bool show = true;

if(!registry.valid(node))
Expand All @@ -44,11 +51,11 @@ namespace Lumos

static const char* defaultName = "Entity";
const NameComponent* nameComponent = registry.try_get<NameComponent>(node);
const char* name = nameComponent ? nameComponent->name.c_str() : defaultName; // StringUtilities::ToString(entt::to_integral(node));
String8 name = PushStr8Copy(m_StringArena, nameComponent ? nameComponent->name.c_str() : defaultName); // StringUtilities::ToString(entt::to_integral(node));

if(m_HierarchyFilter.IsActive())
{
if(!m_HierarchyFilter.PassFilter(name))
if(!m_HierarchyFilter.PassFilter((const char*)name.str))
{
show = false;
}
Expand Down Expand Up @@ -93,53 +100,53 @@ namespace Lumos
m_HadRecentDroppedEntity = entt::null;
}

std::string icon = ICON_MDI_CUBE_OUTLINE;
auto& iconMap = m_Editor->GetComponentIconMap();
String8 icon = Str8C((char*)ICON_MDI_CUBE_OUTLINE);
auto& iconMap = m_Editor->GetComponentIconMap();

if(registry.all_of<Camera>(node))
{
if(iconMap.find(typeid(Camera).hash_code()) != iconMap.end())
icon = iconMap[typeid(Camera).hash_code()];
icon = Str8C((char*)iconMap[typeid(Camera).hash_code()]);
}
if(registry.all_of<LuaScriptComponent>(node))
{
if(iconMap.find(typeid(LuaScriptComponent).hash_code()) != iconMap.end())
icon = iconMap[typeid(LuaScriptComponent).hash_code()];
icon = Str8C((char*)iconMap[typeid(LuaScriptComponent).hash_code()]);
}
else if(registry.all_of<SoundComponent>(node))
{
if(iconMap.find(typeid(SoundComponent).hash_code()) != iconMap.end())
icon = iconMap[typeid(SoundComponent).hash_code()];
icon = Str8C((char*)iconMap[typeid(SoundComponent).hash_code()]);
}
else if(registry.all_of<RigidBody2DComponent>(node))
{
if(iconMap.find(typeid(RigidBody2DComponent).hash_code()) != iconMap.end())
icon = iconMap[typeid(RigidBody2DComponent).hash_code()];
icon = Str8C((char*)iconMap[typeid(RigidBody2DComponent).hash_code()]);
}
else if(registry.all_of<Graphics::Light>(node))
{
if(iconMap.find(typeid(Graphics::Light).hash_code()) != iconMap.end())
icon = iconMap[typeid(Graphics::Light).hash_code()];
icon = Str8C((char*)iconMap[typeid(Graphics::Light).hash_code()]);
}
else if(registry.all_of<Graphics::Environment>(node))
{
if(iconMap.find(typeid(Graphics::Environment).hash_code()) != iconMap.end())
icon = iconMap[typeid(Graphics::Environment).hash_code()];
icon = Str8C((char*)iconMap[typeid(Graphics::Environment).hash_code()]);
}
else if(registry.all_of<Graphics::Sprite>(node))
{
if(iconMap.find(typeid(Graphics::Sprite).hash_code()) != iconMap.end())
icon = iconMap[typeid(Graphics::Sprite).hash_code()];
icon = Str8C((char*)iconMap[typeid(Graphics::Sprite).hash_code()]);
}
else if(registry.all_of<TextComponent>(node))
{
if(iconMap.find(typeid(TextComponent).hash_code()) != iconMap.end())
icon = iconMap[typeid(TextComponent).hash_code()];
icon = Str8C((char*)iconMap[typeid(TextComponent).hash_code()]);
}

ImGui::PushStyleColor(ImGuiCol_Text, ImGuiUtilities::GetIconColour());
// ImGui::BeginGroup();
bool nodeOpen = ImGui::TreeNodeEx((void*)(intptr_t)entt::to_integral(node), nodeFlags, "%s", icon.c_str());
bool nodeOpen = ImGui::TreeNodeEx((void*)(intptr_t)entt::to_integral(node), nodeFlags, "%s", (const char*)icon.str);
{
// Allow clicking of icon and text. Need twice as they are separated
if(ImGui::IsItemClicked(ImGuiMouseButton_Left) && !ImGui::IsItemToggledOpen())
Expand Down Expand Up @@ -182,27 +189,31 @@ namespace Lumos

if(isPrefab)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_CheckMark));
ImGui::TextUnformatted(name);
ImGui::TextUnformatted((const char*)name.str);
if(isPrefab)
ImGui::PopStyleColor();
}
// ImGui::EndGroup();

if(doubleClicked)
{
static char objName[INPUT_BUF_SIZE];
strcpy(objName, name);
String8 nameBuffer = { 0 };
nameBuffer.str = PushArray(m_StringArena, uint8_t, INPUT_BUF_SIZE);
nameBuffer.size = INPUT_BUF_SIZE;

MemoryCopy(nameBuffer.str, name.str, name.size);

ImGui::PushItemWidth(-1);
if(ImGui::InputText("##Name", objName, IM_ARRAYSIZE(objName), 0))
registry.get_or_emplace<NameComponent>(node).name = objName;
if(ImGui::InputText("##Name", (char*)nameBuffer.str, INPUT_BUF_SIZE, 0))
registry.get_or_emplace<NameComponent>(node).name = (const char*)nameBuffer.str;
ImGui::PopStyleVar();
}

if(!active)
ImGui::PopStyleColor();

bool deleteEntity = false;
if(ImGui::BeginPopupContextItem(name))
if(ImGui::BeginPopupContextItem((const char*)name.str))
{
if(ImGui::Selectable("Copy"))
{
Expand Down Expand Up @@ -497,7 +508,9 @@ namespace Lumos
m_SelectUp = Input::Get().GetKeyPressed(Lumos::InputCode::Key::Up);
m_SelectDown = Input::Get().GetKeyPressed(Lumos::InputCode::Key::Down);

ImGui::Begin(m_Name.c_str(), &m_Active, flags);
ArenaClear(m_StringArena);

if(ImGui::Begin(m_Name.c_str(), &m_Active, flags))
{
auto scene = Application::Get().GetSceneManager()->GetCurrentScene();

Expand Down
6 changes: 4 additions & 2 deletions Editor/Source/HierarchyPanel.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "EditorPanel.h"

#include "Core/OS/Memory.h"
#include <entt/entity/fwd.hpp>
#include <imgui/imgui.h>

Expand All @@ -11,7 +11,7 @@ namespace Lumos
{
public:
HierarchyPanel();
~HierarchyPanel() = default;
~HierarchyPanel();

void DrawNode(entt::entity node, entt::registry& registry);
void OnImGui() override;
Expand All @@ -26,5 +26,7 @@ namespace Lumos
entt::entity m_CurrentPrevious;
bool m_SelectUp;
bool m_SelectDown;

Arena* m_StringArena;
};
}
14 changes: 8 additions & 6 deletions Editor/Source/InspectorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

#include <sol/sol.hpp>
#include <inttypes.h>
#include <spdlog/fmt/bundled/format.h>
#include <ozz/animation/runtime/skeleton.h>

namespace MM
{
Expand Down Expand Up @@ -78,9 +80,9 @@ namespace MM

if(ImGui::Button("New File", ImVec2(ImGui::GetContentRegionAvail().x, 0.0f)))
{
std::string newFilePath = "//Scripts";
std::string newFilePath = "//Assets/Scripts";
std::string physicalPath;
if(!Lumos::VFS::Get().ResolvePhysicalPath(newFilePath, physicalPath, true))
if(!Lumos::FileSystem::Get().ResolvePhysicalPath(newFilePath, physicalPath, true))
{
LUMOS_LOG_ERROR("Failed to Create Lua script {0}", physicalPath);
}
Expand Down Expand Up @@ -740,7 +742,7 @@ end
if(ImGui::AcceptDragDropPayload("AssetFile"))
{
std::string physicalPath;
Lumos::VFS::Get().ResolvePhysicalPath(filePath, physicalPath);
Lumos::FileSystem::Get().ResolvePhysicalPath(filePath, physicalPath);
auto newSound = Lumos::Sound::Create(physicalPath, Lumos::StringUtilities::GetFilePathExtension(filePath));

soundNode->SetSound(newSound);
Expand Down Expand Up @@ -2000,9 +2002,9 @@ end
ImGui::Indent();
if(ImGui::Button("Save to file"))
{
std::string filePath = "//Meshes"; // Materials/" + matName + ".lmat";
std::string filePath = "//Assets/Meshes"; // Materials/" + matName + ".lmat";
std::string physicalPath;
if(VFS::Get().ResolvePhysicalPath(filePath, physicalPath))
if(FileSystem::Get().ResolvePhysicalPath(filePath, physicalPath))
{
physicalPath += "/Materials/" + matName + ".lmat";
std::stringstream storage;
Expand Down Expand Up @@ -2501,7 +2503,7 @@ namespace Lumos
if(ImGui::Button("OK", ImVec2(120, 0)))
{
std::string physicalPath;
VFS::Get().ResolvePhysicalPath(prefabNamePath, physicalPath, true);
FileSystem::Get().ResolvePhysicalPath(prefabNamePath, physicalPath, true);
std::string FullPath = physicalPath + prefabName + std::string(".lprefab");
Application::Get().GetSceneManager()->GetCurrentScene()->SavePrefab({ selected, Application::Get().GetSceneManager()->GetCurrentScene() }, FullPath);
ImGui::CloseCurrentPopup();
Expand Down
Loading

0 comments on commit f039c3d

Please sign in to comment.