Forums
This is the online documentation for Colossus Entertainments Pixie Game Engine

System.h

Go to the documentation of this file.
00001 
00012 #ifndef __System_H__
00013 #define __System_H__
00014 
00015 // It shouldn't be possible to create copies of Systems, and therefore the copy constructor
00016 // and assignment operators have been made private with no implementation. Unfortunately,
00017 // this will cause compiler warning for derived classes, when the compiler tries to 
00018 // automatically generate the copy constructor and assignment operator. To make sure we get
00019 // a clean build without having to declare a copy constructor and assignment operator in
00020 // every derived class, those two warnings are disabled for every file that includes System.h
00021 #pragma warning( disable : 4511)  // copy constructor could not be generated
00022 #pragma warning( disable : 4512)  // assignment operator could not be generated
00023 
00024 // Includes 
00025 #include "Engine.h"
00026 
00027 // External declares
00028 
00029 // System
00030 class System
00031    {
00032    friend class SystemManager;
00033    friend class Engine;
00034    public:
00035       bool IsInitialized();
00036       bool IsStarted();
00037       bool IsRunning();
00038 
00039    protected:
00040       System();
00041       virtual ~System();
00042 
00043       virtual void Initialize();
00044       virtual void Start();
00045       virtual void Stop();
00046       virtual void Terminate();
00047    
00048    private:
00049       void SetInitialized(bool initialized);
00050       void SetStarted(bool started);
00051 
00052    private:
00053       bool initialized_; 
00054       bool started_; 
00055 
00056    // The following will generate a compiler error if there is an attempt
00057    // to create a second instance of the class
00058    private:  
00059       System(const System&);  
00060       const System& operator=(const System&);   
00061    };
00062 
00063 // Helper macros for creating singletons
00064 #define SYSTEM_IMPLEMENTATION(implementationName)                    \
00065    private:                                              \
00066       static implementationName* Create##implementationName##Instance() \
00067          {                                               \
00068          return new implementationName;                           \
00069          }                                               \
00070    public:                                                  \
00071       static void Register()                                   \
00072          {                                               \
00073          Engine::GetInstance()->RegisterSystem(                   \
00074                      #implementationName,                   \
00075                      (void*)Create##implementationName##Instance);   \
00076          }                                               
00077 
00078 #define IMPLEMENT_GETINSTANCE(className)                                \
00079    inline className* GetInstance_##className(bool assertExists = true)           \
00080       {                                                        \
00081       static className* instance=0;                                  \
00082       if (instance)                                               \
00083          {                                                     \
00084          return instance;                                         \
00085          }                                                     \
00086                                                                \
00087       if (!assertExists && !Engine::GetInstance()->IsSystemPresent(#className))  \
00088          {                                                     \
00089          return 0;                                                \
00090          }                                                     \
00091                                                                \
00092       instance=(className*)Engine::GetInstance()->GetSystem(#className);         \
00093       return instance;                                            \
00094       }                                                        \
00095                                                             
00096 
00097 
00098 #endif /* __System_H__ */