Original Post
Hello! I'm currently working on a game project with SFML and C++ and I'm writing my games resource manager, if you don't know what that is it's basically a class to take care of storing game assets that can be reused without reloading, and takes care of cleaning them up (RAII).
My design plan is to create a main template interface (or base) class called ResourceManager, the template parameter being the type of resource you want it to manage. It would have a function Get, which would take a std::string argument filename, and which would load the resource if not loaded, and then return it, or just return it if it's already loaded. It would have a typedef T* Resource (T being the template parameter.) It would have a std::map which would store the resources and the key being the filename. The destructor would take care of the resources of cleaning up the resources (SFML's resource types use RAII already anyway, so this is unnecessary for some of them). Lastly it would have a pure virtual function called LoadResource(const std::string& filename);
Next I would create classes like ImageManager, SoundManager, MusicManager, etc. Those would inherit ResourceManager (Resource type being sf::Image for SFML Images, sf::Sound for SFML sounds, etc.) and Singleton (ManagerClassName being ImageManager for ImageManager, etc.). These classes would then implement the virtual LoadResource() function and load the resource for it's specific resource type, then return the resource for the Get function.
Accessing a resource would be simple, for example I could assign it to ImageManager::Resource logo_image = ImageManager::GetInstance().Get("Data/Textures/Logo.jpg"), which could then be applied to an sf::Sprite via sprite.SetImage(*logo_image). Or I could assign and play music by going ImageManager::GetInstance().Get("Data/Music/Music.ogg")->Play();. Simple as that!
(Resource again being the typedef T*)
My design plan is to create a main template interface (or base) class called ResourceManager, the template parameter being the type of resource you want it to manage. It would have a function Get, which would take a std::string argument filename, and which would load the resource if not loaded, and then return it, or just return it if it's already loaded. It would have a typedef T* Resource (T being the template parameter.) It would have a std::map
Next I would create classes like ImageManager, SoundManager, MusicManager, etc. Those would inherit ResourceManager
Accessing a resource would be simple, for example I could assign it to ImageManager::Resource logo_image = ImageManager::GetInstance().Get("Data/Textures/Logo.jpg"), which could then be applied to an sf::Sprite via sprite.SetImage(*logo_image). Or I could assign and play music by going ImageManager::GetInstance().Get("Data/Music/Music.ogg")->Play();. Simple as that!
(Resource again being the typedef T*)