aboutsummaryrefslogtreecommitdiff
path: root/resource-manager/resource_manager.h
diff options
context:
space:
mode:
Diffstat (limited to 'resource-manager/resource_manager.h')
-rw-r--r--resource-manager/resource_manager.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/resource-manager/resource_manager.h b/resource-manager/resource_manager.h
index 7a86360..fd6657c 100644
--- a/resource-manager/resource_manager.h
+++ b/resource-manager/resource_manager.h
@@ -2,12 +2,14 @@
+#include <algorithm>
#include <string>
#include <unordered_map>
#include "resource.h"
#include "constants.h"
+#include "resource_fabricator.h"
using namespace crepe;
@@ -20,9 +22,21 @@ public:
ResourceManager();
~ResourceManager();
- Resource* Load(const Constants::FILE_PATH& file_path);
- void Unload(const Constants::FILE_PATH& file_path);
+ template<typename T>
+ T* Load(const Constants::FILE_PATH& file_path){
+
+ if (m_resources.find(file_path) != m_resources.end()) {
+ return static_cast<T*>(m_resources[file_path]);
+ }
+
+ Resource* resource = ResourceFactory::create_resource(file_path);
+ if (resource) {
+ m_resources[file_path] = std::move(resource);
+ }
+ return static_cast<T*>(m_resources[file_path]);
+ }
+ void Unload(const Constants::FILE_PATH& file_path);
private:
std::unordered_map<Constants::FILE_PATH, Resource*> m_resources;