From 7349c0eb16215a71aa140160cb547ec709a013b9 Mon Sep 17 00:00:00 2001 From: Nigel Barink Date: Mon, 5 Jun 2023 17:48:11 +0200 Subject: [PATCH] Basics of the meta Asset Management --- Editor/src/EditorLayer.h | 49 +++++++++---------- YoggieEngine/src/Assets/Asset.h | 7 +-- YoggieEngine/src/Assets/AssetManager.h | 4 +- .../src/Assets/AssetManagerEditor.cpp | 6 +-- YoggieEngine/src/Assets/uuid.h | 9 ++++ 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/Editor/src/EditorLayer.h b/Editor/src/EditorLayer.h index a470edf..5f09a37 100644 --- a/Editor/src/EditorLayer.h +++ b/Editor/src/EditorLayer.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "Inspector.h" #include "Console.h" @@ -16,30 +17,27 @@ class EditorLayer : public Layer { public: - EditorLayer() : - Layer(), - inspector(Selected), - scene(), - renderer() + EditorLayer() : Layer() { Logo.Load("rsc/Yoggie.png"); - spdlog::info("{0}", project.GetProjectDirectory().string()); - Selected = YoggieEngine::Entity((entt::entity)-1, &scene); + Selected = YoggieEngine::Entity{ (entt::entity)-1, (scene.get()) }; } void OnStartup() override { std::string path = (std::filesystem::current_path()).string(); - project.setProjectDirectory(path); + scene = std::make_unique(); + project = std::make_unique(); + project.get()->setProjectDirectory(path); LoadLastOrEmptyProject(); //Console console = Console(); } void OnUpdate() override { - scene.Update(); - renderer.Render(scene, *camera); + scene.get()->Update(); + renderer.get()->Render(*scene, *camera); } @@ -282,7 +280,7 @@ public: ImGui::Begin("SceneView",nullptr,viewportWindowFlags); // spdlog::info("{0}x{1}", ImGui::GetWindowWidth(), ImGui::GetWindowHeight()); SceneisFocused = ImGui::IsWindowFocused() || ImGui::IsWindowHovered(); - ImGui::Image((ImTextureID)(intptr_t)renderer.getCurrentFrameBuffer().GetColourAttachment(), + ImGui::Image((ImTextureID)(intptr_t)renderer.get()->getCurrentFrameBuffer().GetColourAttachment(), ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()}); @@ -331,11 +329,11 @@ public: ImGui::Begin(ICON_MD_MENU "SceneExplorer",nullptr); - scene.getReg().each([&](entt::entity enttNumber) { - YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &scene); + scene.get()->getReg().each([&](entt::entity enttNumber) { + YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &*scene.get()); auto id = entity.GetComponent(); if (ImGui::Selectable(id.name.c_str(), entity == Selected)) { - Selected = YoggieEngine::Entity(enttNumber, &scene); + Selected = YoggieEngine::Entity(enttNumber, &*scene); } }); @@ -343,7 +341,7 @@ public: ImGui::End(); - /* + { ImGui::Begin("Asset", nullptr); @@ -364,7 +362,7 @@ public: YoggieEngine::Texture folderIcon; YoggieEngine::Texture assetIcon; - assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png"); + //assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png"); ImGui::DragInt("IconSize", &iconSize, 1, 30, 90); @@ -389,7 +387,7 @@ public: ImGui::ImageButton( (ImTextureID)assetIcon.GetID(), ImVec2{ (float)iconSize, (float)iconSize }); - ImGui::Text(asset.GetName(), row); + ImGui::Text(asset.Handle.String().c_str(), row); @@ -408,7 +406,7 @@ public: ImGui::End(); } - */ + ImGui::ShowDemoWindow(); @@ -467,15 +465,15 @@ public: private: - Inspector inspector; - Renderer renderer; + std::unique_ptr inspector = std::make_unique(Selected); + std::unique_ptr renderer = std::make_unique(); + std::unique_ptr camera = std::make_unique(); + std::unique_ptr project; + std::unique_ptr scene; - EditorCamera* camera = new EditorCamera(); + Texture Logo; - Project project; - Scene scene; - bool SimulatePhysics = true; bool SceneisFocused = false; @@ -483,7 +481,6 @@ private: ImGuizmo::OPERATION activeOperation = ImGuizmo::OPERATION::TRANSLATE; char* path = nullptr; - Texture Logo; void LoadLastOrEmptyProject() { // Check if there is a last known loaded project and @@ -507,7 +504,7 @@ private: if (ini["editor"]["openlastproject"] == "TRUE") { - Project::LoadProject(ini["cache"]["project"], project); + Project::LoadProject(ini["cache"]["project"], *project); ///LoadScene(ini["cache"]["scene"], scene); } diff --git a/YoggieEngine/src/Assets/Asset.h b/YoggieEngine/src/Assets/Asset.h index 9d5bc5f..1cb8308 100644 --- a/YoggieEngine/src/Assets/Asset.h +++ b/YoggieEngine/src/Assets/Asset.h @@ -4,6 +4,7 @@ typedef uuid::v4::UUID AssetHandle; + enum class AssetType { Unknown = -1, Mesh, @@ -13,9 +14,9 @@ enum class AssetType { }; struct Asset { - //AssetHandle Handle; + AssetHandle Handle; - //template - //static AssetType GetType(T t) { return t.GetType(); } + template + static AssetType GetType(T t) { return t.GetType(); } virtual AssetType GetType() { return AssetType::Unknown; } }; diff --git a/YoggieEngine/src/Assets/AssetManager.h b/YoggieEngine/src/Assets/AssetManager.h index 4162b22..0c64f46 100644 --- a/YoggieEngine/src/Assets/AssetManager.h +++ b/YoggieEngine/src/Assets/AssetManager.h @@ -9,8 +9,8 @@ public: virtual Asset& GetAsset(AssetHandle handle) = 0; protected: - //AssetRegistry Assets; - //std::map LoadedAssets; + AssetRegistry Assets; + std::map LoadedAssets; }; \ No newline at end of file diff --git a/YoggieEngine/src/Assets/AssetManagerEditor.cpp b/YoggieEngine/src/Assets/AssetManagerEditor.cpp index a3f33ec..bdc808b 100644 --- a/YoggieEngine/src/Assets/AssetManagerEditor.cpp +++ b/YoggieEngine/src/Assets/AssetManagerEditor.cpp @@ -14,7 +14,7 @@ Asset& AssetManagerEditor::GetAsset(AssetHandle handle) // 2. check if asset needs loading Asset asset; if (IsAssetLoaded(handle)) { - // asset = LoadedAssets.at(handle); + asset = LoadedAssets.at(handle); } else { // Load asset @@ -33,9 +33,9 @@ Asset& AssetManagerEditor::GetAsset(AssetHandle handle) bool AssetManagerEditor::IsAssetHandleValid(AssetHandle handle) { - return false;///return Assets.find(handle) != Assets.end(); + return Assets.find(handle) != Assets.end(); } bool AssetManagerEditor::IsAssetLoaded(AssetHandle handle ) { - return false;//return LoadedAssets.find(handle) != LoadedAssets.end(); + return LoadedAssets.find(handle) != LoadedAssets.end(); } \ No newline at end of file diff --git a/YoggieEngine/src/Assets/uuid.h b/YoggieEngine/src/Assets/uuid.h index b9dd316..5b2f981 100644 --- a/YoggieEngine/src/Assets/uuid.h +++ b/YoggieEngine/src/Assets/uuid.h @@ -17,6 +17,15 @@ namespace uuid::v4 { public: UUID() {} + // I need a better UUID class that will work as a key in std::map + // because this won't properly work + + bool operator() (const UUID& lhs, const UUID& rhs) const { + return 1==1; + } + bool operator< (const UUID& rhs)const { + return false; + } // method for creating UUID object. void generate ()