Hello,
few days ago i started writing my own Resource Manager. It's not my first attemp to do this so i'm trying to design it as good as possible, but i run to couple of issues.
So i've got Resource<T> class that takes as template parameter some data.
For example if i want to pack Shader inside it , it's done like this:
typedef Resource<ShaderData> Shader; //Somewhere in code
Shader SomeKindOfShader = ResourceManager->load<Shader>("Basic"); //This returns existing shader or loads new
SomeKingOfShader->bind(); //-> is overloaded to return ShaderData
But the problem is in ResourceManager, to make it most flexible i decided to make ResourceLoaders as Depedency Injection objects.
Let's say:
class ResourceManager
{
public:
void addLoader(ResourceLoader* NewLoader); //Adds it to map
private:
std::map<typeid, ResourceLoader*> Loaders;
}
class ResourceLoader
{
public:
virtual any load(void* Data) = 0; //Loads given from memory data
}
class TextureLoader : public ResourceLoader
{
public:
any load(void* Data) //Here is problem, loader would like to know also about Width, Height etc.
{
//Loads and returns data
}
}
The problem is that i have no idea how to workaround problem with additionall parameters for given loaders.
Texture loader here is just example, there could be Shader loader who would need also compilation parameters for uber shader etc.
I've come with ideas of using va_list, initializer_list and even variadic_templates but they're not really beautiful solutions.
Here is my question: How to design(or redisign) current way of managing those loaders with custom number of parameters?
Thanks for any help :)