diff options
Diffstat (limited to 'resource-manager')
-rw-r--r-- | resource-manager/main.cpp | 6 | ||||
-rw-r--r-- | resource-manager/resource_manager.cpp | 11 | ||||
-rw-r--r-- | resource-manager/resource_manager.h | 24 |
3 files changed, 33 insertions, 8 deletions
diff --git a/resource-manager/main.cpp b/resource-manager/main.cpp index 6b3a23e..0148555 100644 --- a/resource-manager/main.cpp +++ b/resource-manager/main.cpp @@ -15,8 +15,6 @@ #include <SDL_timer.h> #include <SDL_video.h> #include <cstddef> -#include <iostream> -#include <ostream> int main() { SDL_Init(SDL_INIT_VIDEO); @@ -32,8 +30,8 @@ int main() { SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0); - - ResourceManager * rm = new ResourceManager(); + + ResourceManager* rm = ResourceManager::get_instance(); ResourceConverter resource_converter; Texture* img = rm->Load<Texture>("../img.png"); diff --git a/resource-manager/resource_manager.cpp b/resource-manager/resource_manager.cpp index 1412592..aee0ce2 100644 --- a/resource-manager/resource_manager.cpp +++ b/resource-manager/resource_manager.cpp @@ -5,6 +5,15 @@ #include "resource.h" #include <unordered_map> +ResourceManager* ResourceManager::m_single_resource_manager = nullptr; + +ResourceManager* ResourceManager::get_instance(){ + if (m_single_resource_manager == nullptr) { + m_single_resource_manager = new ResourceManager(); + } + return m_single_resource_manager; +} + ResourceManager::ResourceManager(){ } @@ -14,6 +23,8 @@ ResourceManager::~ResourceManager(){ for(auto pair : m_resources){ delete pair.second; } + + delete m_single_resource_manager; } diff --git a/resource-manager/resource_manager.h b/resource-manager/resource_manager.h index ea9c80a..c155559 100644 --- a/resource-manager/resource_manager.h +++ b/resource-manager/resource_manager.h @@ -14,11 +14,29 @@ using namespace crepe; class ResourceManager{ -public: +private: + + static ResourceManager* m_single_resource_manager; + std::unordered_map<Constants::FILE_PATH, Resource*> m_resources; + + + +protected: ResourceManager(); ~ResourceManager(); - + +public: + ResourceManager(const ResourceManager &) = delete; + ResourceManager(ResourceManager &&) = delete; + ResourceManager &operator=(const ResourceManager &) = delete; + ResourceManager &operator=(ResourceManager &&) = delete; + + static ResourceManager* get_instance(); + + + +public: template<typename T> T* Load(const Constants::FILE_PATH& file_path){ @@ -35,8 +53,6 @@ public: void Unload(const Constants::FILE_PATH& file_path); -private: - std::unordered_map<Constants::FILE_PATH, Resource*> m_resources; }; |