changeset 49:48705dc6e568

Fix window issues; Start on GuiRenderContext
author koryspansel
date Fri, 23 Sep 2011 16:54:51 -0700
parents 4663f93aefc4
children 7ff46a00bcd3
files .hgignore Data/Maps/map03.map Extern/D3DCompiler_43.dll Extern/D3DX9_43.dll Extern/msvcm90.dll Extern/msvcrt.dll LightClone/LightClone.vcproj LightClone/Source/Environment.cpp LightClone/Source/GraphicsDevice.cpp LightClone/Source/GuiInterface.cpp LightClone/Source/GuiInterface.h LightClone/Source/GuiRenderContext.cpp LightClone/Source/GuiRenderContext.h LightClone/Source/Mediator.cpp LightClone/Source/Trace.cpp LightClone/Source/Window.cpp LightClone/Source/World.cpp LightTools/release.py Release/LightClone201109220236PM.zip
diffstat 19 files changed, 398 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Sep 23 11:50:59 2011 -0700
+++ b/.hgignore	Fri Sep 23 16:54:51 2011 -0700
@@ -12,4 +12,5 @@
 Bin\*
 Intermediate\*
 LightTools\Build\*
-Release\*.rar
\ No newline at end of file
+Release\*.rar
+Release\*.zip
Binary file Data/Maps/map03.map has changed
Binary file Extern/D3DCompiler_43.dll has changed
Binary file Extern/D3DX9_43.dll has changed
Binary file Extern/msvcm90.dll has changed
Binary file Extern/msvcrt.dll has changed
--- a/LightClone/LightClone.vcproj	Fri Sep 23 11:50:59 2011 -0700
+++ b/LightClone/LightClone.vcproj	Fri Sep 23 16:54:51 2011 -0700
@@ -259,6 +259,10 @@
 					RelativePath=".\Source\GuiLabel.cpp"
 					>
 				</File>
+				<File
+					RelativePath=".\Source\GuiRenderContext.cpp"
+					>
+				</File>
 			</Filter>
 			<Filter
 				Name="Core"
@@ -401,6 +405,10 @@
 					RelativePath=".\Source\GuiLabel.h"
 					>
 				</File>
+				<File
+					RelativePath=".\Source\GuiRenderContext.h"
+					>
+				</File>
 			</Filter>
 			<Filter
 				Name="Core"
--- a/LightClone/Source/Environment.cpp	Fri Sep 23 11:50:59 2011 -0700
+++ b/LightClone/Source/Environment.cpp	Fri Sep 23 16:54:51 2011 -0700
@@ -46,6 +46,14 @@
 				eCode = SetupVertexBuffer();
 			}
 		}
+		else
+		{
+			TRACE("Error: Failed to load Data\\Textures\\Block04.tga\n");
+		}
+	}
+	else
+	{
+		TRACE("Error: Failed to load Data\\Shaders\\Environment.fx\n");
 	}
 
 	return eCode;
--- a/LightClone/Source/GraphicsDevice.cpp	Fri Sep 23 11:50:59 2011 -0700
+++ b/LightClone/Source/GraphicsDevice.cpp	Fri Sep 23 16:54:51 2011 -0700
@@ -55,8 +55,8 @@
 			nHeight,
 			D3DFMT_UNKNOWN,
 			1,
-			D3DMULTISAMPLE_4_SAMPLES,
-			1,
+			D3DMULTISAMPLE_NONE,
+			0,
 			D3DSWAPEFFECT_DISCARD,
 			kWindow,
 			TRUE,
@@ -71,24 +71,78 @@
 		IDirect3D9* pContext = Direct3DCreate9(D3D_SDK_VERSION);
 		if(pContext)
 		{
-			TRACE("    Success!\n");
-			IDirect3DDevice9* pDevice = NULL;
-
-			TRACE("  Creating DirectX device\n");
-			HRESULT hResult = pContext->CreateDevice(nAdapter, D3DDEVTYPE_HAL, kWindow, nFlags, &kParameters, &pDevice);
+			D3DCAPS9 kDeviceCaps;
+			HRESULT hResult = pContext->GetDeviceCaps(nAdapter, D3DDEVTYPE_HAL, &kDeviceCaps);
 			if(SUCCEEDED(hResult))
 			{
-				TRACE("    Success!\n");
-				TRACE("  Initializing vertex types\n");
+				if(!(kDeviceCaps.RasterCaps & D3DPRASTERCAPS_ANISOTROPY))
+				{
+					TRACE("Device does not support anistropic filtering\n");
+				}
+
+				if(kDeviceCaps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY)
+				{
+					TRACE("Device does not support non-square textures\n");
+				}
 
-				eCode = InitializeVertexTypes(pDevice);
-				if(eCode == Error_Success)
+				if(!(kDeviceCaps.TextureCaps & D3DPTEXTURECAPS_POW2))
 				{
-					TRACE("    Success!\n");
-					*pInstance = new GraphicsDevice(pContext, pDevice, kParameters);
+					if(!(kDeviceCaps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
+					{
+						TRACE("Device may not support non-power-of-two textures\n");
+					}
+					else
+					{
+						TRACE("Device does not support non-power-of-two textures\n");
+					}
 				}
 
-				pDevice->Release();
+				TRACE("Vertex Shader Version: %d\n", kDeviceCaps.VertexShaderVersion);
+				TRACE("Pixel Shader Version: %d\n", kDeviceCaps.PixelShaderVersion);
+
+				D3DDISPLAYMODE kMode;
+				hResult = pContext->GetAdapterDisplayMode(nAdapter, &kMode);
+				if(SUCCEEDED(hResult))
+				{
+					kParameters.BackBufferFormat = kMode.Format;
+
+					DWORD nQuality = 0;
+					hResult = pContext->CheckDeviceMultiSampleType(nAdapter, D3DDEVTYPE_HAL, kMode.Format, TRUE, D3DMULTISAMPLE_4_SAMPLES, &nQuality);
+					if(SUCCEEDED(hResult))
+					{
+						kParameters.MultiSampleType		= D3DMULTISAMPLE_4_SAMPLES;
+						kParameters.MultiSampleQuality	= nQuality - 1;
+					}
+					else
+					{
+						TRACE("4X FSAA is not supported\n");
+					}
+
+					TRACE("    Success!\n");
+					IDirect3DDevice9* pDevice = NULL;
+
+					TRACE("  Creating DirectX device\n");
+					HRESULT hResult = pContext->CreateDevice(nAdapter, D3DDEVTYPE_HAL, kWindow, nFlags, &kParameters, &pDevice);
+					if(SUCCEEDED(hResult))
+					{
+						TRACE("    Success!\n");
+						TRACE("  Initializing vertex types\n");
+
+						eCode = InitializeVertexTypes(pDevice);
+						if(eCode == Error_Success)
+						{
+							TRACE("    Success!\n");
+							*pInstance = new GraphicsDevice(pContext, pDevice, kParameters);
+						}
+
+						pDevice->Release();
+					}
+				}
+				else
+				{
+					TRACE("Failed to acquire device capabilities\n");
+
+				}
 			}
 
 			pContext->Release();
--- a/LightClone/Source/GuiInterface.cpp	Fri Sep 23 11:50:59 2011 -0700
+++ b/LightClone/Source/GuiInterface.cpp	Fri Sep 23 16:54:51 2011 -0700
@@ -161,8 +161,7 @@
  */
 void GuiInterface::Render(RenderContext& kContext, Camera& kCamera)
 {
-	//TODO: Begin batch
-	//kContext.BeginBatch();
+	//kRenderContext.Begin(&kContext, &kCamera);
 
 	if(nFlags & GuiElementFlag_Visible)
 	{
@@ -184,8 +183,7 @@
 		}
 	}
 
-	//TODO: End batch
-	//kContext.EndBatch()
+	//kRenderContext.End();
 }
 
 /*
--- a/LightClone/Source/GuiInterface.h	Fri Sep 23 11:50:59 2011 -0700
+++ b/LightClone/Source/GuiInterface.h	Fri Sep 23 16:54:51 2011 -0700
@@ -8,6 +8,7 @@
 #include "Core.h"
 #include "GuiElement.h"
 #include "GuiCursor.h"
+#include "GuiRenderContext.h"
 #include "InputManager.h"
 
 /*
@@ -21,6 +22,11 @@
 	InputManager* pInputManager;
 
 	/*
+	 * kRenderContext
+	 */
+	GuiRenderContext kRenderContext;
+
+	/*
 	 * pCursor
 	 */
 	GuiCursor* pCursor;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/GuiRenderContext.cpp	Fri Sep 23 16:54:51 2011 -0700
@@ -0,0 +1,135 @@
+/*
+ * RenderContext
+ */
+
+#include "GuiRenderContext.h"
+#include "VertexTypes.h"
+
+/*
+ * GuiRenderContext
+ */
+GuiRenderContext::GuiRenderContext() : pContext(NULL), pCamera(NULL), pEffect(NULL), pVertexBuffer(NULL)
+{
+}
+
+/*
+ * Initialize
+ */
+ErrorCode GuiRenderContext::Initialize(ResourceManager* pResourceManager)
+{
+	ErrorCode eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\TexturedQuad.fx", &pEffect);
+	if(eCode == Error_Success)
+	{
+		eCode = pResourceManager->CreateVertexBuffer(QuadsPerBatch * VerticesPerQuad * sizeof(Vertex::Quad), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pVertexBuffer);
+		if(eCode == Error_Success)
+		{
+			//eCode = SetupVertexBuffer();
+		}
+	}
+
+	return eCode;
+}
+
+/*
+ * Terminate
+ */
+void GuiRenderContext::Terminate()
+{
+	if(pVertexBuffer)
+	{
+		pVertexBuffer->Release();
+		pVertexBuffer = NULL;
+	}
+
+	pEffect = NULL;
+}
+
+/*
+ * Begin
+ */
+void GuiRenderContext::Begin(RenderContext* pRenderContext, Camera* pRenderCamera)
+{
+	if(pRenderContext && pRenderCamera)
+	{
+		pContext = pRenderContext;
+		pCamera = pRenderCamera;
+
+		pContext->ApplyCameraToEffect(*pCamera, pEffect);
+	}
+}
+
+/*
+ * End
+ */
+void GuiRenderContext::End()
+{
+	pContext = NULL;
+	pCamera	= NULL;
+
+	//TODO: Submit primitives
+
+	uint32 nPasses = 0;
+
+	pEffect->SetTechnique(pEffect->GetTechnique(0));
+	pEffect->Begin(&nPasses, 0);
+	pEffect->BeginPass(0);
+
+	/*
+	for each batch:
+	{
+		// setup effect parameters
+		pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
+		pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
+		pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture);
+
+	}
+	*/
+
+	pEffect->EndPass();
+	pEffect->End();
+
+	/*
+	const float fOffsetX = -0.5f * ScreenSizeX;
+	const float fOffsetY = +0.5f * ScreenSizeY;
+
+	const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f);
+
+	kContext.ApplyCameraToEffect(kCamera, pEffect);
+
+	D3DXMATRIX kScale;
+	D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f);
+
+	const D3DXVECTOR2& kLocation = GetPosition();
+
+	D3DXMATRIX kTranslate;
+	D3DXMatrixTranslation(&kTranslate, fOffsetX + kLocation.x + 0.5f, fOffsetY - kLocation.y + 0.5f, 0.0f);
+
+	D3DXMATRIX kWorldMatrix;
+	D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate);
+
+	kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
+	*/
+}
+
+/*
+ * AddToBatch
+ */
+ErrorCode GuiRenderContext::AddToBatch(IDirect3DTexture9* pTexture, const D3DXVECTOR2& kPosition, const D3DXVECTOR2& kSize, D3DCOLOR kColor)
+{
+}
+
+/*
+ * GetRenderContext
+ */
+RenderContext* GuiRenderContext::GetRenderContext()
+{
+	return pContext;
+}
+
+/*
+ * GetCamera
+ */
+Camera* GuiRenderContext::GetCamera()
+{
+	return pCamera;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/GuiRenderContext.h	Fri Sep 23 16:54:51 2011 -0700
@@ -0,0 +1,97 @@
+/*
+ * GuiRenderContext
+ */
+
+#ifndef __GUIRENDERCONTEXT_H__
+#define __GUIRENDERCONTEXT_H__
+
+#include "Core.h"
+#include "RenderContext.h"
+#include "Camera.h"
+#include "ResourceManager.h"
+
+/*
+ * GuiRenderContext
+ */
+class GuiRenderContext
+{
+	/*
+	 * QuadsPerBatch
+	 */
+	static const uint32 QuadsPerBatch = 256;
+
+	/*
+	 * VerticesPerQuad
+	 */
+	static const uint32 VerticesPerQuad = 6;
+
+	/*
+	 * pContext
+	 */
+	RenderContext* pContext;
+
+	/*
+	 * pCamera
+	 */
+	Camera* pCamera;
+
+	/*
+	 * pEffect
+	 */
+	ID3DXEffect* pEffect;
+
+	/*
+	 * pVertexBuffer
+	 */
+	IDirect3DVertexBuffer9* pVertexBuffer;
+
+public:
+
+	/*
+	 * GuiRenderContext
+	 */
+	GuiRenderContext();
+
+	/*
+	 * Initialize
+	 */
+	ErrorCode Initialize(ResourceManager* pResourceManager);
+
+	/*
+	 * Terminate
+	 */
+	void Terminate();
+
+	/*
+	 * Begin
+	 */
+	void Begin(RenderContext* pRenderContext, Camera* pRenderCamera);
+
+	/*
+	 * End
+	 */
+	void End();
+
+	/*
+	 * AddToBatch
+	 */
+	ErrorCode AddToBatch(IDirect3DTexture9* pTexture, const D3DXVECTOR2& kPosition, const D3DXVECTOR2& kSize, D3DCOLOR kColor);
+
+	/*
+	 * GetRenderContext
+	 */
+	RenderContext* GetRenderContext();
+
+	/*
+	 * GetCamera
+	 */
+	Camera* GetCamera();
+
+private:
+
+	/*
+	 * SetupVertexBuffer
+	 */
+};
+
+#endif //__GUIRENDERCONTEXT_H__
--- a/LightClone/Source/Mediator.cpp	Fri Sep 23 11:50:59 2011 -0700
+++ b/LightClone/Source/Mediator.cpp	Fri Sep 23 16:54:51 2011 -0700
@@ -89,6 +89,8 @@
 		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;
 		}
@@ -96,6 +98,8 @@
 		eCode = kContext.Initialize(pGraphicsDevice);
 		if(eCode != Error_Success)
 		{
+			TRACE("Error: Failed to initialize render context\n");
+
 			Terminate();
 			return Error_Fail;
 		}
@@ -103,6 +107,8 @@
 		eCode = kResourceManager.Initialize(pGraphicsDevice);
 		if(eCode != Error_Success)
 		{
+			TRACE("Error: Failed to initialize resource manager\n");
+
 			Terminate();
 			return Error_Fail;
 		}
@@ -110,6 +116,8 @@
 		eCode = kInputManager.Initialize(kWindow.GetHandle());
 		if(eCode != Error_Success)
 		{
+			TRACE("Error: Failed to initialize input manager\n");
+
 			Terminate();
 			return Error_Fail;
 		}
@@ -117,6 +125,8 @@
 		eCode = kWorld.Initialize(&kResourceManager, &kInputManager);
 		if(eCode != Error_Success)
 		{
+			TRACE("Error: Failed to initialize world\n");
+
 			Terminate();
 			return Error_Fail;
 		}
--- a/LightClone/Source/Trace.cpp	Fri Sep 23 11:50:59 2011 -0700
+++ b/LightClone/Source/Trace.cpp	Fri Sep 23 16:54:51 2011 -0700
@@ -92,6 +92,7 @@
 		if(pFile)
 		{
 			fwrite(pBuffer, sizeof(char), nSize, pFile);
+			fflush(pFile);
 		}
 	}
 };
--- a/LightClone/Source/Window.cpp	Fri Sep 23 11:50:59 2011 -0700
+++ b/LightClone/Source/Window.cpp	Fri Sep 23 16:54:51 2011 -0700
@@ -62,27 +62,53 @@
 		const uint32 nStyle		= WS_OVERLAPPEDWINDOW | WS_VISIBLE;
 
 		RECT kDesktopRectangle;
-		GetClientRect(GetDesktopWindow(), &kDesktopRectangle);
+		//GetClientRect(GetDesktopWindow(), &kDesktopRectangle);
+		kDesktopRectangle.left		= 0;
+		kDesktopRectangle.top		= 0;
+		kDesktopRectangle.right		= GetSystemMetrics(SM_CXSCREEN);
+		kDesktopRectangle.bottom	= GetSystemMetrics(SM_CYSCREEN);
+
+		TRACE("Desktop Rectangle:\n");
+		TRACE("  Left   : %d\n", kDesktopRectangle.left);
+		TRACE("  Top    : %d\n", kDesktopRectangle.top);
+		TRACE("  Right  : %d\n", kDesktopRectangle.right);
+		TRACE("  Bottom : %d\n", kDesktopRectangle.bottom);
 
 		RECT kRectangle;
-		kRectangle.left		= 0;
-		kRectangle.top		= 0;
-		kRectangle.right	= ScreenSizeX;
-		kRectangle.bottom	= ScreenSizeY;
+		kRectangle.left				= 0;
+		kRectangle.top				= 0;
+		kRectangle.right			= ScreenSizeX;
+		kRectangle.bottom			= ScreenSizeY;
+
+		TRACE("Window Rectangle:\n");
+		TRACE("  Left   : %d\n", kRectangle.left);
+		TRACE("  Top    : %d\n", kRectangle.top);
+		TRACE("  Right  : %d\n", kRectangle.right);
+		TRACE("  Bottom : %d\n", kRectangle.bottom);
 
 		AdjustWindowRectEx(&kRectangle, nStyle, FALSE, nStyleEx);
 
-		uint32 nW			= kRectangle.right - kRectangle.left;
-		uint32 nH			= kRectangle.bottom - kRectangle.top;
-		uint32 nX			= ((kDesktopRectangle.right - kDesktopRectangle.left) - nW) / 2;
-		uint32 nY			= ((kDesktopRectangle.bottom - kDesktopRectangle.top) - nH) / 2;
+		TRACE("Adjusted Rectangle:\n");
+		TRACE("  Left   : %d\n", kRectangle.left);
+		TRACE("  Top    : %d\n", kRectangle.top);
+		TRACE("  Right  : %d\n", kRectangle.right);
+		TRACE("  Bottom : %d\n", kRectangle.bottom);
+
+		int32 nW			= kRectangle.right - kRectangle.left;
+		int32 nH			= kRectangle.bottom - kRectangle.top;
+		int32 nX			= ((kDesktopRectangle.right - kDesktopRectangle.left) - nW) / 2;
+		int32 nY			= ((kDesktopRectangle.bottom - kDesktopRectangle.top) - nH) / 2;
 
 		TRACE("  Creating window\n");
+		TRACE("    Position   : (%d, %d)\n", nX, nY);
+		TRACE("    Dimensions : (%d, %d)\n", nW, nH);
+
 		kWindow = CreateWindowEx(nStyleEx, kClassName, kCaption, nStyle, nX, nY, nW, nH, NULL, NULL, hInstance, NULL);
 		if(kWindow)
 		{
 			TRACE("    Success!\n");
 			UpdateWindow(kWindow);
+			ShowWindow(kWindow, SW_SHOW);
 
 			return Error_Success;
 		}
--- a/LightClone/Source/World.cpp	Fri Sep 23 11:50:59 2011 -0700
+++ b/LightClone/Source/World.cpp	Fri Sep 23 16:54:51 2011 -0700
@@ -45,8 +45,24 @@
 						nCurrentLevel	= 0;
 						nGameState		= GameState_LoadMap;
 					}
+					else
+					{
+						TRACE("Error: Failed to initialize interface\n");
+					}
+				}
+				else
+				{
+					TRACE("Error: Failed to initialize program\n");
 				}
 			}
+			else
+			{
+				TRACE("Error: Failed to initialize bot\n");
+			}
+		}
+		else
+		{
+			TRACE("Error: Failed to initialize environment\n");
 		}
 	}
 
--- a/LightTools/release.py	Fri Sep 23 11:50:59 2011 -0700
+++ b/LightTools/release.py	Fri Sep 23 16:54:51 2011 -0700
@@ -29,6 +29,7 @@
         raise Exception('Error: Could not locate executable')
 
     data = join(root, 'data')
+    extern = join(root, 'extern')
 
     if not isdir(data):
         raise Exception('Error: Could not locate data folder')
@@ -41,13 +42,21 @@
     shutil.copyfile(executable, join(build, basename(executable)))
         
     for filename in relative_walk(data):
-        filepath = join(build, filename)
+        filepath = join(build, 'Data', filename)
 
         if not isdir(dirname(filepath)):
             os.makedirs(dirname(filepath))
 
         shutil.copyfile(join(data, filename), filepath)
         
+    for filename in relative_walk(extern):
+        filepath = join(build, filename)
+        
+        if not isdir(dirname(filepath)):
+            os.makedirs(dirname(filepath))
+            
+        shutil.copyfile(join(extern, filename), filepath)
+        
     if not isdir(location):
         os.makedirs(location)
         
Binary file Release/LightClone201109220236PM.zip has changed