Sign in to follow this  
extralongpants

Resources Containing Resources

Recommended Posts

extralongpants    704
One thing I failed to take into account when designing my resource manager, was the seemingly innevitable need for resources to contain other resources (or at least references to them). My brain can't seem to generate a good enough solution (yes, it's my brain's fault, not mine!) for the problem, so I am asking you for advice. Let me describe my situation so that you may understand the problem on a practical level: I have two resource types: GUI Theme and Font. In each GUI Theme file there is a string representing the location of a Font, and the GUI Theme itself contains a handle to the Font as loaded into the resource manager. When loading a GUI Theme, do I...
  1. have the GUI Theme load the Font file?
  2. have the GUI Theme 'schedule' the Font to be loaded at a later time?
  3. leave it up to the programmer to load the Font after loading the GUI Theme?
  4. <insert better solution here>?
There are problems to all of my proposed solutions, as follows:
  1. have the GUI Theme load the Font file? - This requires my resource manager to be able to recursively load resources, which at present, may be problematic. If the Font resides in the same resource file as the GUI Theme, for instance, the file will be opened up twice, which seems dangerous to me. I think my manager would behave itself, but it's also up to each resource to behave itself when it reads itself from the file.
  2. have the GUI Theme 'schedule' the Font to be loaded at a later time? - This solution isn't as dangerous as the first, but it is not ideal in that resources are not immediately available after loading, and there is no immediate way to tell if a resource file has failed to load properly.
  3. leave it up to the programmer to load the Font after loading the GUI Theme? - I think it's pretty apparent that this sucks. Espcecially if resources are deeply nested. It solves the problem, but it leaves way too much up to the programmer.
  4. <insert better solution here>? - It hasn't been suggested yet [lol].
Can you think of a better solution, or a way to improve one of my own? I will be grateful for any advice given. Thanks for your time. -Chris [EDIT] - Oh, and I forgot to mention: All of my solutions are less than ideal because they form an interdepency between the resource being loaded and the resource manager. It seems to me that the resource manager should be aware of the resource, and not the other way around, although I may have to settle on the issue due to the practicality of the 'improper' approach. [Edited by - extralongpants on March 27, 2006 5:07:15 PM]

Share this post


Link to post
Share on other sites
Doggan    528
1). have the GUI Theme load the Font file? - I do not like this idea at all. The point of creating a resource manager in the first place is to 'manage' the resources. A resource should not load another resource directly, nor should it directly tell the resource manager to load another resource.

2). have the GUI Theme 'schedule' the Font to be loaded at a later time? - I had actually thought of this before I read it in your post. Possibly create a priority queue? which will load in all your resources. When a resource deems it needs to load in a resource, add this to your priority queue w/ a very high priority so that it gets loaded next. This will allow for a recursive resource loading.

3). leave it up to the programmer to load the Font after loading the GUI Theme? - No - it is quite apparent that this sucks :p

It is true that the resource should not be aware of the resource manager. But from what comes to mind at the current time, 2) is by far the best. You are not violating this principle too much, because the resource isn't 'really' aware of the resource manager (it would be bad to call the resource manager directly). The queue system makes the resource only indirectly aware of the resource manager...

Share this post


Link to post
Share on other sites
extralongpants    704
Quote:
Original post by Doggan
1). have the GUI Theme load the Font file? - I do not like this idea at all. The point of creating a resource manager in the first place is to 'manage' the resources. A resource should not load another resource directly, nor should it directly tell the resource manager to load another resource.

2). have the GUI Theme 'schedule' the Font to be loaded at a later time? - I had actually thought of this before I read it in your post. Possibly create a priority queue? which will load in all your resources. When a resource deems it needs to load in a resource, add this to your priority queue w/ a very high priority so that it gets loaded next. This will allow for a recursive resource loading.

3). leave it up to the programmer to load the Font after loading the GUI Theme? - No - it is quite apparent that this sucks :p

It is true that the resource should not be aware of the resource manager. But from what comes to mind at the current time, 2) is by far the best. You are not violating this principle too much, because the resource isn't 'really' aware of the resource manager (it would be bad to call the resource manager directly). The queue system makes the resource only indirectly aware of the resource manager...


Thanks for your input!

Yeah, I agree on #2 being the best option thus far. I guess I could separate the queue a from the resource manager in such a way as to minimize access to the manager from resource classes.

The queue also lends itself to multi-threading more easily, which is something I want to take advantage of, given the recent trend in CPU architecture.

Share this post


Link to post
Share on other sites

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