Here comes the point in the thread where I actually begin theorizing rather than giving you provenly tested code, don't fret, I'm pretty sure I've got this down pat.
ResourceCache, as we said before, does not work on his own, he is like a paintbrush without an artist. ResourceManager is that artist.... What does ResourceManager need to do? Well first, lets think about what ResourceCache can't do.
He doesn't know what to load.
He'll load whatever you give him regardless if it is already in the warehouse or not
He doesn't decide when to clear out his caches.
He doesn't decide when to start adding to his caches
He doesn't have a way to keep track of what resources are there.
ResourceManager will do a few main things, keep track of what resources have been loaded, take orders on what needs to be loaded (from where you don't need to worry about yet), and he needs to give orders to clean up shop, as well as needing to give orders of what to load when, for how long...
Another thing to think about, is what kinds of caches will we have? Even though they might contain relatively the same information, do you really need the mass of Object A when he is either out of your sight completely, or so far away you really just don't need his information, no, not at all. Do you need information at all times for an object that has a lifetime of mere seconds? Think bullets, rockets, projectiles, particles, things like this!
We'll continue with some code:
class ResourceManager{Resourcecache LevelCache*;ResourceCache TempCache*;ResourceCache PermanentCache*void Create_IDs(Object);{ Read what resources the Object needs (comes in the form of strings for filenames, or wherever you're getting the info from.) If resources exist, do not load them! Instead return the index of the container theyre in <-- THIS IS YOUR OBJECT ID!!! PRECIOUS!!! If they don't exist, tell the caches to load them, and then return the index of the container theyre in <---- your OBJECT IDs!!! Set ID values in Object's info structure (explained shortly) equal to what this function is popping out...}};
Okay, whew, that was alot, I'll try to explain this the best I can. If I can't explain this, I'll need to rework my system until I can explain it.
Alright, so lets start at the top, ResourceManager has a couple resourceCache types... He can handle Level Cache, the kind of resource you need throughout your actual game level, or anything for an extended but non permanent length of time. He can handle temporary cache, things like particles, bullets, laser guns, rockets, little things with a short life. And then finally he can handle a permanent cache, things that you need throughout the entire program life, menu systems, things like that.
This guy is like a director of sorts, he just directs traffic in and out of the caches... He needs a method to hand out Object ID's. I'll take this time to explain an ID, most of this will be ripped from another source.
"An ID is simply the index of the object in the index which contains all of the game objects, or at least all of them for the current level, or the current map area that has been loaded in (say in a flight sim)."
This boils down to, the object ID is the element where the resource is held in in our container! This I feel is the best way to keep track of ID's as well as generate them, and almost the only way to tie resources and ID's together. We need ID's to provide quick and easy access to information that certain systems might need, like your Rendering engine, your physics and collision engine, your sound engine, multiple engines in your system can use a simple list of ObjectID's to deal with..
There are still a few questions to answer, What exactly is Object giving to the Create_IDs function to let it do its job?
The answer lies in the next post.
----------------------------------------------------------Rating me down will only make me stronger.----------------------------------------------------------