changeset 63:44dcff5abf12

Work on ServiceProvider
author koryspansel
date Tue, 04 Oct 2011 12:04:09 -0700
parents 6d4437a24aeb
children 3507bd831c7f
files LightClone/LightClone.vcproj LightClone/Source/InputManager.h LightClone/Source/Mediator.cpp LightClone/Source/Mediator.h LightClone/Source/ResourceManager.h LightClone/Source/Service.cpp LightClone/Source/Service.h LightClone/Source/ServiceProvider.cpp LightClone/Source/ServiceProvider.h LightClone/ToDo.txt
diffstat 10 files changed, 192 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/LightClone/LightClone.vcproj	Mon Oct 03 15:14:41 2011 -0700
+++ b/LightClone/LightClone.vcproj	Tue Oct 04 12:04:09 2011 -0700
@@ -306,6 +306,14 @@
 					>
 				</File>
 				<File
+					RelativePath=".\Source\Service.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\Source\ServiceProvider.cpp"
+					>
+				</File>
+				<File
 					RelativePath=".\Source\Trace.cpp"
 					>
 				</File>
@@ -480,6 +488,14 @@
 					>
 				</File>
 				<File
+					RelativePath=".\Source\Service.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Source\ServiceProvider.h"
+					>
+				</File>
+				<File
 					RelativePath=".\Source\Trace.h"
 					>
 				</File>
--- a/LightClone/Source/InputManager.h	Mon Oct 03 15:14:41 2011 -0700
+++ b/LightClone/Source/InputManager.h	Tue Oct 04 12:04:09 2011 -0700
@@ -8,6 +8,7 @@
 #define DIRECTINPUT_VERSION 0x0800
 #include <dinput.h>
 #include "Core.h"
+#include "Service.h"
 
 /*
  * MouseButton
@@ -23,7 +24,7 @@
 /*
  * InputManager
  */
-class InputManager
+class InputManager : public Service
 {
 	/*
 	 * pDirectInput
--- a/LightClone/Source/Mediator.cpp	Mon Oct 03 15:14:41 2011 -0700
+++ b/LightClone/Source/Mediator.cpp	Tue Oct 04 12:04:09 2011 -0700
@@ -84,53 +84,76 @@
 	InitializeTrace(TraceFlag_Debug | TraceFlag_File);
 
 	ErrorCode eCode = kWindow.Initialize();
-	if(eCode == Error_Success)
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to initialize window\n");
+
+		Terminate();
+		return eCode;
+	}
+
+	eCode = GraphicsDevice::Create(kWindow.GetHandle(), ScreenSizeX, ScreenSizeY, &pGraphicsDevice);
+	if(eCode != Error_Success)
 	{
-		ErrorCode eCode = GraphicsDevice::Create(kWindow.GetHandle(), ScreenSizeX, ScreenSizeY, &pGraphicsDevice);
-		if(eCode != Error_Success)
-		{
-			TRACE("Error: Failed to initialize graphics device\n");
-			
-			Terminate();
-			return Error_Fail;
-		}
+		TRACE("Error: Failed to initialize graphics device\n");
+		
+		Terminate();
+		return eCode;
+	}
+
+	eCode = kContext.Initialize(pGraphicsDevice);
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to initialize render context\n");
 
-		eCode = kContext.Initialize(pGraphicsDevice);
-		if(eCode != Error_Success)
-		{
-			TRACE("Error: Failed to initialize render context\n");
+		Terminate();
+		return eCode;
+	}
 
-			Terminate();
-			return Error_Fail;
-		}
+	eCode = kResourceManager.Initialize(pGraphicsDevice);
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to initialize resource manager\n");
+
+		Terminate();
+		return eCode;
+	}
 
-		eCode = kResourceManager.Initialize(pGraphicsDevice);
-		if(eCode != Error_Success)
-		{
-			TRACE("Error: Failed to initialize resource manager\n");
+	eCode = kInputManager.Initialize(kWindow.GetHandle());
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to initialize input manager\n");
+
+		Terminate();
+		return eCode;
+	}
 
-			Terminate();
-			return Error_Fail;
-		}
+	eCode = kWorld.Initialize(&kResourceManager, &kInputManager);
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to initialize world\n");
 
-		eCode = kInputManager.Initialize(kWindow.GetHandle());
-		if(eCode != Error_Success)
-		{
-			TRACE("Error: Failed to initialize input manager\n");
+		Terminate();
+		return eCode;
+	}
 
-			Terminate();
-			return Error_Fail;
-		}
+	eCode = kServiceProvider.AddService("ResourceManager", &kResourceManager);
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to add resource manager service\n");
+
+		Terminate();
+		return eCode;
+	}
 
-		eCode = kWorld.Initialize(&kResourceManager, &kInputManager);
-		if(eCode != Error_Success)
-		{
-			TRACE("Error: Failed to initialize world\n");
+	eCode = kServiceProvider.AddService("InputManager", &kInputManager);
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to add input manager service\n");
 
-			Terminate();
-			return Error_Fail;
-		}
-	}
+		Terminate();
+		return eCode;
+	}	
 	
 	return eCode;
 }
--- a/LightClone/Source/Mediator.h	Mon Oct 03 15:14:41 2011 -0700
+++ b/LightClone/Source/Mediator.h	Tue Oct 04 12:04:09 2011 -0700
@@ -13,6 +13,7 @@
 #include "ResourceManager.h"
 #include "RenderContext.h"
 #include "World.h"
+#include "ServiceProvider.h"
 
 /*
  * Mediator
@@ -50,6 +51,11 @@
 	InputManager kInputManager;
 
 	/*
+	 * kServiceProvider
+	 */
+	ServiceProvider kServiceProvider;
+
+	/*
 	 * kWorld
 	 */
 	World kWorld;
--- a/LightClone/Source/ResourceManager.h	Mon Oct 03 15:14:41 2011 -0700
+++ b/LightClone/Source/ResourceManager.h	Tue Oct 04 12:04:09 2011 -0700
@@ -9,6 +9,7 @@
 #include "GraphicsDevice.h"
 #include "FixedString.h"
 #include "HashMap.h"
+#include "Service.h"
 
 /*
  * ResourceType
@@ -31,7 +32,7 @@
 /*
  * ResourceManager
  */
-class ResourceManager
+class ResourceManager : public Service
 {
 	/*
 	 * TextureCache
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/Service.cpp	Tue Oct 04 12:04:09 2011 -0700
@@ -0,0 +1,12 @@
+/*
+ * Service
+ */
+
+#include "Service.h"
+
+/*
+ * ~Service
+ */
+Service::~Service()
+{
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/Service.h	Tue Oct 04 12:04:09 2011 -0700
@@ -0,0 +1,23 @@
+/*
+ * Service
+ */
+
+#ifndef __SERVICE_H__
+#define __SERVICE_H__
+
+#include "Types.h"
+
+/*
+ * Service
+ */
+class Service
+{
+public:
+
+	/*
+	 * ~Service
+	 */
+	virtual ~Service();
+};
+
+#endif //__SERVICE_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/ServiceProvider.cpp	Tue Oct 04 12:04:09 2011 -0700
@@ -0,0 +1,21 @@
+/*
+ * ServiceProvider
+ */
+
+#include "ServiceProvider.h"
+
+/*
+ * AddService
+ */
+ErrorCode ServiceProvider::AddService(const char* pName, Service* pService)
+{
+	return Error_Success;
+}
+
+/*
+ * GetService
+ */
+Service* ServiceProvider::GetService(const char* pName)
+{
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/ServiceProvider.h	Tue Oct 04 12:04:09 2011 -0700
@@ -0,0 +1,49 @@
+/*
+ * ServiceProvider
+ */
+
+#ifndef __SERVICEPROVIDER_H__
+#define __SERVICEPROVIDER_H__
+
+#include "Types.h"
+#include "Service.h"
+
+/*
+ * ServiceProvider
+ */
+class ServiceProvider
+{
+public:
+
+	/*
+	 * AddService
+	 */
+	ErrorCode AddService(const char* pName, Service* pService);
+
+	/*
+	 * GetService
+	 */
+	Service* GetService(const char* pName);
+
+	/*
+	 * GetService
+	 */
+	template<typename ServiceType>
+	ErrorCode GetService(const char* pName, Service** pService)
+	{
+		ErrorCode eCode = Error_Fail;
+
+		if(pService)
+		{
+			*pService = (ServiceType*)GetService(pName);
+			if(*pService)
+			{
+				eCode = Error_Success;
+			}
+		}
+
+		return eCode;
+	}
+};
+
+#endif //__SERVICEPROVIDER_H__
--- a/LightClone/ToDo.txt	Mon Oct 03 15:14:41 2011 -0700
+++ b/LightClone/ToDo.txt	Tue Oct 04 12:04:09 2011 -0700
@@ -3,7 +3,6 @@
 2.	Main menu
 3.	Pause menu
 4.	Additional maps
-5.	Add camera position to map
 
 Polish:
 1.	Button tool tips