Skip to main content
GameDev.net gamedev.net
🔒 Locked

Resource Manager Design

Started by Ilici Dec 28, 2004 at 6:23 PM 3 replies 1.1k views
Original Post
Ilici
Ilici
I'm trying to make a resource manager which would take care of loading all of the loadable game objects i'm using such as images, sounds and 3d models. Now i want to have all of these share some properties so i'm going to make them inherit a resource base class:

class VResource
{
public:

	VResource();

	string GetName() { return FileName; }
	string SetName(string name) { FileName = name; }

	unsigned GetReferenceCount() { return ReferenceCount; }
	void	IncrementCount() { ReferenceCount++; }
	void	DecrementCount() { ReferenceCount--; }

	virtual void Destroy() = 0;
	virtual void LoadFromFile(string fname) = 0;
	
private:

	string FileName;

	unsigned ReferenceCount;	//this should be incremented for every load, and decremented for every destroy
};
Now the resource manager should load any type of resource which inherits this base class. I've thought of having the resource manager call the LoadFromFile function of each resource but since it doesn't know what type of resource this is it can't cast it to the right type of class. How do you think it should it be designed?
Brendan Bond
Brendan Bond
Well, you might first think about adding garbage collecting functionality to the VResource class. In answer to your question, though, a solution might be to use a template LoadFromFile() function. That way, you could return whatever typename you specify in the function. The only downside to this, I think, would be the fact that a class derived from VResource isn't guaranteed to be returned by the function.

-Brendan Bond

EDIT: Wow, what a weird double post.
Brendan Bond
Ilici
Ilici
Quote:
Original post by Brendan Bond
Well, you might first think about adding garbage collecting functionality to the VResource class. In answer to your question, though, a solution might be to use a template LoadFromFile() function. That way, you could return whatever typename you specify in the function. The only downside to this, I think, would be the fact that a class derived from VResource isn't guaranteed to be returned by the function.

-Brendan Bond



How does garbage collection work? I've never implemented this. What i did until now is to deallocate all the objects in the manager's pool at the end of the game.

How would the template LoadFromFile function look like? (I've rarely used templates before)
sakky
sakky
Here is a link to a topic I started similar to this one. I’ve listed my design there.
Take back the internet with the most awsome browser around, FireFox

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.