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 <nfd.h>
#include <ImGuizmo.h>
#include <memory>
#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<Scene>();
project = std::make_unique<Project>();
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<YoggieEngine::IdentifierComponent>();
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> inspector = std::make_unique<Inspector>(Selected);
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 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);
}

View File

@ -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<class T >
//static AssetType GetType(T t) { return t.GetType(); }
template<class T >
static AssetType GetType(T t) { return t.GetType(); }
virtual AssetType GetType() { return AssetType::Unknown; }
};

View File

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

View File

@ -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();
}

View File

@ -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 ()