Basics of the meta Asset Management

This commit is contained in:
Nigel Barink 2023-06-05 17:48:11 +02:00
parent 19b630104c
commit 7349c0eb16
5 changed files with 41 additions and 34 deletions

View File

@ -3,6 +3,7 @@
#include <mini/ini.h> #include <mini/ini.h>
#include <nfd.h> #include <nfd.h>
#include <ImGuizmo.h> #include <ImGuizmo.h>
#include <memory>
#include "Inspector.h" #include "Inspector.h"
#include "Console.h" #include "Console.h"
@ -16,30 +17,27 @@ class EditorLayer : public Layer {
public: public:
EditorLayer() : EditorLayer() : Layer()
Layer(),
inspector(Selected),
scene(),
renderer()
{ {
Logo.Load("rsc/Yoggie.png"); Logo.Load("rsc/Yoggie.png");
spdlog::info("{0}", project.GetProjectDirectory().string()); Selected = YoggieEngine::Entity{ (entt::entity)-1, (scene.get()) };
Selected = YoggieEngine::Entity((entt::entity)-1, &scene);
} }
void OnStartup() override { void OnStartup() override {
std::string path = (std::filesystem::current_path()).string(); std::string path = (std::filesystem::current_path()).string();
project.setProjectDirectory(path); scene = std::make_unique<Scene>();
project = std::make_unique<Project>();
project.get()->setProjectDirectory(path);
LoadLastOrEmptyProject(); LoadLastOrEmptyProject();
//Console console = Console(); //Console console = Console();
} }
void OnUpdate() override { void OnUpdate() override {
scene.Update(); scene.get()->Update();
renderer.Render(scene, *camera); renderer.get()->Render(*scene, *camera);
} }
@ -282,7 +280,7 @@ public:
ImGui::Begin("SceneView",nullptr,viewportWindowFlags); ImGui::Begin("SceneView",nullptr,viewportWindowFlags);
// spdlog::info("{0}x{1}", ImGui::GetWindowWidth(), ImGui::GetWindowHeight()); // spdlog::info("{0}x{1}", ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
SceneisFocused = ImGui::IsWindowFocused() || ImGui::IsWindowHovered(); 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()}); ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()});
@ -331,11 +329,11 @@ public:
ImGui::Begin(ICON_MD_MENU "SceneExplorer",nullptr); ImGui::Begin(ICON_MD_MENU "SceneExplorer",nullptr);
scene.getReg().each([&](entt::entity enttNumber) { scene.get()->getReg().each([&](entt::entity enttNumber) {
YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &scene); YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &*scene.get());
auto id = entity.GetComponent<YoggieEngine::IdentifierComponent>(); auto id = entity.GetComponent<YoggieEngine::IdentifierComponent>();
if (ImGui::Selectable(id.name.c_str(), entity == Selected)) { 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::End();
/*
{ {
ImGui::Begin("Asset", nullptr); ImGui::Begin("Asset", nullptr);
@ -364,7 +362,7 @@ public:
YoggieEngine::Texture folderIcon; YoggieEngine::Texture folderIcon;
YoggieEngine::Texture assetIcon; YoggieEngine::Texture assetIcon;
assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png"); //assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png");
ImGui::DragInt("IconSize", &iconSize, 1, 30, 90); ImGui::DragInt("IconSize", &iconSize, 1, 30, 90);
@ -389,7 +387,7 @@ public:
ImGui::ImageButton( ImGui::ImageButton(
(ImTextureID)assetIcon.GetID(), (ImTextureID)assetIcon.GetID(),
ImVec2{ (float)iconSize, (float)iconSize }); 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::End();
} }
*/
ImGui::ShowDemoWindow(); ImGui::ShowDemoWindow();
@ -467,15 +465,15 @@ public:
private: private:
Inspector inspector; std::unique_ptr<Inspector> inspector = std::make_unique<Inspector>(Selected);
Renderer renderer; std::unique_ptr<Renderer> renderer = std::make_unique<Renderer>();
std::unique_ptr<EditorCamera> camera = std::make_unique<EditorCamera>();
std::unique_ptr<Project> project;
std::unique_ptr<Scene> scene;
EditorCamera* camera = new EditorCamera(); Texture Logo;
Project project;
Scene scene;
bool SimulatePhysics = true; bool SimulatePhysics = true;
bool SceneisFocused = false; bool SceneisFocused = false;
@ -483,7 +481,6 @@ private:
ImGuizmo::OPERATION activeOperation = ImGuizmo::OPERATION::TRANSLATE; ImGuizmo::OPERATION activeOperation = ImGuizmo::OPERATION::TRANSLATE;
char* path = nullptr; char* path = nullptr;
Texture Logo;
void LoadLastOrEmptyProject() { void LoadLastOrEmptyProject() {
// Check if there is a last known loaded project and // Check if there is a last known loaded project and
@ -507,7 +504,7 @@ private:
if (ini["editor"]["openlastproject"] == "TRUE") if (ini["editor"]["openlastproject"] == "TRUE")
{ {
Project::LoadProject(ini["cache"]["project"], project); Project::LoadProject(ini["cache"]["project"], *project);
///LoadScene(ini["cache"]["scene"], scene); ///LoadScene(ini["cache"]["scene"], scene);
} }

View File

@ -4,6 +4,7 @@
typedef uuid::v4::UUID AssetHandle; typedef uuid::v4::UUID AssetHandle;
enum class AssetType { enum class AssetType {
Unknown = -1, Unknown = -1,
Mesh, Mesh,
@ -13,9 +14,9 @@ enum class AssetType {
}; };
struct Asset { struct Asset {
//AssetHandle Handle; AssetHandle Handle;
//template<class T > template<class T >
//static AssetType GetType(T t) { return t.GetType(); } static AssetType GetType(T t) { return t.GetType(); }
virtual AssetType GetType() { return AssetType::Unknown; } virtual AssetType GetType() { return AssetType::Unknown; }
}; };

View File

@ -9,8 +9,8 @@ public:
virtual Asset& GetAsset(AssetHandle handle) = 0; virtual Asset& GetAsset(AssetHandle handle) = 0;
protected: protected:
//AssetRegistry Assets; AssetRegistry Assets;
//std::map<AssetHandle, Asset> LoadedAssets; std::map<AssetHandle, Asset> LoadedAssets;
}; };

View File

@ -14,7 +14,7 @@ Asset& AssetManagerEditor::GetAsset(AssetHandle handle)
// 2. check if asset needs loading // 2. check if asset needs loading
Asset asset; Asset asset;
if (IsAssetLoaded(handle)) { if (IsAssetLoaded(handle)) {
// asset = LoadedAssets.at(handle); asset = LoadedAssets.at(handle);
} }
else { else {
// Load asset // Load asset
@ -33,9 +33,9 @@ Asset& AssetManagerEditor::GetAsset(AssetHandle handle)
bool AssetManagerEditor::IsAssetHandleValid(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 ) { bool AssetManagerEditor::IsAssetLoaded(AssetHandle handle ) {
return false;//return LoadedAssets.find(handle) != LoadedAssets.end(); return LoadedAssets.find(handle) != LoadedAssets.end();
} }

View File

@ -17,6 +17,15 @@ namespace uuid::v4
{ {
public: public:
UUID() {} 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. // method for creating UUID object.
void generate () void generate ()