Game Engine Architecture

(Ben Green) #1

204 5. Engine Support Systems


if(LogManager::getSingletonPtr() == 0)
{
mLogManager = new LogManager();
mLogManager->createLog(logFileName, true, true);
}

// Dynamic library manager
mDynLibManager = new DynLibManager();
mArchiveManager = new ArchiveManager();

// ResourceGroupManager
mResourceGroupManager = new ResourceGroupManager();

// ResourceBackgroundQueue
mResourceBackgroundQueue
= new ResourceBackgroundQueue();
// and so on...

Ogre provides a templated Ogre::Singleton base class from which all of its
singleton (manager) classes derive. If you look at its implementation, you’ll
see that Ogre::Singleton does not use deferred construction, but instead
relies on Ogre::Root to explicitly new each singleton. As we discussed above,
this is done to ensure that the singletons are created and destroyed in a well-
defi ned order.

5.1.3.2. Naughty Dog’s Uncharted: Drake’s Fortune
The Uncharted: Drake’s Fortune engine created by Naughty Dog Inc. uses a
similar explicit technique for starting up its subsystems. You’ll notice by look-
ing at the following code that engine start-up is not always a simple sequence
of allocating singleton instances. A wide range of operating system services,
third party libraries, and so on must all be started up during engine initial-
ization. Also, dynamic memory allocation is avoided wherever possible, so
many of the singletons are statically-allocated objects (e.g., g_fileSystem,
g_languageMgr, etc.) It’s not always prett y, but it gets the job done.

Err BigInit()
{
init_exception_handler();

U8* pPhysicsHeap = new(kAllocGlobal, kAlign16)
U8[ALLOCATION_GLOBAL_PHYS_HEAP];
PhysicsAllocatorInit(pPhysicsHeap,
ALLOCATION_GLOBAL_PHYS_HEAP);
g_textDb.Init();
g_textSubDb.Init();
Free download pdf