Sign in to follow this  

Resource load parameters

This topic is 4531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I came up against a design problem. I have Resource and ResourceManager base classes that serve to manage all resources in our engine. Lets make an example with textures. When you want to load a Texture (derived from Resource), you request it to TextureManager (derived from ResourceManager) with a file and certain load parameters (like filtering, compression, bpp). The problem arises when you request the same texture twice but with different LoadParams, what should the manager do? Maybe the best option is to save load params in the texture and compare between requests of the same resource. I haven't taken into account that a resource can have load parameters, because they can vary in number and size, so basic resource manager hasn't got the ability to distinguish between parameters.

Share this post


Link to post
Share on other sites
First thing to do, is to pack all load parameters into a single struct. That way all loading functions would have similar syntax. You could also use it as a resource key, along with file name(if needed).

Second: probably you have your reasons to use inheritance for managers. But I don't know them, so let's put them aside for a moment. I would say - go for templates. Templated by parameter-struct and resource type. A manager could still be derived from base ResourceManager class (but I don't know what functionality it could provide then, though). So better to stick with base template, which would be instantiated for each resource type.

You would have to know what type the manager is, when getting/loading resource, so what good will inheritance do here anyway?

But maybe I'm saying that because my resource managing system looks like that...

Cheers.
/def

Share this post


Link to post
Share on other sites
Maybe it's just me, but I really don't see the need of complicating matters as much as in the article. I'm more into the way it's done in DX (actually, only some parts of their design). There's a manager, which is basically a map< key, pair<refcnt,value*> >. Key and value are template parameters, refcnt is a simple int.

Upon loading, it simply returns the resource (or something, that allows the manager to quickly find the node in its map (like wraper for pointer of the node), otherwise you need to store a map<value*, node> in the manager, which could be a waste, but for starting, it's ok). The every Get() of the resource will quickly search for it and increase refcnt (otherwise load).
From the resource level, you can call release(), instead of deleting. The resource itself should then pass parameters needed to its manager, the manager would decrease refcnt, and delete the resource if needed.

Now, why multimap? You meant map with multiple values as key, probably. You simply pack them into a struct, and pass as a single template parameter.
struct TexKey {
std::string name;
int bpp;
int filtering;
//...
};

If you want, you can create an additional function, which would be getting all those parameters, pack them into a struct, and pass to the underlying map.

Hope that helps.
/def

Share this post


Link to post
Share on other sites

This topic is 4531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this