Jump to content
  • Advertisement
Sign in to follow this  
B_old

(C++) Templates for a resourcemanager

This topic is 4485 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

Hello, I was thinking about having a resourcemanager using templates. The idea, which I saw somewhere, is this. You have a ResourceManager where you can register different ResourceLoaders. Then you use the manager like this: resourceManager.loadResource<Texture>(). The manager will find the appropriate loader and use it to proive a Texture (in this case). I believe this, or something similar, can be done, but I have several problems. How could loadResource<>() find the right loader depending on the provided template class? I want the manager to have a list with all the resources loaded so far. But there is no way to dynamically add a resource typ when a new loader is registered. Right? There would have to be a common baseclass for all resources I believe. Can you see a solution for some of my problems, or do you maybe have a suggestion to do it differently alltogether? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
If you derive all your resources from a common base class, you can create a resource creation base interface, call it ResourceCreator. The use a wrapper class around the std::type_info with an ordering relationship, call it TypeInfo, and you can register your resource creators with the TypeInfo of the resource class in a std::map<TypeInfo, ResourceCreator *> . Then when the template resource creation function is called, you can index the std::map with the type_id of the desired resource and invoke the creator from the relevant ResourceCreator interface.

Share this post


Link to post
Share on other sites
The resourcecreator is what I called loader?
I will look into the std::type_info. Thanks!

A general question. Does this seem like a more or less reasonable way to handle resources?

Share this post


Link to post
Share on other sites
Correct.

another solution object factory

highly recommend Modern C++ Design: Generic Programming and Design Patterns Applied by Andrei Alexandrescu

Kuphryn

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!