浏览代码

Started porting stuff from singleton to module

Marko Pintera 13 年之前
父节点
当前提交
3a44bae9a6
共有 29 个文件被更改,包括 194 次插入142 次删除
  1. 4 4
      CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj
  2. 2 3
      CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp
  3. 4 4
      CamelotGLRenderer/CamelotGLRenderer.vcxproj
  4. 3 4
      CamelotGLRenderer/Source/CmGLRenderSystem.cpp
  5. 1 1
      CamelotGLRenderer/Source/CmGLTexture.cpp
  6. 5 0
      CamelotGLRenderer/Source/CmWin32Window.cpp
  7. 4 13
      CamelotGLRenderer/Source/GLSL/src/CmGLSLGpuProgram.cpp
  8. 2 0
      CamelotGLRenderer/Source/GLSL/src/CmGLSLProgram.cpp
  9. 5 0
      CamelotRenderer.sln
  10. 4 4
      CamelotRenderer/CamelotRenderer.vcxproj
  11. 0 2
      CamelotRenderer/Include/CmApplication.h
  12. 0 6
      CamelotRenderer/Include/CmRenderSystem.h
  13. 2 35
      CamelotRenderer/Include/CmTextureManager.h
  14. 3 1
      CamelotRenderer/Source/CmApplication.cpp
  15. 2 0
      CamelotRenderer/Source/CmFrustum.cpp
  16. 20 0
      CamelotRenderer/Source/CmGpuProgramParams.cpp
  17. 0 1
      CamelotRenderer/Source/CmRenderSystem.cpp
  18. 1 1
      CamelotRenderer/Source/CmRenderSystemManager.cpp
  19. 0 10
      CamelotRenderer/Source/CmTextureManager.cpp
  20. 3 2
      CamelotUtility/CamelotUtility.vcxproj
  21. 3 0
      CamelotUtility/CamelotUtility.vcxproj.filters
  22. 4 35
      CamelotUtility/Include/CmDynLibManager.h
  23. 6 5
      CamelotUtility/Include/CmException.h
  24. 93 0
      CamelotUtility/Include/CmModule.h
  25. 6 0
      CamelotUtility/Include/CmPrerequisitesUtil.h
  26. 2 0
      CamelotUtility/Source/CmDynLib.cpp
  27. 5 11
      CamelotUtility/Source/CmDynLibManager.cpp
  28. 2 0
      CamelotUtility/Source/CmPixelUtil.cpp
  29. 8 0
      Dependencies.txt

+ 4 - 4
CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj

@@ -48,13 +48,13 @@
     <ClCompile>
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;.\Include;..\CamelotRenderer\Include;..\CamelotUtility\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;.\Include;..\CamelotRenderer\Include;..\CamelotUtility\Include;..\Dependencies\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>CM_RSD3D9_EXPORTS;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <AdditionalDependencies>d3d9.lib;d3dx9.lib;DxErr.lib;dxguid.lib;CamelotRenderer.lib;%(AdditionalDependencies)</AdditionalDependencies>
-      <AdditionalLibraryDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;..\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <AdditionalLibraryDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;..\lib\$(Configuration);..\Dependencies\lib\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <ImportLibrary>..\lib\$(Configuration)\$(TargetName).lib</ImportLibrary>
     </Link>
   </ItemDefinitionGroup>
@@ -64,7 +64,7 @@
       <Optimization>MaxSpeed</Optimization>
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;.\Include;..\CamelotRenderer\Include;..\CamelotUtility\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;.\Include;..\CamelotRenderer\Include;..\CamelotUtility\Include;..\Dependencies\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>CM_RSD3D9_EXPORTS;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
     <Link>
@@ -72,7 +72,7 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
       <AdditionalDependencies>d3d9.lib;d3dx9.lib;DxErr.lib;dxguid.lib;CamelotRenderer.lib;%(AdditionalDependencies)</AdditionalDependencies>
-      <AdditionalLibraryDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;..\lib\$(Configuration)</AdditionalLibraryDirectories>
+      <AdditionalLibraryDirectories>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;..\lib\$(Configuration);..\Dependencies\lib\Release</AdditionalLibraryDirectories>
       <ImportLibrary>..\lib\$(Configuration)\$(TargetName).lib</ImportLibrary>
     </Link>
   </ItemDefinitionGroup>

+ 2 - 3
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -68,7 +68,6 @@ namespace CamelotEngine
 		mpD3D = NULL;		
 		mDriverList = NULL;
 		mActiveD3DDriver = NULL;
-		mTextureManager = NULL;
 		mHardwareBufferManager = NULL;
 		mGpuProgramManager = NULL;			
 		mUseNVPerfHUD = false;
@@ -512,7 +511,7 @@ namespace CamelotEngine
 		mDeviceManager = new D3D9DeviceManager();
 
 		// Create the texture manager for use by others		
-		mTextureManager = new D3D9TextureManager();
+		TextureManager::startUp(new D3D9TextureManager());
 
 		// Also create hardware buffer manager		
 		mHardwareBufferManager = new D3D9HardwareBufferManager();
@@ -623,7 +622,7 @@ namespace CamelotEngine
 		SAFE_DELETE( mDriverList );
 		mActiveD3DDriver = NULL;	
 						
-		SAFE_DELETE( mTextureManager );
+		TextureManager::shutDown();
 		SAFE_DELETE( mHardwareBufferManager );
 		SAFE_DELETE( mGpuProgramManager );			
 	}

+ 4 - 4
CamelotGLRenderer/CamelotGLRenderer.vcxproj

@@ -48,14 +48,14 @@
     <ClCompile>
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>./Source/win32;./Source/GLSL/include;./Source/atifs/include;../CamelotUtility/Include;../CamelotRenderer/Include;./Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>./Source/win32;./Source/GLSL/include;./Source/atifs/include;../CamelotUtility/Include;../CamelotRenderer/Include;./Include;../Dependencies/Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>_WINDLL;CM_RSGL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <AdditionalDependencies>glu32.lib;opengl32.lib;CamelotRenderer.lib;CamelotUtility.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <ImportLibrary>..lib\$(Configuration)\$(TargetName).lib</ImportLibrary>
-      <AdditionalLibraryDirectories>..\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <AdditionalLibraryDirectories>..\lib\$(Configuration);..\Dependencies\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -64,7 +64,7 @@
       <Optimization>MaxSpeed</Optimization>
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>./Source/win32;./Source/GLSL/include;./Source/atifs/include;../CamelotUtility/Include;../CamelotRenderer/Include;./Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>./Source/win32;./Source/GLSL/include;./Source/atifs/include;../CamelotUtility/Include;../CamelotRenderer/Include;./Include;../Dependencies/Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>_WINDLL;CM_RSGL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
     <Link>
@@ -73,7 +73,7 @@
       <OptimizeReferences>true</OptimizeReferences>
       <AdditionalDependencies>glu32.lib;opengl32.lib;CamelotRenderer.lib;CamelotUtility.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <ImportLibrary>..lib\$(Configuration)\$(TargetName).lib</ImportLibrary>
-      <AdditionalLibraryDirectories>..\lib\$(Configuration)</AdditionalLibraryDirectories>
+      <AdditionalLibraryDirectories>..\lib\$(Configuration);..\Dependencies\Debug</AdditionalLibraryDirectories>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>

+ 3 - 4
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -827,7 +827,7 @@ namespace CamelotEngine {
 		}
 
 		/// Create the texture manager        
-		mTextureManager = new GLTextureManager(*mGLSupport); 
+		TextureManager::startUp(new GLTextureManager(*mGLSupport)); 
 
 		mGLInitialised = true;
 	}
@@ -877,8 +877,7 @@ namespace CamelotEngine {
 		mGLSupport->stop();
 		mStopRendering = true;
 
-		delete mTextureManager;
-		mTextureManager = 0;
+		TextureManager::shutDown();
 
 		// There will be a new initial window and so forth, thus any call to test
 		//  some params will access an invalid pointer, so it is best to reset
@@ -1290,7 +1289,7 @@ namespace CamelotEngine {
 				glBindTexture( mTextureTypes[stage], tex->getGLID() );
 			else
 			{
-				glBindTexture( mTextureTypes[stage], static_cast<GLTextureManager*>(mTextureManager)->getWarningTextureID() );
+				glBindTexture( mTextureTypes[stage], static_cast<GLTextureManager*>(&TextureManager::instance())->getWarningTextureID() );
 			}
 		}
 		else

+ 1 - 1
CamelotGLRenderer/Source/CmGLTexture.cpp

@@ -96,7 +96,7 @@ namespace CamelotEngine {
 		
 
 		// Adjust format if required
-		mFormat = TextureManager::getSingleton().getNativeFormat(mTextureType, mFormat, mUsage);
+		mFormat = TextureManager::instance().getNativeFormat(mTextureType, mFormat, mUsage);
 		
 		// Check requested number of mipmaps
 		size_t maxMips = GLPixelUtil::getMaxMipmaps(mWidth, mHeight, mDepth, mFormat);

+ 5 - 0
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -406,11 +406,16 @@ namespace CamelotEngine {
 		{
 			mGlrc = wglCreateContext(mHDC);
 			if (!mGlrc)
+			{
 				CM_EXCEPT(RenderingAPIException, 
 				"wglCreateContext failed: " + translateWGLError());
+			}
 		}
+
 		if (!wglMakeCurrent(mHDC, mGlrc))
+		{
 			CM_EXCEPT(RenderingAPIException, "wglMakeCurrent");
+		}
 
 		// Do not change vsync if the external window has the OpenGL control
 		if (!mIsExternalGLControl) {

+ 4 - 13
CamelotGLRenderer/Source/GLSL/src/CmGLSLGpuProgram.cpp

@@ -123,19 +123,10 @@ namespace CamelotEngine {
 	//-----------------------------------------------------------------------------
 	void GLSLGpuProgram::bindProgramParameters(GpuProgramParametersSharedPtr params, UINT16 mask)
 	{
-		// link can throw exceptions, ignore them at this point
-		try
-		{
-			// activate the link program object
-			GLSLLinkProgram* linkProgram = GLSLLinkProgramManager::getSingleton().getActiveLinkProgram();
-			// pass on parameters from params to program object uniforms
-			linkProgram->updateUniforms(params, mask, mType);
-		}
-		catch (Exception& e) 
-		{
-			throw;
-		}
-	
+		// activate the link program object
+		GLSLLinkProgram* linkProgram = GLSLLinkProgramManager::getSingleton().getActiveLinkProgram();
+		// pass on parameters from params to program object uniforms
+		linkProgram->updateUniforms(params, mask, mType);
 	}
 
 	//-----------------------------------------------------------------------------

+ 2 - 0
CamelotGLRenderer/Source/GLSL/src/CmGLSLProgram.cpp

@@ -129,9 +129,11 @@ namespace CamelotEngine {
 		size_t src_len = mSource.size ();
 		char *out = cpp.Parse (src, src_len, out_size);
 		if (!out || !out_size)
+		{
 			// Failed to preprocess, break out
 			CM_EXCEPT(RenderingAPIException,
 						 "Failed to preprocess shader ");
+		}
 
 		mSource = String (out, out_size);
 		if (out < src || out > src + src_len)

+ 5 - 0
CamelotRenderer.sln

@@ -23,6 +23,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CamelotGLRenderer", "Camelo
 		{9B21D41C-516B-43BF-9B10-E99B599C7589} = {9B21D41C-516B-43BF-9B10-E99B599C7589}
 	EndProjectSection
 EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1D081E5A-615A-4C06-B2DF-0D8D9390DE02}"
+	ProjectSection(SolutionItems) = preProject
+		Dependencies.txt = Dependencies.txt
+	EndProjectSection
+EndProject
 Global
 	GlobalSection(SubversionScc) = preSolution
 		Svn-Managed = True

+ 4 - 4
CamelotRenderer/CamelotRenderer.vcxproj

@@ -58,13 +58,13 @@
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;CM_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>./Include;../CamelotUtility/Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>./Include;../CamelotUtility/Include;../Dependencies/Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>NotSet</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <AdditionalDependencies>CamelotUtility.lib;%(AdditionalDependencies)</AdditionalDependencies>
-      <AdditionalLibraryDirectories>../lib/$(Configuration)</AdditionalLibraryDirectories>
+      <AdditionalLibraryDirectories>../lib/$(Configuration);../Dependencies/lib/Debug</AdditionalLibraryDirectories>
       <ImportLibrary>..\lib\$(Configuration)\$(TargetName).lib</ImportLibrary>
     </Link>
   </ItemDefinitionGroup>
@@ -77,7 +77,7 @@
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;CM_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>./Include;../CamelotUtility/Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>./Include;../CamelotUtility/Include;../Dependencies/Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>NotSet</SubSystem>
@@ -85,7 +85,7 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
       <AdditionalDependencies>CamelotUtility.lib;%(AdditionalDependencies)</AdditionalDependencies>
-      <AdditionalLibraryDirectories>../lib/$(Configuration)</AdditionalLibraryDirectories>
+      <AdditionalLibraryDirectories>../lib/$(Configuration);../Dependencies/lib/Release</AdditionalLibraryDirectories>
       <ImportLibrary>..\lib\$(Configuration)\$(TargetName).lib</ImportLibrary>
     </Link>
   </ItemDefinitionGroup>

+ 0 - 2
CamelotRenderer/Include/CmApplication.h

@@ -31,8 +31,6 @@ namespace CamelotEngine
 			Camera* mCamera;
 			HighLevelGpuProgramPtr mFragProg;
 			HighLevelGpuProgramPtr mVertProg;
-
-			DynLibManager* mDynLibManager; // TODO - Handle singletons differently
 	};
 
 	CM_EXPORT Application& gApplication();

+ 0 - 6
CamelotRenderer/Include/CmRenderSystem.h

@@ -1306,12 +1306,6 @@ namespace CamelotEngine
 		GpuProgramParametersSharedPtr mActiveGeometryGpuProgramParameters;
 		GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters;
 
-		// Texture manager
-		// A concrete class of this will be created and
-		// made available under the TextureManager singleton,
-		// managed by the RenderSystem
-		TextureManager* mTextureManager;
-
 		// Active viewport (dest for future rendering operations)
 		Viewport* mActiveViewport;
 

+ 2 - 35
CamelotRenderer/Include/CmTextureManager.h

@@ -32,7 +32,7 @@ THE SOFTWARE.
 #include "CmPrerequisites.h"
 
 #include "CmTexture.h"
-#include "CmSingleton.h"
+#include "CmModule.h"
 
 
 namespace CamelotEngine {
@@ -56,7 +56,7 @@ namespace CamelotEngine {
             created at least one window - this may be done at the
             same time as part a if you allow Ogre to autocreate one.
      */
-    class CM_EXPORT TextureManager : public Singleton<TextureManager>
+    class CM_EXPORT TextureManager : public Module<TextureManager>
     {
 		protected:
 			virtual Texture* createImpl() = 0;
@@ -281,39 +281,6 @@ namespace CamelotEngine {
             return mDefaultNumMipmaps;
         }
 
-        /** Override standard Singleton retrieval.
-        @remarks
-        Why do we do this? Well, it's because the Singleton
-        implementation is in a .h file, which means it gets compiled
-        into anybody who includes it. This is needed for the
-        Singleton template to work, but we actually only want it
-        compiled into the implementation of the class based on the
-        Singleton, not all of them. If we don't change this, we get
-        link errors when trying to use the Singleton-based class from
-        an outside dll.
-        @par
-        This method just delegates to the template version anyway,
-        but the implementation stays in this single compilation unit,
-        preventing link errors.
-        */
-        static TextureManager& getSingleton(void);
-        /** Override standard Singleton retrieval.
-        @remarks
-        Why do we do this? Well, it's because the Singleton
-        implementation is in a .h file, which means it gets compiled
-        into anybody who includes it. This is needed for the
-        Singleton template to work, but we actually only want it
-        compiled into the implementation of the class based on the
-        Singleton, not all of them. If we don't change this, we get
-        link errors when trying to use the Singleton-based class from
-        an outside dll.
-        @par
-        This method just delegates to the template version anyway,
-        but the implementation stays in this single compilation unit,
-        preventing link errors.
-        */
-        static TextureManager* getSingletonPtr(void);
-
     protected:
 
         UINT16 mPreferredIntegerBitDepth;

+ 3 - 1
CamelotRenderer/Source/CmApplication.cpp

@@ -21,7 +21,7 @@ namespace CamelotEngine
 	void Application::startUp(String renderSystemDll)
 	{
 		mGpuProgramManager = new HighLevelGpuProgramManager(); // TODO - Use Camelot::Module for instantiating this
-		mDynLibManager = new DynLibManager(); // TODO - Same as above, use Module
+		DynLibManager::startUp(new DynLibManager());
 
 		RenderSystemManager::initialize(renderSystemDll);
 
@@ -99,6 +99,8 @@ namespace CamelotEngine
 
 		if(mGpuProgramManager != nullptr)
 			delete mGpuProgramManager;
+
+		DynLibManager::shutDown();
 	}
 
 	void Application::DBG_renderSimpleFrame()

+ 2 - 0
CamelotRenderer/Source/CmFrustum.cpp

@@ -102,7 +102,9 @@ namespace CamelotEngine {
     void Frustum::setNearClipDistance(float nearPlane)
     {
         if (nearPlane <= 0)
+		{
             CM_EXCEPT(InvalidParametersException, "Near clip distance must be greater than zero.");
+		}
         mNearDist = nearPlane;
         invalidateFrustum();
     }

+ 20 - 0
CamelotRenderer/Source/CmGpuProgramParams.cpp

@@ -1122,8 +1122,10 @@ namespace CamelotEngine
 	GpuLogicalIndexUse* GpuProgramParameters::_getIntConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, UINT16 variability)
 	{
 		if (mIntLogicalToPhysical == nullptr)
+		{
 			CM_EXCEPT(InvalidParametersException, 
 			"This is not a low-level parameter parameter object");
+		}
 
 		GpuLogicalIndexUse* indexUse = 0;
 		CM_LOCK_MUTEX(mIntLogicalToPhysical->mutex)
@@ -1267,8 +1269,10 @@ namespace CamelotEngine
 	GpuConstantDefinitionIterator GpuProgramParameters::getConstantDefinitionIterator(void) const
 	{
 		if (mNamedConstants == nullptr)
+		{
 			CM_EXCEPT(InvalidParametersException, 
 			"This params object is not based on a program with named parameters.");
+		}
 
 		return mNamedConstants->map.begin();
 
@@ -1277,8 +1281,10 @@ namespace CamelotEngine
 	const GpuNamedConstants& GpuProgramParameters::getConstantDefinitions() const
 	{
 		if (mNamedConstants == nullptr)
+		{
 			CM_EXCEPT(InvalidParametersException, 
 			"This params object is not based on a program with named parameters.");
+		}
 
 		return *mNamedConstants;
 	}
@@ -1286,8 +1292,10 @@ namespace CamelotEngine
 	const GpuConstantDefinition& GpuProgramParameters::getConstantDefinition(const String& name) const
 	{
 		if (mNamedConstants == nullptr)
+		{
 			CM_EXCEPT(InvalidParametersException, 
 			"This params object is not based on a program with named parameters.");
+		}
 
 
 		// locate, and throw exception if not found
@@ -1304,8 +1312,11 @@ namespace CamelotEngine
 		if (mNamedConstants == nullptr)
 		{
 			if (throwExceptionIfNotFound)
+			{
 				CM_EXCEPT(InvalidParametersException, 
 				"Named constants have not been initialised, perhaps a compile error.");
+			}
+
 			return 0;
 		}
 
@@ -1313,8 +1324,11 @@ namespace CamelotEngine
 		if (i == mNamedConstants->map.end())
 		{
 			if (throwExceptionIfNotFound)
+			{
 				CM_EXCEPT(InvalidParametersException, 
 				"Parameter called " + name + " does not exist. ");
+			}
+
 			return 0;
 		}
 		else
@@ -1659,8 +1673,10 @@ namespace CamelotEngine
 		GpuProgramParameters::findFloatAutoConstantEntry(size_t logicalIndex)
 	{
 		if (mFloatLogicalToPhysical == nullptr)
+		{
 			CM_EXCEPT(InvalidParametersException, 
 			"This is not a low-level parameter parameter object");
+		}
 
 		return _findRawAutoConstantEntryFloat(
 			_getFloatConstantPhysicalIndex(logicalIndex, 0, GPV_GLOBAL));
@@ -1671,8 +1687,10 @@ namespace CamelotEngine
 		GpuProgramParameters::findIntAutoConstantEntry(size_t logicalIndex)
 	{
 		if (mIntLogicalToPhysical == nullptr)
+		{
 			CM_EXCEPT(InvalidParametersException, 
 			"This is not a low-level parameter parameter object");
+		}
 
 		return _findRawAutoConstantEntryInt(
 			_getIntConstantPhysicalIndex(logicalIndex, 0, GPV_GLOBAL));
@@ -1684,8 +1702,10 @@ namespace CamelotEngine
 		GpuProgramParameters::findAutoConstantEntry(const String& paramName)
 	{
 		if (mNamedConstants == nullptr)
+		{
 			CM_EXCEPT(InvalidParametersException, 
 			"This params object is not based on a program with named parameters.");
+		}
 
 		const GpuConstantDefinition& def = getConstantDefinition(paramName);
 		if (def.isFloat())

+ 0 - 1
CamelotRenderer/Source/CmRenderSystem.cpp

@@ -47,7 +47,6 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     RenderSystem::RenderSystem()
         : mActiveRenderTarget(0)
-        , mTextureManager(0)
         , mActiveViewport(0)
         // This means CULL clockwise vertices, i.e. front of poly is counter-clockwise
         // This makes it the same as OpenGL and other right-handed systems

+ 1 - 1
CamelotRenderer/Source/CmRenderSystemManager.cpp

@@ -10,7 +10,7 @@ namespace CamelotEngine
 
 	void RenderSystemManager::initialize(const String& pluginFilename)
 	{
-		DynLib* loadedLibrary = DynLibManager::getSingleton().load(pluginFilename);
+		DynLib* loadedLibrary = gDynLibManager().load(pluginFilename);
 		String name = "";
 
 		if(loadedLibrary != nullptr)

+ 0 - 10
CamelotRenderer/Source/CmTextureManager.cpp

@@ -30,16 +30,6 @@ THE SOFTWARE.
 #include "CmPixelUtil.h"
 
 namespace CamelotEngine {
-    //-----------------------------------------------------------------------
-    template<> TextureManager* Singleton<TextureManager>::ms_Singleton = 0;
-    TextureManager* TextureManager::getSingletonPtr(void)
-    {
-        return ms_Singleton;
-    }
-    TextureManager& TextureManager::getSingleton(void)
-    {  
-        assert( ms_Singleton );  return ( *ms_Singleton );  
-    }
     //-----------------------------------------------------------------------
     TextureManager::TextureManager(void)
          : mPreferredIntegerBitDepth(0)

+ 3 - 2
CamelotUtility/CamelotUtility.vcxproj

@@ -48,7 +48,7 @@
     <ClCompile>
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>Include</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>./Include;../Dependencies/Include</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>CM_EXPORTS</PreprocessorDefinitions>
     </ClCompile>
     <Link>
@@ -62,7 +62,7 @@
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>CM_EXPORTS</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>Include</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>./Include;../Dependencies/Include</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>
@@ -77,6 +77,7 @@
     <ClInclude Include="Include\CmDynLibManager.h" />
     <ClInclude Include="Include\CmException.h" />
     <ClInclude Include="Include\CmMathAsm.h" />
+    <ClInclude Include="Include\CmModule.h" />
     <ClInclude Include="Include\CmPixelUtil.h" />
     <ClInclude Include="Include\CmSingleton.h" />
     <ClInclude Include="Include\CmString.h" />

+ 3 - 0
CamelotUtility/CamelotUtility.vcxproj.filters

@@ -108,6 +108,9 @@
     <ClInclude Include="Include\CmSingleton.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\CmModule.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Include\CmAxisAlignedBox.cpp">

+ 4 - 35
CamelotUtility/Include/CmDynLibManager.h

@@ -28,7 +28,7 @@ THE SOFTWARE.
 #pragma once
 
 #include "CmPrerequisitesUtil.h"
-#include "CmSingleton.h"
+#include "CmModule.h"
 
 namespace CamelotEngine {
 	/** \addtogroup Core
@@ -43,7 +43,7 @@ namespace CamelotEngine {
             libraries, opens them and returns references to already-open
             libraries.
     */
-    class CM_EXPORT DynLibManager: public Singleton<DynLibManager>
+    class CM_EXPORT DynLibManager: public Module<DynLibManager>
     {
 	protected:
 		typedef map<String, DynLib*>::type DynLibList;
@@ -75,40 +75,9 @@ namespace CamelotEngine {
 		filename The name of the library. The extension can be omitted
 		*/
 		void unload(DynLib* lib);
-
-		/** Override standard Singleton retrieval.
-        @remarks
-        Why do we do this? Well, it's because the Singleton
-        implementation is in a .h file, which means it gets compiled
-        into anybody who includes it. This is needed for the
-        Singleton template to work, but we actually only want it
-        compiled into the implementation of the class based on the
-        Singleton, not all of them. If we don't change this, we get
-        link errors when trying to use the Singleton-based class from
-        an outside dll.
-        @par
-        This method just delegates to the template version anyway,
-        but the implementation stays in this single compilation unit,
-        preventing link errors.
-        */
-        static DynLibManager& getSingleton(void);
-        /** Override standard Singleton retrieval.
-        @remarks
-        Why do we do this? Well, it's because the Singleton
-        implementation is in a .h file, which means it gets compiled
-        into anybody who includes it. This is needed for the
-        Singleton template to work, but we actually only want it
-        compiled into the implementation of the class based on the
-        Singleton, not all of them. If we don't change this, we get
-        link errors when trying to use the Singleton-based class from
-        an outside dll.
-        @par
-        This method just delegates to the template version anyway,
-        but the implementation stays in this single compilation unit,
-        preventing link errors.
-        */
-        static DynLibManager* getSingletonPtr(void);
     };
+
+	DynLibManager& gDynLibManager();
 	/** @} */
 	/** @} */
 }

+ 6 - 5
CamelotUtility/Include/CmException.h

@@ -2,8 +2,8 @@
 
 #include "CmPrerequisitesUtil.h"
 
-//#include <boost/static_assert.hpp>
-//#include <boost/type_traits.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/type_traits.hpp>
 
 #if defined(_MSC_VER)
 #undef __PRETTY_FUNCTION__
@@ -133,9 +133,10 @@ namespace CamelotEngine
 	// TODO - Temporarily disabled until I include boost
 #ifndef CM_EXCEPT
 #define CM_EXCEPT(type, desc)	\
-	throw type##(desc, __PRETTY_FUNCTION__, __FILE__, __LINE__);
-//	BOOST_STATIC_ASSERT_MSG((boost::is_base_of<CamelotEngine::Exception, type##>::value), "Invalid exception type (" #type ") for CM_EXCEPT macro. It needs to derive from CamelotEngine::Exception."); \
-//	throw type##(desc, __PRETTY_FUNCTION__, __FILE__, __LINE__);
+	{                           \
+	BOOST_STATIC_ASSERT_MSG((boost::is_base_of<CamelotEngine::Exception, type##>::value), "Invalid exception type (" #type ") for CM_EXCEPT macro. It needs to derive from CamelotEngine::Exception."); \
+	throw type##(desc, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
+	}
 #endif
 }
 

+ 93 - 0
CamelotUtility/Include/CmModule.h

@@ -0,0 +1,93 @@
+#pragma once
+
+#include "CmPrerequisitesUtil.h"
+#include "CmException.h"
+
+namespace CamelotEngine
+{
+	/**
+	 * @brief	Represents one engine module. Essentially it is a specialized type of singleton.
+	 */
+	template <class T> // TODO - Make it thread safe
+	class Module
+	{
+	public:
+		static T& instance()
+		{
+			if(isShutDown)
+			{
+				CM_EXCEPT(InternalErrorException, 
+					"Trying to access a module but it hasn't been started up yet.");
+			}
+
+			if(isDestroyed)
+			{
+				CM_EXCEPT(InternalErrorException, 
+					"Trying to access a destroyed module.");
+			}
+
+			return *_instance;
+		}
+
+		/**
+		 * @brief	Initializes the module.
+		 *
+		 * @param [in]	moduleInstance Instantiated module. Module takes ownership of instance memory
+		 * 								and releases it when shutDown is called.
+		 */
+		static void startUp(T* moduleInstance)
+		{
+			if(!isShutDown)
+			{
+				CM_EXCEPT(InternalErrorException, 
+					"Trying to start an already started module.");
+			}
+
+			_instance = moduleInstance;
+			isShutDown = false;
+		}
+
+		/**
+		 * @brief	Shuts down this module and frees any resources it is using.
+		 */
+		static void shutDown()
+		{
+			if(isShutDown)
+			{
+				CM_EXCEPT(InternalErrorException, 
+					"Trying to shut down an already shut down module.");
+			}
+
+			delete _instance;
+			isShutDown = true;
+		}
+
+	protected:
+		Module() 
+		{ 
+		}
+
+		virtual ~Module()
+		{ 
+			_instance = nullptr;
+			isDestroyed = true;
+		}
+
+		Module(const Module&) { }
+		Module& operator=(const Module&) { return *this; }
+
+	private:
+		static T* _instance;
+		static bool isShutDown;
+		static bool isDestroyed;
+	};
+
+	template <class T>
+	T* Module<T>::_instance = nullptr;
+
+	template <class T>
+	bool Module<T>::isShutDown = true;
+
+	template <class T>
+	bool Module<T>::isDestroyed = false;
+}

+ 6 - 0
CamelotUtility/Include/CmPrerequisitesUtil.h

@@ -32,6 +32,12 @@ THE SOFTWARE
 
 #if CM_COMPILER == CM_COMPILER_MSVC
 
+// TODO - This is not deactivated anywhere, therefore it applies to any file that includes this header.
+//      - Right now I don't have an easier way to apply these warnings globally so I'm keeping it this way.
+
+// Secure versions aren't multiplatform, so we won't be using them
+#define _CRT_SECURE_NO_WARNINGS
+
 // disable: "<type> needs to have dll-interface to be used by clients'
 // Happens on STL member variables which are not public therefore is ok
 #   pragma warning (disable : 4251)

+ 2 - 0
CamelotUtility/Source/CmDynLib.cpp

@@ -78,9 +78,11 @@ namespace CamelotEngine {
         m_hInst = (DYNLIB_HANDLE)DYNLIB_LOAD( name.c_str() );
 
         if( !m_hInst )
+		{
             CM_EXCEPT(InternalErrorException, 
                 "Could not load dynamic library " + mName + 
                 ".  System Error: " + dynlibError());
+		}
     }
 
     //-----------------------------------------------------------------------

+ 5 - 11
CamelotUtility/Source/CmDynLibManager.cpp

@@ -30,17 +30,6 @@ THE SOFTWARE.
 
 namespace CamelotEngine
 {
-    //-----------------------------------------------------------------------
-    template<> DynLibManager* Singleton<DynLibManager>::ms_Singleton = 0;
-    DynLibManager* DynLibManager::getSingletonPtr(void)
-    {
-        return ms_Singleton;
-    }
-	//-----------------------------------------------------------------------
-    DynLibManager& DynLibManager::getSingleton(void)
-    {  
-        assert( ms_Singleton );  return ( *ms_Singleton );  
-    }
     //-----------------------------------------------------------------------
 	DynLibManager::DynLibManager()
 	{
@@ -85,4 +74,9 @@ namespace CamelotEngine
         // Empty the list
         mLibList.clear();
     }
+
+	DynLibManager& gDynLibManager()
+	{
+		return DynLibManager::instance();
+	}
 }

+ 2 - 0
CamelotUtility/Source/CmPixelUtil.cpp

@@ -953,7 +953,9 @@ namespace CamelotEngine {
 			CM_EXCEPT(InvalidParametersException, "Cannot return subvolume of compressed PixelBuffer");
 		}
 		if(!contains(def))
+		{
 			CM_EXCEPT(InvalidParametersException, "Bounds out of range");
+		}
 
 		const size_t elemSize = PixelUtil::getNumElemBytes(format);
 		// Calculate new data origin

+ 8 - 0
Dependencies.txt

@@ -0,0 +1,8 @@
+Camelot relies on following 3rd party libraries:
+ - Boost 1.49
+
+
+Make sure to include:
+ - Library include file in /Dependencies/Include
+ - Static library files in /Dependencies/lib/Debug and /Dependencies/lib/Release
+ - Dynamic library files in /bin/Debug and /bin/Release (Possibly others if you define other configuration types)