I posted a question about asynchronous resource loading previously, and got some really useful replies. I've run into a problem with resource dependencies, and I was hoping to see what others think.
My original system had several resource types, and some were dependent on others - for example, a Shader resource is dependent on a VertexShader and FragmentShader, and a Material is dependent on a Shader.
I solved this by providing the loaders access to caches of the dependent resources, which works fine when everything is synchronous:
ResourceLoader<Shader> shaderLoader;
ResourceCache<Shader> shaderCache(&shaderLoader);
// Allow the material loader to resolve shader references:
ResourceLoader<Material> materialLoader(&shaderCache);
// Now a material request will automatically load the shader if necessary.
ResourceCache<Material> materialCache(&materialLoader);
MaterialPtr material = materialCache.get("test.mat");
With asynchronous loading this isn't so straightforward. A material will be loaded and asynchronously load its dependent shader, but the shader won't be loaded right away and might even encounter an error - making the material invalid.
I could design some complicated dependency system, but I'm hoping there is a simpler way. Does anyone have any suggestions to point me in the right direction?
Many thanks!