SLIDE 3 A simple approach that works (1/2) A simple approach that works (1/2)
class GRenderEngine { class GRenderEngine { // // game render manager game render manager public: public: void void startUp startUp () () { /* { /* start up the render manager start up the render manager */ } */ } void void shutDown shutDown () () { /* { /* shut down the manager shut down the manager */ } */ } void void shutDown shutDown () () { /* { /* shut down the manager shut down the manager */ } */ } GRenderEngine () GRenderEngine () { /* { /* initial values for empty state initial values for empty state */ } */ } ~GRenderEngine () ~GRenderEngine () { /* { /* do do (mostly mostly) nothing nothing */ } . . . */ } . . . }; }; class GPhysicsEngine class GPhysicsEngine { / { /* similar . . . similar . . . */ }; / }; class GAnimationMachine { / class GAnimationMachine { /* similar . . . similar . . . */ }; / }; * * class GTextureManager class GTextureManager { / { /* similar . . . similar . . . */ }; / }; class GVideoManager class GVideoManager { / { /* similar . . . similar . . . */ }; / }; class GMemoryManager class GMemoryManager { / { /* similar . . . similar . . . */ }; / }; class GFileSystemManager { / class GFileSystemManager { /* similar . . . similar . . . */ }; . . . / }; . . .
21.2.2017 21.2.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 9
Simple approach that works (2/2) Simple approach that works (2/2)
GRenderEngine Renderer; GRenderEngine Renderer; GPhysicsEngine PhysicsEngine; . . . GPhysicsEngine PhysicsEngine; . . . // // etc. etc. GMemoryManager MemoryManager; GMemoryManager MemoryManager; GFileSystemManager FileSystemManager; GFileSystemManager FileSystemManager; . . . . . .
static instances
GFileSystemManager FileSystemManager; GFileSystemManager FileSystemManager; . . . . . . int main () { int main () { Renderer.startUp (); Renderer.startUp (); // // start all subsystems start all subsystems in order in order PhysicsEngine.startUp (); PhysicsEngine.startUp (); . . . . . . GameRun (); GameRun (); . . . . . . // // run the game run the game PhysicsEngine.shutDown (); PhysicsEngine.shutDown (); // // close down systems close down systems in reverse in reverse PhysicsEngine.shutDown (); PhysicsEngine.shutDown (); // // close down systems close down systems in reverse in reverse Renderer.shutDown (); Renderer.shutDown (); }
- [Gregory]: the solution is crude but simple and explicit; and easy
[Gregory]: the solution is crude but simple and explicit; and easy to implement, debug, and maintain to implement, debug, and maintain
21.2.2017 21.2.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 10 10
Sample initialization: Ogre3D Sample initialization: Ogre3D
OgreRoot.h OgreRoot.h // // header file header file class _OgreExport Root: public class _OgreExport Root: public Singleton Singleton <Root> { <Root> { // < // < some code omitted some code omitted... > ... > OverlayElementFactory OverlayElementFactory * mPanelFactory; mPanelFactory; OverlayElementFactory OverlayElementFactory * mBorderPanelFactory; mBorderPanelFactory;
defines singleton entry point and checks
// // declare singletons declare singletons LogManager LogManager * mLogManager; mLogManager; ControllerManager ControllerManager * mControllerManager; mControllerManager; SceneManagerEnumerator SceneManagerEnumerator * mSceneManagerEnum; mSceneManagerEnum; SceneManager SceneManager * mCurrentSceneManager; mCurrentSceneManager; DynLibManager DynLibManager * mDynLibManager; mDynLibManager; ArchiveManager ArchiveManager * mArchiveManager; mArchiveManager; OverlayElementFactory OverlayElementFactory * mBorderPanelFactory; mBorderPanelFactory; OverlayElementFactory OverlayElementFactory * mTextAreaFactory; mTextAreaFactory; OverlayManager OverlayManager * mOverlayManager; mOverlayManager; FontManager FontManager * mFontManager; mFontManager; ArchiveFactory ArchiveFactory * * mZipArchiveFactory; mZipArchiveFactory; ArchiveFactory ArchiveFactory * * mFileSystemArchiveFactory; mFileSystemArchiveFactory; ResourceGroupManager ResourceGroupManager * mResourceGroupManager; mResourceGroupManager; ResourceBackgroundQueue ResourceBackgroundQueue *
21.2.2017 21.2.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 11 11
MaterialManager MaterialManager * mMaterialManager; mMaterialManager; MeshManager MeshManager * mMeshManager; mMeshManager; ParticleSystemManager ParticleSystemManager * mParticleManager; mParticleManager; SkeletonManager SkeletonManager * mSkeletonManager; mSkeletonManager; ResourceBackgroundQueue ResourceBackgroundQueue * mResourceBackgroundQueue; mResourceBackgroundQueue; ShadowTextureManager ShadowTextureManager * mShadowTextureManager; mShadowTextureManager; // // etc. etc. }; };
Sample initialization: Ogre3D (cont.) Sample initialization: Ogre3D (cont.)
OgreRoot.cpp OgreRoot.cpp // // translation unit translation unit Root::Root (const String& pluginFileName, Root::Root (const String& pluginFileName, const String& configFileName, const String& configFileName, // // create log manager and default log file if there create log manager and default log file if there // // is no log manager yet is no log manager yet
Uses manager objects, but could be possible to hide these in .cpp files?
const String& configFileName, const String& configFileName, const String& logFileName) : const String& logFileName) : mLogManager (0), mLogManager (0), mCurrentFrame (0), mCurrentFrame (0), mFrameSmoothingTime (0.0f), mFrameSmoothingTime (0.0f), mNextMovableObjectTypeFlag (1), mNextMovableObjectTypeFlag (1), mIsInitialised (false) mIsInitialised (false) { // { // superclass will do singleton checking superclass will do singleton checking // // is no log manager yet is no log manager yet if (LogManager::getSingletonPtr () == 0) { if (LogManager::getSingletonPtr () == 0) { mLogManager = new LogManager (); mLogManager = new LogManager (); mLogManager mLogManager->createLog (logFileName, true, >createLog (logFileName, true, true); true); } mDynLibManager = new DynLibManager (); mDynLibManager = new DynLibManager (); mArchiveManager = new ArchiveManager (); mArchiveManager = new ArchiveManager (); mResourceGroupManager = new mResourceGroupManager = new
21.2.2017 21.2.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 12 12
. . . . mActiveRenderer = 0; mActiveRenderer = 0; mVersion = . . . // mVersion = . . . // construct version name construct version name mConfigFileName = configFileName; mConfigFileName = configFileName; mResourceGroupManager = new mResourceGroupManager = new ResourceGroupManager (); ResourceGroupManager (); mResourceBackgroundQueue = new mResourceBackgroundQueue = new ResourceBackgroundQueue (); ResourceBackgroundQueue (); // // and so on.. and so on..