Categories: General
Posted by
pieterg on
11/8/2005 11:59 PM |
Comments (6)
Today I am going to try and map out what I have in store for my resource and entity manager.
When working with large amounts of data such as textures, meshes and other variables also known as resources you need to be pretty sure that you manage them well.
Let s go over some of the basic methods that present themselves.
Entity self loadingYou could have an entity manager that has a couple of methods for handling it s own resources. This is quite a good concept at first and let s look at the basic outline
///
/// Handles specific entities and queries the resource list to instantiate them ///
class EntityManager
{ #region Membersprivate ArrayList entityList;#endregion#region Propertiespublic ArrayList EntityList
{get { return entityList; }
}#endregion#region Methodspublic EntityManager()
{
entityList = new ArrayList();
}publicvoid Add(Entity entity)
{
entityList.Add(entity);
}publicvoid Remove(Entity entity)
{
entityList.Remove(entity);
}#endregion
}
From first glance this seems pretty useless as it s just a skeleton and it could easily be just an ArrayList can t it. The thing to note is that you could enhance the entity manager to control certain parts of each entity like provide a cull method or provide a property that will only return renderable entities. This is really just a simple entity manager.
The problem comes in resource management and that you might have 50 entities using the same texture or mesh or both. So when loading your entities and letting them handle their resources themselves present the problem of duplicating alot of resources which is "bad". What else can we do?The Resource Manager
We could create a resource manager. This resource manager will keep a list of all available resources that are loaded and ready to use. This will include textures, models and more.. This will enable the entity manager or scenegraph whatever the structure of your engine is to query the resource manager for a set of specific resources and create an entity object and place it in a entity list.
PS: The entity list is usefull for doing queries from as it will enable you to pass the list between manager such as your physics engine that will do it s magic on the entities and pass the object to a pre-render batching system that will compute a PVS (Potentially visible set) which will basically cull some objects and pass a modified list to the renderer for rendering.
///
/// Manages resources such as Meshes, Animations, Textures. ///
class ResourceManager
{#region Membersprivate Hashtable resourceList; #endregion#region Propertiespublic Hashtable ResourceList
{get { return resourceList; }
} #endregion#region Methods
///
/// Constructor : Initializes the resource list ///
public ResourceManager()
{
resourceList = new Hashtable();
}public void Add(string key, object resourceItem)
{
resourceList.Add(key, resourceItem);
} #endregion
}
You could provide methods on getting the resources which should be trivial.
As I continue to make adjustments to this work in progress I shall post updated parts of the resource and entiy manager.
72c393f2-4776-429d-8f20-c1196b833c40|0|.0