I've created a resource manager in my engine which adds some basic functions for adding and accessing loaded resources the actual loading is handled wherever it's needed though for example in News my mesh file I have the class and a free function
struct Mesh : Resource {
// vetices, vao, vbo, etc
};
void LoadMeshFromFile(const std::string& name, const std::string& path)
I realized it'd make more sense if the resource manager also handled loading that way I can do some common things like checking if the file is valid instead of having multiple load functions scattered around, however, I'm not exactly sure how I'd refactor for this to work.
struct ResourceLibrary {
std::map<std::string, std::unique_ptr<Resource>> resources;
template<typename TResource>
void AddResource(const std::string& name, std::unique_ptr<TResource> resource) {
}
template<typename TResource>
TResource& GetResource(const std::string& name) {
}
};
The easiest and only solution I've seen is to have some sort of registering of loader classes or functions and then have a load function (probably templated) that calls the proper load function, but I feel like this is a bit messy since i have to find a convenient spot to register all of them and perhaps do some inheritance if I use classes.