From 9037aca03bfa4312794a6954752628381256f777 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 22 Oct 2024 12:15:03 +0200 Subject: merged further and changed to standard --- src/crepe/api/AssetManager.h | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/crepe/api/AssetManager.h (limited to 'src/crepe/api/AssetManager.h') diff --git a/src/crepe/api/AssetManager.h b/src/crepe/api/AssetManager.h new file mode 100644 index 0000000..a646d95 --- /dev/null +++ b/src/crepe/api/AssetManager.h @@ -0,0 +1,57 @@ +#pragma once + + + +#include +#include +#include +#include + +#include "api/baseResource.h" + + +namespace crepe::api{ + +class ResourceManager{ + + +private: + + std::unordered_map< std::string, std::unique_ptr> m_resources; + + +protected: + ResourceManager() = default; + ~ResourceManager(); + +public: + ResourceManager(const ResourceManager &) = delete; + ResourceManager(ResourceManager &&) = delete; + ResourceManager &operator=(const ResourceManager &) = delete; + ResourceManager &operator=(ResourceManager &&) = delete; + + static ResourceManager& get_instance(); + + + +public: + template + T* Load(const std::string& file_path){ + + if (m_resources.find(file_path) != m_resources.end()) { + return static_cast(m_resources[file_path].get()); + } + + auto resource = std::make_unique(file_path.c_str()); + if (resource) { + m_resources[file_path] = std::move(resource); + return static_cast(m_resources[file_path].get() ); + } + + return nullptr; + } + + void Unload(const std::string& file_path); + +}; +} -- cgit v1.2.3