diff --git a/src/base.hpp b/src/base.hpp index 43859ea1a..f0b18f04d 100644 --- a/src/base.hpp +++ b/src/base.hpp @@ -150,8 +150,6 @@ #if EE_PLATFORM == EE_PLATFORM_WIN #ifdef EE_DYNAMIC - #define EE_CALL _stdcall - // Windows platforms #ifdef EE_EXPORTS // From DLL side, we must export @@ -165,20 +163,20 @@ #pragma warning(disable : 4251) #pragma warning(disable : 4244) #pragma warning(disable : 4996) + #pragma warning(disable : 4311) + #pragma warning(disable : 4312) #endif #else // No specific directive needed for static build #ifndef EE_API #define EE_API #endif - #define EE_CALL #endif #else // Other platforms don't need to define anything #ifndef EE_API #define EE_API #endif - #define EE_CALL #endif #ifndef EE_USE_DOUBLES diff --git a/src/graphics/cfontmanager.cpp b/src/graphics/cfontmanager.cpp index 66dbda06b..f8a8097f1 100644 --- a/src/graphics/cfontmanager.cpp +++ b/src/graphics/cfontmanager.cpp @@ -2,6 +2,8 @@ namespace EE { namespace Graphics { +SINGLETON_DECLARE_IMPLEMENTATION(cFontManager) + cFontManager::cFontManager() { } diff --git a/src/graphics/cfontmanager.hpp b/src/graphics/cfontmanager.hpp index 6e21e78be..615bf9fb2 100644 --- a/src/graphics/cfontmanager.hpp +++ b/src/graphics/cfontmanager.hpp @@ -7,8 +7,9 @@ namespace EE { namespace Graphics { class EE_API cFontManager : public tResourceManager, public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cFontManager) + cFontManager(); virtual ~cFontManager(); diff --git a/src/graphics/cframebuffermanager.cpp b/src/graphics/cframebuffermanager.cpp index e7e700f28..904831a2b 100644 --- a/src/graphics/cframebuffermanager.cpp +++ b/src/graphics/cframebuffermanager.cpp @@ -2,6 +2,8 @@ namespace EE { namespace Graphics { namespace Private { +SINGLETON_DECLARE_IMPLEMENTATION(cFrameBufferManager) + cFrameBufferManager::cFrameBufferManager() { } diff --git a/src/graphics/cframebuffermanager.hpp b/src/graphics/cframebuffermanager.hpp index 855df10ca..60ce5b113 100644 --- a/src/graphics/cframebuffermanager.hpp +++ b/src/graphics/cframebuffermanager.hpp @@ -7,8 +7,9 @@ namespace EE { namespace Graphics { namespace Private { class EE_API cFrameBufferManager : public tContainer, public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cFrameBufferManager) + cFrameBufferManager(); virtual ~cFrameBufferManager(); diff --git a/src/graphics/cglobalbatchrenderer.cpp b/src/graphics/cglobalbatchrenderer.cpp index c98d68cfb..edac477e5 100755 --- a/src/graphics/cglobalbatchrenderer.cpp +++ b/src/graphics/cglobalbatchrenderer.cpp @@ -2,6 +2,8 @@ namespace EE { namespace Graphics { +SINGLETON_DECLARE_IMPLEMENTATION(cGlobalBatchRenderer) + cGlobalBatchRenderer::cGlobalBatchRenderer() { AllocVertexs( 1024 ); } diff --git a/src/graphics/cglobalbatchrenderer.hpp b/src/graphics/cglobalbatchrenderer.hpp index 75ae53835..995973af9 100755 --- a/src/graphics/cglobalbatchrenderer.hpp +++ b/src/graphics/cglobalbatchrenderer.hpp @@ -8,8 +8,9 @@ namespace EE { namespace Graphics { /** @brief The global Batch Renderer class. This class will be used by the engine for the rendering. */ class EE_API cGlobalBatchRenderer : public tSingleton, public cBatchRenderer { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cGlobalBatchRenderer) + cGlobalBatchRenderer(); ~cGlobalBatchRenderer(); diff --git a/src/graphics/cglobalshapegroup.cpp b/src/graphics/cglobalshapegroup.cpp index d9bb5a018..9576d2949 100644 --- a/src/graphics/cglobalshapegroup.cpp +++ b/src/graphics/cglobalshapegroup.cpp @@ -3,6 +3,8 @@ namespace EE { namespace Graphics { +SINGLETON_DECLARE_IMPLEMENTATION(cGlobalShapeGroup) + cGlobalShapeGroup::cGlobalShapeGroup() : cShapeGroup( "global" ) { diff --git a/src/graphics/cglobalshapegroup.hpp b/src/graphics/cglobalshapegroup.hpp index f34cdcf4d..c12eab3c1 100644 --- a/src/graphics/cglobalshapegroup.hpp +++ b/src/graphics/cglobalshapegroup.hpp @@ -7,8 +7,9 @@ namespace EE { namespace Graphics { class EE_API cGlobalShapeGroup : public cShapeGroup, public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cGlobalShapeGroup) + cGlobalShapeGroup(); ~cGlobalShapeGroup(); diff --git a/src/graphics/cshaderprogrammanager.cpp b/src/graphics/cshaderprogrammanager.cpp index a6678d803..9ea741bc8 100644 --- a/src/graphics/cshaderprogrammanager.cpp +++ b/src/graphics/cshaderprogrammanager.cpp @@ -2,6 +2,8 @@ namespace EE { namespace Graphics { +SINGLETON_DECLARE_IMPLEMENTATION(cShaderProgramManager) + cShaderProgramManager::cShaderProgramManager() { } diff --git a/src/graphics/cshaderprogrammanager.hpp b/src/graphics/cshaderprogrammanager.hpp index 558771819..8e1d7a96a 100644 --- a/src/graphics/cshaderprogrammanager.hpp +++ b/src/graphics/cshaderprogrammanager.hpp @@ -7,8 +7,9 @@ namespace EE { namespace Graphics { class EE_API cShaderProgramManager : public tResourceManager, public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cShaderProgramManager) + cShaderProgramManager(); virtual ~cShaderProgramManager(); diff --git a/src/graphics/cshapegroupmanager.cpp b/src/graphics/cshapegroupmanager.cpp index 3e0823abc..479df6a22 100644 --- a/src/graphics/cshapegroupmanager.cpp +++ b/src/graphics/cshapegroupmanager.cpp @@ -3,6 +3,8 @@ namespace EE { namespace Graphics { +SINGLETON_DECLARE_IMPLEMENTATION(cShapeGroupManager) + cShapeGroupManager::cShapeGroupManager() : tResourceManager( false ) { diff --git a/src/graphics/cshapegroupmanager.hpp b/src/graphics/cshapegroupmanager.hpp index b531e2d66..d2fcd7898 100644 --- a/src/graphics/cshapegroupmanager.hpp +++ b/src/graphics/cshapegroupmanager.hpp @@ -8,8 +8,9 @@ namespace EE { namespace Graphics { class EE_API cShapeGroupManager : public tResourceManager, public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cShapeGroupManager) + cShapeGroupManager(); virtual ~cShapeGroupManager(); diff --git a/src/graphics/ctexturefactory.cpp b/src/graphics/ctexturefactory.cpp index 820ce954c..0f90635e8 100755 --- a/src/graphics/ctexturefactory.cpp +++ b/src/graphics/ctexturefactory.cpp @@ -4,6 +4,8 @@ namespace EE { namespace Graphics { +SINGLETON_DECLARE_IMPLEMENTATION(cTextureFactory) + cTextureFactory::cTextureFactory() : mMemSize(0) { diff --git a/src/graphics/ctexturefactory.hpp b/src/graphics/ctexturefactory.hpp index 1e20ec340..7507093da 100755 --- a/src/graphics/ctexturefactory.hpp +++ b/src/graphics/ctexturefactory.hpp @@ -14,8 +14,9 @@ class cGlobalBatchRenderer; /** @brief The Texture Manager Class. Here we do all the textures stuff. (Singleton Class) */ class EE_API cTextureFactory: public tSingleton, protected cMutex { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cTextureFactory) + /** Create an empty texture * @param Width Texture Width * @param Height Texture Height diff --git a/src/graphics/cvertexbuffermanager.cpp b/src/graphics/cvertexbuffermanager.cpp index 0be789d2f..1cdf67e07 100644 --- a/src/graphics/cvertexbuffermanager.cpp +++ b/src/graphics/cvertexbuffermanager.cpp @@ -2,6 +2,8 @@ namespace EE { namespace Graphics { namespace Private { +SINGLETON_DECLARE_IMPLEMENTATION(cVertexBufferManager) + cVertexBufferManager::cVertexBufferManager() { } diff --git a/src/graphics/cvertexbuffermanager.hpp b/src/graphics/cvertexbuffermanager.hpp index e663eabe5..fbb4e84c4 100644 --- a/src/graphics/cvertexbuffermanager.hpp +++ b/src/graphics/cvertexbuffermanager.hpp @@ -7,8 +7,9 @@ namespace EE { namespace Graphics { namespace Private { class EE_API cVertexBufferManager : public tContainer, public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cVertexBufferManager) + cVertexBufferManager(); virtual ~cVertexBufferManager(); diff --git a/src/physics/cphysicsmanager.cpp b/src/physics/cphysicsmanager.cpp index 81aa1c332..d8d91e37a 100644 --- a/src/physics/cphysicsmanager.cpp +++ b/src/physics/cphysicsmanager.cpp @@ -6,6 +6,8 @@ CP_NAMESPACE_BEGIN +SINGLETON_DECLARE_IMPLEMENTATION(cPhysicsManager) + cPhysicsManager::cPhysicsManager() : mMemoryManager( false ) { diff --git a/src/physics/cphysicsmanager.hpp b/src/physics/cphysicsmanager.hpp index d7aeaeafc..55600efcd 100644 --- a/src/physics/cphysicsmanager.hpp +++ b/src/physics/cphysicsmanager.hpp @@ -11,8 +11,9 @@ class cConstraint; class cSpace; class CP_API cPhysicsManager : public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cPhysicsManager) + class cDrawSpaceOptions { public: cDrawSpaceOptions() : diff --git a/src/system/clog.cpp b/src/system/clog.cpp index 81c7a438f..d99347dff 100755 --- a/src/system/clog.cpp +++ b/src/system/clog.cpp @@ -2,6 +2,8 @@ namespace EE { namespace System { +SINGLETON_DECLARE_IMPLEMENTATION(cLog) + cLog::cLog() : mSave( false ), mConsoleOutput( false ), diff --git a/src/system/clog.hpp b/src/system/clog.hpp index 25abfc608..70b0fed45 100755 --- a/src/system/clog.hpp +++ b/src/system/clog.hpp @@ -8,8 +8,9 @@ namespace EE { namespace System { class EE_API cLog : public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cLog) + void Save(const std::string& filepath = "" ); void Write(const std::string& Text, const bool& newLine = true); diff --git a/src/system/cpackmanager.cpp b/src/system/cpackmanager.cpp index 97015be45..8359eb1a3 100644 --- a/src/system/cpackmanager.cpp +++ b/src/system/cpackmanager.cpp @@ -2,6 +2,8 @@ namespace EE { namespace System { +SINGLETON_DECLARE_IMPLEMENTATION(cPackManager) + cPackManager::cPackManager() : mFallback( true ) { diff --git a/src/system/cpackmanager.hpp b/src/system/cpackmanager.hpp index 216b3495b..bda7fe9ce 100644 --- a/src/system/cpackmanager.hpp +++ b/src/system/cpackmanager.hpp @@ -8,8 +8,9 @@ namespace EE { namespace System { class EE_API cPackManager : public tContainer, public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cPackManager) + cPackManager(); virtual ~cPackManager(); diff --git a/src/system/tsingleton.hpp b/src/system/tsingleton.hpp index 1fd758c0b..9325d4807 100755 --- a/src/system/tsingleton.hpp +++ b/src/system/tsingleton.hpp @@ -2,19 +2,51 @@ #define EE_SYSTEMSINGLETON_H #include "../base.hpp" -#include + +#define SINGLETON_DECLARE_HEADERS( T ) \ + static T * CreateSingleton(); \ +\ + static T * ExistsSingleton(); \ +\ + static T * instance(); \ +\ + static void DestroySingleton(); + +#define SINGLETON_DECLARE_IMPLEMENTATION( T ) \ +template<> T* tSingleton::ms_singleton = NULL; \ +\ +T* T::CreateSingleton() { \ + if ( NULL == ms_singleton ) { \ + ms_singleton = eeNew( T, () ); \ + } \ +\ + return ms_singleton; \ +} \ +\ +T * T::ExistsSingleton() { \ + return ms_singleton; \ +} \ +\ +T * T::instance() { \ + return CreateSingleton(); \ +} \ +\ +void T::DestroySingleton() { \ + eeSAFE_DELETE(ms_singleton) ; \ +} namespace EE { namespace System { /** @brief Template class for only one instance classes. */ template class tSingleton { - static T* ms_singleton; + protected: + static T* ms_singleton; public: /** Get the singleton pointer */ static T* CreateSingleton() { - if (ms_singleton == 0) { + if ( NULL == ms_singleton ) { ms_singleton = eeNew( T, () ); } @@ -33,13 +65,9 @@ class tSingleton { /** Destroy the singleton instance */ static void DestroySingleton() { - if( ms_singleton != 0 ) { - eeDelete( ms_singleton ); - ms_singleton = 0; - } + eeSAFE_DELETE(ms_singleton); } }; -template T* tSingleton ::ms_singleton = 0; }} #endif diff --git a/src/ui/cuimanager.cpp b/src/ui/cuimanager.cpp index cd7c26b6e..f9bbf1125 100644 --- a/src/ui/cuimanager.cpp +++ b/src/ui/cuimanager.cpp @@ -3,6 +3,8 @@ namespace EE { namespace UI { +SINGLETON_DECLARE_IMPLEMENTATION(cUIManager) + cUIManager::cUIManager() : mWindow( NULL ), mKM( NULL ), diff --git a/src/ui/cuimanager.hpp b/src/ui/cuimanager.hpp index e12b45a04..a3ef070b4 100644 --- a/src/ui/cuimanager.hpp +++ b/src/ui/cuimanager.hpp @@ -9,8 +9,9 @@ namespace EE { namespace UI { class EE_API cUIManager : public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cUIManager) + cUIManager(); ~cUIManager(); diff --git a/src/ui/cuithememanager.cpp b/src/ui/cuithememanager.cpp index b303dc8a8..a5b437797 100644 --- a/src/ui/cuithememanager.cpp +++ b/src/ui/cuithememanager.cpp @@ -4,6 +4,8 @@ namespace EE { namespace UI { +SINGLETON_DECLARE_IMPLEMENTATION(cUIThemeManager) + cUIThemeManager::cUIThemeManager() : tResourceManager( true ), mFont( NULL ), diff --git a/src/ui/cuithememanager.hpp b/src/ui/cuithememanager.hpp index e8a8937a0..89b4f6207 100644 --- a/src/ui/cuithememanager.hpp +++ b/src/ui/cuithememanager.hpp @@ -9,8 +9,9 @@ namespace EE { namespace UI { class cUIControl; class EE_API cUIThemeManager : public tResourceManager, public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cUIThemeManager) + cUIThemeManager(); virtual ~cUIThemeManager(); diff --git a/src/window/cengine.cpp b/src/window/cengine.cpp index 37d40204a..c6bb266cb 100755 --- a/src/window/cengine.cpp +++ b/src/window/cengine.cpp @@ -32,6 +32,8 @@ namespace EE { namespace Window { +SINGLETON_DECLARE_IMPLEMENTATION(cEngine) + cEngine::cEngine() : mBackend( NULL ), mWindow( NULL ) diff --git a/src/window/cengine.hpp b/src/window/cengine.hpp index 31d97ff43..a10887d5e 100755 --- a/src/window/cengine.hpp +++ b/src/window/cengine.hpp @@ -9,8 +9,9 @@ namespace EE { namespace Window { /** @brief The window management class. Here the engine start working. (Singleton Class). */ class EE_API cEngine : public tSingleton { - friend class tSingleton; public: + SINGLETON_DECLARE_HEADERS(cEngine) + ~cEngine(); /** Creates a new window.