What do you mean with diffrent resource keys?
I thought about a single class template
thor::ResourceKey<R>, where
R is the resource. For example,
thor::ResourceKey<sf::Texture> replaces
thor::Resources::TextureKey. It can be initialized from a function returning a pointer to a resource (maybe
unique_ptr) and a string representation to compare different keys. It also provides methods to actually load a resource and to get debug informations. Resource keys are more constrained (one must use
thor::ResourceKey), but custom ones are easier to construct.
template <class R>
class ResourceKey
{
public:
ResourceKey(std::function<R*()> loader, std::string key);
std::unique_ptr<R> load() const;
std::string getInfo() const;
};
Furthermore, there are free functions that create a resource key, for example:
template <class R>
thor::ResourceKey<R> thor::Resources::fromFile(std::string filename);
Note that it is a template. It should be able to load every class providing a method
bool R::loadFromFile(std::string filename);
Unfortunately, I would have to create a special case for
sf::Music because of its
openFromFile() function
thor::ResourceManager<Resource> itself doesn't require a second template argument, keys are always
thor::ResourceKey<Resource>. Loading looks like this:
thor::ResourceManager<sf::Texture> manager;
manager.acquire( thor::Resources::fromFile<sf::Texture>("image.png") );
The thing I currently don't like is the need to specify
sf::Texture again. I could avoid that by complicated return types with implicit conversions, but that's probably not good either
What do you think?
Since you're gonna refractor it, I wanted to asked if it was somehow possible to combine the resource manager into one class or provide another class which combines the other ones. It's just kinda of annoying if you have to keep track of three or more diffrent resource managers (one for loading fonts, one for loading textures, one for loading sounds, etc). I don't know how one would do this the best way but maybe you do!
Yes, I've already thought about this in Thor 1, but I haven't found a clean solution so far. However I'll reflect about it again, thanks for the feedback