Recommended Posts

Ok I've got main engine app object, and there shoud be only one instance of it. There are many subsystems (resource cache, asset manager, scene graph, etc). Which is the best way to access and create them.(All of them can have only one instance)

Currently I'm using 2 static global object for each system + a static get method.
static AssetManager * g_pAssetManager = NULL;
static AssetDestructor g_AssetManagerDestructor; // omfg I could have used boost's shared ptr to remove this class...
static AssetManager * const AssetManager::Get();

On Get() I'm checking if g_pAssetManager = NULL and allocate it. Then I return the ptr;
g_AssetManagerDestructor just check if g_pAssetManager is different than NULL and delete it;

However some systems are using another systems in their destruction process and this can cause runtime failure(destory A.destroy B using A's methods)

Any ideas how I can keep these sytems so I can control their destruction order?
(I have tried something with the resource cache already. To save some headaches and saved the get method, but I moved the global pointer into the engine app object. So it is actually doing:
[source lang="cpp"]static ResourceCashe * const ResourceCache::Get()
{
return RandomEngineApp::Get()->GetResCache();
}[/source]
Any suggestions? I've got poor design pattern knowledge(only factories, I've heard of singleton pattern but I'm not really sure if I'm using it )
Edited August 27, 2012 by Nickie

0

Share this post

Link to post

Share on other sites

Yea you're using singleton pattern, and seeing some problems what they can cause. If you create the systems normally and give global access to them, you can control the construction and destruction orders.