Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Resource Manager Design Part 1

Sign in to follow this  


I don't claim to be a design guru, nor do I claim to be a C++ expert, this is just me working idea through to try and come up with a decent and comprehensive resource manager.

With that out of the way, welcome [smile]
As started above and before now, this is basically going to be me pondering things and working through a design of a resource system, hopefull I'll formalise this when finished and both this and the formal document will be some use to people.

Anyways, right now I've finished and coded up the first design; its a simple two class affair, one being the manager and the other being a 'handle' class.

One of the first issues which hit me was; is manager a good name?
After a trip to dictionary.com I decided it was and the definition helpped work out one other implimentation detail; what responciblity goes where?
Manager at Dictionary.com
someone who controls resources and expenditures

Using this quote and thinking about it in real world terms means that really all a manager should do is hand out and keep a track of resources, this is important as it lets us know where we should put the functionality such as binding the texture.

Why is this important? Well, the definition gives us the 'scope' of the class and its responibilties and one of the tenets of OOP is the Single responsibility principle or SRP, which states that one class should have one responciblity, which in this case is the handing out and tracking of resources, so to add things such as binding to it would be a violation of the SRP.

This means the handle object needs functions so that we can act upon a texture, I'm reasonably happy with this idea, although the SRP is kinda cominbg back to me at this point as does a handle really need to act on a texture at all? Maybe someone else should be doing this work and is supplied a handle? hmmm, worth considering, if only because as things stand the handle would have to free the texture, does this make sense wrt SRP?

The net result of this is the following code, which as it stands it technically a very basic texture resource handler;



namespace TextureManagerLib
class TextureHandle
TextureHandle(GLuint id) : id(id){};
void Bind()
GLuint id;

typedef boost::shared_ptr handle_t;

class TextureManager
handle_t LoadTexture(std::string const &filename);
typedef std::map texturemap_t;

texturemap_t texturemap;



#include "textureManagerLib.hpp"

namespace TextureManagerLib




handle_t TextureManager::LoadTexture(const std::string &filename)
texturemap_t::iterator it = texturemap.find(filename);
if(it != texturemap.end())
return it->second;

GameTextureLoader::ImagePtr img(GameTextureLoader::LoadTexture(filename),GameTextureLoader::FreeTexture);
GLuint id;
handle_t texture(new TextureHandle(id));

if(img->getFormat() == GameTextureLoader::FORMAT_RGBA)


return texture;

TextureManagerLib v0.1 is done [smile]
Now, to consider the issues I raised some more...
Sign in to follow this  

1 Comment

Recommended Comments

Interesting take on the "real world" definitions and OOP principles. I'm guilty of implementing too many classes/functions that do everything - splitting them up really would be a good idea.

Anyway, back to implementing by CCool3DEngine class...


Share this comment

Link to comment

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
  • 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!