Mercurial > LightClone
changeset 3:6f227dd9a94f
Re-add code that was lost during the transfer
author | koryspansel |
---|---|
date | Wed, 07 Sep 2011 13:47:48 -0700 |
parents | fd55825393df |
children | d52a7042fa1a |
files | LightClone/LightClone.vcproj LightClone/Source/Bot.cpp LightClone/Source/Bot.h LightClone/Source/Controller.cpp LightClone/Source/Controller.h LightClone/Source/Core.h LightClone/Source/InputManager.cpp LightClone/Source/InputManager.h LightClone/Source/Interface.cpp LightClone/Source/Interface.h LightClone/Source/Model.cpp LightClone/Source/Model.h LightClone/Source/View.cpp LightClone/Source/View.h |
diffstat | 14 files changed, 1176 insertions(+), 808 deletions(-) [+] |
line wrap: on
line diff
--- a/LightClone/LightClone.vcproj Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/LightClone.vcproj Wed Sep 07 13:47:48 2011 -0700 @@ -213,6 +213,10 @@ > </File> <File + RelativePath=".\Source\Interface.cpp" + > + </File> + <File RelativePath=".\Source\Loader.cpp" > </File> @@ -295,6 +299,10 @@ > </File> <File + RelativePath=".\Source\Interface.h" + > + </File> + <File RelativePath=".\Source\Loader.h" > </File>
--- a/LightClone/Source/Bot.cpp Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/Source/Bot.cpp Wed Sep 07 13:47:48 2011 -0700 @@ -188,7 +188,7 @@ /* * Update */ -void Bot::Update(float fElapsed) +bool Bot::Update(float fElapsed) { if(nState == BotState_Evaluate) { @@ -326,6 +326,9 @@ if(kSequencer.fTimer <= 0.0f) { nState = BotState_Evaluate; + return true; } } + + return false; }
--- a/LightClone/Source/Bot.h Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/Source/Bot.h Wed Sep 07 13:47:48 2011 -0700 @@ -165,7 +165,7 @@ /* * Update */ - void Update(float fElapsed); + bool Update(float fElapsed); private:
--- a/LightClone/Source/Controller.cpp Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/Source/Controller.cpp Wed Sep 07 13:47:48 2011 -0700 @@ -16,7 +16,16 @@ */ ErrorCode Controller::Initialize() { - return kInputManager.Initialize(pView->GetWindow()); + HWND kWindow = pView->GetWindow(); + + ErrorCode eCode = pModel->kInputManager.Initialize(kWindow); + if(eCode == Error_Success) + { + pModel->kInputManager.SetBounds(0, 0, (float)ScreenSizeX, (float)ScreenSizeY); + pModel->kInputManager.SetMouse(0.5f * ScreenSizeX, 0.5f * ScreenSizeY); + } + + return eCode; } /* @@ -24,7 +33,7 @@ */ void Controller::Terminate() { - kInputManager.Terminate(); + pModel->kInputManager.Terminate(); } /* @@ -40,19 +49,6 @@ sprintf_s(kBuffer, "Data\\Maps\\Map%02d.map", pModel->nCurrentLevel++); pModel->nGameState = pModel->Load(kBuffer) ? GameState_Active : GameState_Over; - - /* - bool bLoaded = pModel->Load(kBuffer); - if(bLoaded) - { - pModel->nGameState = GameState_Active; - } - else - { - //TODO: Display game over dialog - pModel->nGameState = GameState_Over; - } - */ } else @@ -60,36 +56,16 @@ { if(pModel->nSimulationState == SimulationState_Active) { - pModel->GetBot()->Update(fElapsed); - - //TODO: Only check for requirements after an action has completed - Environment* pEnvironment = pModel->GetEnvironment(); - if(pEnvironment->RequirementsMet()) + if(pModel->GetBot()->Update(fElapsed)) { - pModel->nGameState = GameState_Complete; + Environment* pEnvironment = pModel->GetEnvironment(); + if(pEnvironment->RequirementsMet()) + { + pModel->nGameState = GameState_Complete; + } } } } - else - - if(pModel->nGameState == GameState_Complete) - { - //TODO: Level is complete - //TODO: Load next level or end game - //pModel->nGameState = GameState_LoadMap; - } - else - - if(pModel->nGameState == GameState_Over) - { - //TODO: Game is over - //pModel->nGameState = GameState_Exit; - } - else - - if(pModel->nGameState == GameState_Confirm) - { - } } /* @@ -125,57 +101,76 @@ */ void Controller::ProcessInput(float fElapsed) { - kInputManager.Update(fElapsed); + pModel->kInputManager.Update(fElapsed); #if defined(_DEBUG) - if(kInputManager.IsKeyDown(DIK_LEFT)) + if(pModel->kInputManager.IsKeyDown(DIK_LEFT)) { pView->UpdateCameraYaw(0.01f); } else - if(kInputManager.IsKeyDown(DIK_RIGHT)) + if(pModel->kInputManager.IsKeyDown(DIK_RIGHT)) { pView->UpdateCameraYaw(-0.01f); } - if(kInputManager.IsKeyDown(DIK_UP)) + if(pModel->kInputManager.IsKeyDown(DIK_UP)) { pView->UpdateCameraPitch(0.01f); } else - if(kInputManager.IsKeyDown(DIK_DOWN)) + if(pModel->kInputManager.IsKeyDown(DIK_DOWN)) { pView->UpdateCameraPitch(-0.01f); } - if(kInputManager.IsKeyDown(DIK_NEXT)) + if(pModel->kInputManager.IsKeyDown(DIK_NEXT)) { pView->UpdateCameraDistance(-0.1f); } else - if(kInputManager.IsKeyDown(DIK_PRIOR)) + if(pModel->kInputManager.IsKeyDown(DIK_PRIOR)) { pView->UpdateCameraDistance(0.1f); } #endif - const float fSensitivity = 1.5f; - const float fDeltaX = (float)kInputManager.GetMouseDeltaX(); - const float fDeltaY = (float)kInputManager.GetMouseDeltaY(); - - const float fMouseX = Max(0.0f, Min(pModel->fMouseX + fSensitivity * fDeltaX, (float)ScreenSizeX)); - const float fMouseY = Max(0.0f, Min(pModel->fMouseY + fSensitivity * fDeltaY, (float)ScreenSizeY)); - - pModel->fMouseX = fMouseX; - pModel->fMouseY = fMouseY; + const float fMouseX = pModel->kInputManager.GetMouseX(); + const float fMouseY = pModel->kInputManager.GetMouseY(); if(pModel->nGameState == GameState_Active) { - if(kInputManager.IsButtonDown(0) && !kInputManager.WasButtonDown(0)) + if(pModel->kInputManager.IsButtonDown(0) && !pModel->kInputManager.WasButtonDown(0)) { + if(pModel->kControlBounds[ControlButton_Play].Contains(fMouseX, fMouseY)) + { + Start(); + } + else + + if(pModel->kControlBounds[ControlButton_Stop].Contains(fMouseX, fMouseY)) + { + Stop(); + } + else + + if(pModel->kControlBounds[ControlButton_Exit].Contains(fMouseX, fMouseY)) + { + pModel->nGameState = GameState_Exit; + } + + for(uint32 i = 0; i < sizeof(pModel->kArrowBounds) / sizeof(pModel->kArrowBounds[0]); ++i) + { + if(pModel->kArrowBounds[i].Contains(fMouseX, fMouseY)) + { + const uint32 nCount = pModel->GetFunctionCount() - 1; + pModel->nCurrentFunction = (pModel->nCurrentFunction + 2 * (int32)i - 1 + nCount) % nCount; + } + } + for(uint32 i = 0; i < Action_Count; ++i) { if(pModel->kActionBounds[i].Contains(fMouseX, fMouseY)) @@ -209,44 +204,10 @@ } } } - - if(!pModel->kDragController.IsActive()) - { - if(pModel->kControlBounds[0].Contains(fMouseX, fMouseY)) - { - Start(); - } - else - - if(pModel->kControlBounds[1].Contains(fMouseX, fMouseY)) - { - Stop(); - } - else - - if(pModel->kControlBounds[2].Contains(fMouseX, fMouseY)) - { - pModel->nGameState = GameState_Exit; - } - else - - if(pModel->kArrowBounds[0].Contains(fMouseX, fMouseY)) - { - const uint32 nCount = pModel->GetFunctionCount() - 1; - pModel->nCurrentFunction = (pModel->nCurrentFunction - 1 + nCount) % nCount; - } - else - - if(pModel->kArrowBounds[1].Contains(fMouseX, fMouseY)) - { - const uint32 nCount = pModel->GetFunctionCount() - 1; - pModel->nCurrentFunction = (pModel->nCurrentFunction + 1) % nCount; - } - } } else - if(!kInputManager.IsButtonDown(0) && kInputManager.WasButtonDown(0)) + if(!pModel->kInputManager.IsButtonDown(0) && pModel->kInputManager.WasButtonDown(0)) { if(pModel->kDragController.IsActive()) { @@ -270,4 +231,68 @@ } } } + else + + if(pModel->nGameState == GameState_Complete) + { + // check to see if button was clicked + if(pModel->kInputManager.IsButtonDown(0) && !pModel->kInputManager.WasButtonDown(0)) + { + for(uint32 i = 0; i < sizeof(pModel->kDialog1Bounds) / sizeof(pModel->kDialog1Bounds[0]); ++i) + { + if(pModel->kDialog1Bounds[i].Contains(fMouseX, fMouseY)) + { + if(i == 0) + { + pModel->nGameState = GameState_LoadMap; + } + } + } + } + } + else + + if(pModel->nGameState == GameState_Over) + { + // check to see if button was clicked + if(pModel->kInputManager.IsButtonDown(0) && !pModel->kInputManager.WasButtonDown(0)) + { + for(uint32 i = 0; i < sizeof(pModel->kDialog1Bounds) / sizeof(pModel->kDialog1Bounds[0]); ++i) + { + if(pModel->kDialog1Bounds[i].Contains(fMouseX, fMouseY)) + { + if(i == 0) + { + pModel->nCurrentLevel = 0; + pModel->nGameState = GameState_LoadMap; + } + } + } + } + } + else + + if(pModel->nGameState == GameState_Confirm) + { + // check to see if button was clicked + if(pModel->kInputManager.IsButtonDown(0) && !pModel->kInputManager.WasButtonDown(0)) + { + for(uint32 i = 0; i < sizeof(pModel->kDialog2Bounds) / sizeof(pModel->kDialog2Bounds[0]); ++i) + { + if(pModel->kDialog2Bounds[i].Contains(fMouseX, fMouseY)) + { + if(i == 0) + { + pModel->nGameState = GameState_Exit; + } + else + + if(i == 1) + { + pModel->nGameState = GameState_Active; + } + } + } + } + } }
--- a/LightClone/Source/Controller.h Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/Source/Controller.h Wed Sep 07 13:47:48 2011 -0700 @@ -7,7 +7,6 @@ #include "View.h" #include "Model.h" -#include "InputManager.h" /* * Controller @@ -24,11 +23,6 @@ */ View* pView; - /* - * kInputManager - */ - InputManager kInputManager; - public: /*
--- a/LightClone/Source/Core.h Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/Source/Core.h Wed Sep 07 13:47:48 2011 -0700 @@ -99,6 +99,16 @@ }; /* + * ControlButton + */ +enum +{ + ControlButton_Play, + ControlButton_Stop, + ControlButton_Exit, +}; + +/* * ScreenSizeX */ const uint32 ScreenSizeX = 1280;
--- a/LightClone/Source/InputManager.cpp Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/Source/InputManager.cpp Wed Sep 07 13:47:48 2011 -0700 @@ -5,6 +5,11 @@ #include "InputManager.h" /* + * fMouseSensitivity + */ +static const float fMouseSensitivity = 1.5f; + +/* * InputManager */ InputManager::InputManager() @@ -12,6 +17,8 @@ pDirectInput = NULL; pKeyboard = NULL; pMouse = NULL; + fMouseX = 0.0f; + fMouseY = 0.0f; memset(kCurrentKeyboardState, 0, sizeof(kCurrentKeyboardState)); memset(kPreviousKeyboardState, 0, sizeof(kPreviousKeyboardState)); @@ -136,23 +143,30 @@ hResult = pMouse->GetDeviceState(sizeof(kCurrentMouseState), &kCurrentMouseState); } } + + fMouseX = Clamp(fMouseX + fMouseSensitivity * kCurrentMouseState.lX, kMouseBounds.X, kMouseBounds.X + kMouseBounds.Width - 1.0f); + fMouseY = Clamp(fMouseY + fMouseSensitivity * kCurrentMouseState.lY, kMouseBounds.Y, kMouseBounds.Y + kMouseBounds.Height - 1.0f); } } /* - * GetKeyboardState + * SetBounds */ -const char* InputManager::GetKeyboardState(bool bPrevious) const +void InputManager::SetBounds(float fMinimumX, float fMinimumY, float fMaximumX, float fMaximumY) { - return bPrevious ? kPreviousKeyboardState : kCurrentKeyboardState; + kMouseBounds.X = fMinimumX; + kMouseBounds.Y = fMinimumY; + kMouseBounds.Width = fMaximumX - fMinimumX; + kMouseBounds.Height = fMaximumY - fMinimumY; } /* - * GetMouseState + * SetMouse */ -const DIMOUSESTATE* InputManager::GetMouseState(bool bPrevious) const +void InputManager::SetMouse(float fX, float fY) { - return bPrevious ? &kPreviousMouseState : &kCurrentMouseState; + fMouseX = Clamp(fX, kMouseBounds.X, kMouseBounds.X + kMouseBounds.Width - 1.0f); + fMouseY = Clamp(fY, kMouseBounds.Y, kMouseBounds.Y + kMouseBounds.Height - 1.0f); } /* @@ -188,17 +202,17 @@ } /* - * GetMouseDeltaX + * GetMouseX */ -int32 InputManager::GetMouseDeltaX() const +float InputManager::GetMouseX() const { - return (int32)kCurrentMouseState.lX; + return fMouseX; } /* - * GetMouseDeltaY + * GetMouseY */ -int32 InputManager::GetMouseDeltaY() const +float InputManager::GetMouseY() const { - return (int32)kCurrentMouseState.lY; + return fMouseY; } \ No newline at end of file
--- a/LightClone/Source/InputManager.h Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/Source/InputManager.h Wed Sep 07 13:47:48 2011 -0700 @@ -49,6 +49,21 @@ */ DIMOUSESTATE kPreviousMouseState; + /* + * fMouseX + */ + float fMouseX; + + /* + * fMouseY + */ + float fMouseY; + + /* + * kMouseBounds + */ + Rectangle2 kMouseBounds; + public: /* @@ -72,14 +87,14 @@ void Update(float fElapsed); /* - * GetKeyboardState + * SetBounds */ - const char* GetKeyboardState(bool bPrevious = false) const; + void SetBounds(float fMinimumX, float fMinimumY, float fMaximumX, float fMaximumY); /* - * GetMouseState + * SetMouse */ - const DIMOUSESTATE* GetMouseState(bool bPrevious = false) const; + void SetMouse(float fX, float fY); /* * IsKeyDown @@ -102,14 +117,14 @@ bool WasButtonDown(uint32 nButton) const; /* - * GetMouseDeltaX + * GetMouseX */ - int32 GetMouseDeltaX() const; + float GetMouseX() const; /* - * GetMouseDeltaY + * GetMouseY */ - int32 GetMouseDeltaY() const; + float GetMouseY() const; }; #endif //__INPUTMANAGER_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/Interface.cpp Wed Sep 07 13:47:48 2011 -0700 @@ -0,0 +1,740 @@ +/* + * Interface + */ + +#include "Interface.h" +#include "VertexTypes.h" + +/* + * pActionTextureName + */ +static const char* pActionTextureName[] = +{ + "Data\\Textures\\Forward.tga", + "Data\\Textures\\RotateCW.tga", + "Data\\Textures\\RotateCCW.tga", + "Data\\Textures\\Jump.tga", + "Data\\Textures\\Light.tga", + "Data\\Textures\\Function1.tga", + "Data\\Textures\\Function2.tga", +}; + +/* + * pControlTextureName + */ +const char* pControlTextureName[] = +{ + "Data\\Textures\\Play.tga", + "Data\\Textures\\Stop.tga", + "Data\\Textures\\Exit.tga", +}; + +/* + * pArrowTextureName + */ +const char* pArrowTextureName[] = +{ + "Data\\Textures\\Left.tga", + "Data\\Textures\\Right.tga", +}; + +/* + * Interface + */ +Interface::Interface() +{ + pEffect = NULL; + pFont = NULL; + pVertexBuffer = NULL; + pBackgroundTexture = NULL; + pCursorTexture = NULL; + pDialog1Texture = NULL; + pDialog2Texture = NULL; + + memset(pActionTexture, 0, sizeof(pActionTexture)); + memset(pControlTexture, 0, sizeof(pControlTexture)); + memset(pArrowTexture, 0, sizeof(pArrowTexture)); +} + +/* + * Initialize + */ +ErrorCode Interface::Initialize(RenderContext& kContext) +{ + ErrorCode eCode = kContext.CreateEffectFromFile("Data\\Shaders\\TexturedQuad.fx", &pEffect); + if(eCode != Error_Success) + { + Terminate(); + return Error_Fail; + } + + eCode = kContext.CreateFontFromName("Courier New", 18, FW_BOLD, &pFont); + if(eCode != Error_Success) + { + Terminate(); + return Error_Fail; + } + + eCode = kContext.CreateVertexBuffer(TrianglesPerFace * VerticesPerTriangle * sizeof(Vertex::Quad), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pVertexBuffer); + if(eCode != Error_Success) + { + Terminate(); + return Error_Fail; + } + + eCode = kContext.CreateTextureFromFile("Data\\Textures\\Background.tga", &pBackgroundTexture); + if(eCode != Error_Success) + { + Terminate(); + return Error_Fail; + } + + for(uint32 i = 0; i < Action_Count; ++i) + { + eCode = kContext.CreateTextureFromFile(pActionTextureName[i], pActionTexture + i); + if(eCode != Error_Success) + { + Terminate(); + return Error_Fail; + } + } + + for(uint32 i = 0; i < sizeof(pControlTextureName) / sizeof(pControlTextureName[0]); ++i) + { + eCode = kContext.CreateTextureFromFile(pControlTextureName[i], pControlTexture + i); + if(eCode != Error_Success) + { + Terminate(); + return Error_Fail; + } + } + + for(uint32 i = 0; i < sizeof(pArrowTextureName) / sizeof(pArrowTextureName[0]); ++i) + { + eCode = kContext.CreateTextureFromFile(pArrowTextureName[i], pArrowTexture + i); + if(eCode != Error_Success) + { + Terminate(); + return Error_Fail; + } + } + + eCode = kContext.CreateTextureFromFile("Data\\Textures\\Dialog1.tga", &pDialog1Texture); + if(eCode != Error_Success) + { + Terminate(); + return Error_Fail; + } + + eCode = kContext.CreateTextureFromFile("Data\\Textures\\Dialog2.tga", &pDialog2Texture); + if(eCode != Error_Success) + { + Terminate(); + return Error_Fail; + } + + eCode = kContext.CreateTextureFromFile("Data\\Textures\\Arrow.tga", &pCursorTexture); + if(eCode != Error_Success) + { + Terminate(); + return Error_Fail; + } + + return SetupVertexBuffer(); +} + +/* + * Terminate + */ +void Interface::Terminate() +{ + if(pCursorTexture) + { + pCursorTexture->Release(); + pCursorTexture = NULL; + } + + if(pDialog1Texture) + { + pDialog1Texture->Release(); + pDialog1Texture = NULL; + } + + if(pDialog2Texture) + { + pDialog2Texture->Release(); + pDialog2Texture = NULL; + } + + for(uint32 i = 0; i < sizeof(pArrowTexture) / sizeof(pArrowTexture[0]); ++i) + { + if(pArrowTexture[i]) + { + pArrowTexture[i]->Release(); + pArrowTexture[i] = NULL; + } + } + + for(uint32 i = 0; i < sizeof(pControlTexture) / sizeof(pControlTexture[0]); ++i) + { + if(pControlTexture[i]) + { + pControlTexture[i]->Release(); + pControlTexture[i] = NULL; + } + } + + for(uint32 i = 0; i < Action_Count; ++i) + { + if(pActionTexture[i]) + { + pActionTexture[i]->Release(); + pActionTexture[i] = NULL; + } + } + + if(pBackgroundTexture) + { + pBackgroundTexture->Release(); + pBackgroundTexture = NULL; + } + + if(pVertexBuffer) + { + pVertexBuffer->Release(); + pVertexBuffer = NULL; + } + + if(pFont) + { + pFont->Release(); + pFont = NULL; + } + + if(pEffect) + { + pEffect->Release(); + pEffect = NULL; + } +} + +/* + * Render + */ +void Interface::Render(RenderContext& kContext, Model* pModel) +{ + kContext.SetupCamera2D(pEffect); + + uint32 nPasses = 0; + + pEffect->SetTechnique(pEffect->GetTechnique(0)); + pEffect->Begin(&nPasses, 0); + pEffect->BeginPass(0); + + RenderBackground(kContext, pModel); + RenderToolbar(kContext, pModel); + RenderMain(kContext, pModel); + RenderFunctions(kContext, pModel); + RenderControls(kContext, pModel); + + if(pModel->nGameState == GameState_Active) + { + } + else + + if(pModel->nGameState == GameState_Complete) + { + char kMessage[256]; + sprintf_s(kMessage, "Congratulations!\nYou have completed level %d", pModel->nCurrentLevel); + + RenderDialog(kContext, pModel, kMessage, "Ok"); + //RenderLevelDialog(kContext, pModel); + } + else + + if(pModel->nGameState == GameState_Over) + { + const char* pMessage = "Congratulations!\nYou have won the game!"; + + RenderDialog(kContext, pModel, pMessage, "Ok"); + //RenderGameOverDialog(kContext, pModel); + } + else + + if(pModel->nGameState == GameState_Confirm) + { + const char* pMessage = "Are you sure you want to quit the game?"; + + RenderDialog(kContext, pModel, pMessage, "Yes", "No"); + //RenderConfirmExitDialog(kContext, pModel); + } + + RenderCursor(kContext, pModel); + + pEffect->EndPass(); + pEffect->End(); +} + +/* + * SetupVertexBuffer + */ +ErrorCode Interface::SetupVertexBuffer() +{ + Vertex::Quad* pVertices = NULL; + + HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD); + if(FAILED(hResult)) + { + return Error_Fail; + } + + pVertices[0] = Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f); + pVertices[1] = Vertex::Quad(+0.0f, +0.0f, 1.0f, 0.0f, 0.0f); + pVertices[2] = Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f); + pVertices[3] = Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f); + pVertices[4] = Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f); + pVertices[5] = Vertex::Quad(+1.0f, -1.0f, 1.0f, 1.0f, 1.0f); + + pVertexBuffer->Unlock(); + + return Error_Success; +} + +/* + * RenderBackground + */ +void Interface::RenderBackground(RenderContext& kContext, Model* pModel) +{ + const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + + const float fWidth = 304.0f;//10.0f * ScreenSizeX / 26.0f; + const float fHeight = ScreenSizeY; + const float fX = ScreenSizeX - fWidth; + const float fY = 0.0f; + + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, fWidth, fHeight, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + fX + 0.5f, 0.5f * ScreenSizeY - fY + 0.5f, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pBackgroundTexture); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); +} + +/* + * RenderToolbar + */ +void Interface::RenderToolbar(RenderContext& kContext, Model* pModel) +{ + const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + + for(uint32 i = 0; i < Action_Count; ++i) + { + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, pModel->kActionBounds[i].Width, pModel->kActionBounds[i].Height, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->kActionBounds[i].X, 0.5f * ScreenSizeY - pModel->kActionBounds[i].Y, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pActionTexture[i]); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + } +} + +/* + * RenderMain + */ +void Interface::RenderMain(RenderContext& kContext, Model* pModel) +{ + Code* pCode = pModel->GetFunction(0); + if(pCode) + { + const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + + for(uint32 i = 0; i < Max(pCode->GetSize(), 16U); ++i) + { + const uint32 nAction = pCode->GetSlot(i); + + if(Action_Forward <= nAction && nAction <= Action_FunctionB) + { + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, pModel->kMainBounds[i].Width, pModel->kMainBounds[i].Height, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->kMainBounds[i].X, 0.5f * ScreenSizeY - pModel->kMainBounds[i].Y, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pActionTexture[nAction - Action_Forward]); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + } + } + + RECT kRectangle; + kRectangle.left = 1008; + kRectangle.top = 199; + kRectangle.right = kRectangle.left + 200; + kRectangle.bottom = kRectangle.top + 200; + + pFont->DrawTextA(NULL, "Main", -1, &kRectangle, 0, D3DCOLOR_XRGB(0, 0, 0)); + } +} + +/* + * RenderFunctions + */ +void Interface::RenderFunctions(RenderContext& kContext, Model* pModel) +{ + Code* pCode = pModel->GetFunction(pModel->nCurrentFunction + 1); + if(pCode) + { + const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + + for(uint32 i = 0; i < Max(pCode->GetSize(), 8U); ++i) + { + const uint32 nAction = pCode->GetSlot(i); + + if(Action_Forward <= nAction && nAction <= Action_FunctionB) + { + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, pModel->kFunctionBounds[i].Width, pModel->kFunctionBounds[i].Height, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->kFunctionBounds[i].X, 0.5f * ScreenSizeY - pModel->kFunctionBounds[i].Y, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pActionTexture[nAction - Action_Forward]); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + } + } + + for(uint32 i = 0; i < sizeof(pModel->kArrowBounds) / sizeof(pModel->kArrowBounds[0]); ++i) + { + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, pModel->kArrowBounds[i].Width, pModel->kArrowBounds[i].Height, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->kArrowBounds[i].X, 0.5f * ScreenSizeY - pModel->kArrowBounds[i].Y, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pArrowTexture[i]); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + } + + RECT kRectangle; + + kRectangle.left = 1008; + kRectangle.top = 472; + kRectangle.right = kRectangle.left + 200; + kRectangle.bottom = kRectangle.top + 200; + + pFont->DrawTextA(NULL, "Function", -1, &kRectangle, 0, D3DCOLOR_XRGB(0, 0, 0)); + + char kBuffer[16]; + sprintf_s(kBuffer, "%d", pModel->nCurrentFunction + 1); + + kRectangle.left = 1225; + kRectangle.top = 473; + kRectangle.right = kRectangle.left + 200; + kRectangle.bottom = kRectangle.top + 200; + + pFont->DrawTextA(NULL, kBuffer, -1, &kRectangle, 0, D3DCOLOR_XRGB(0, 0, 0)); + } +} + +/* + * RenderControls + */ +void Interface::RenderControls(RenderContext& kContext, Model* pModel) +{ + const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + + for(uint32 i = 0; i < sizeof(pModel->kControlBounds) / sizeof(pModel->kControlBounds[0]); ++i) + { + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, pModel->kControlBounds[i].Width, pModel->kControlBounds[i].Height, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->kControlBounds[i].X, 0.5f * ScreenSizeY - pModel->kControlBounds[i].Y, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pControlTexture[i]); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + } +} + +/* + * RenderLevelDialog + */ +void Interface::RenderLevelDialog(RenderContext& kContext, Model* pModel) +{ + const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + + D3DSURFACE_DESC kDescriptor; + pDialog1Texture->GetLevelDesc(0, &kDescriptor); + + const float fSizeX = (float)kDescriptor.Width; + const float fSizeY = (float)kDescriptor.Height; + + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, fSizeX, fSizeY, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * fSizeX, 0.5f * fSizeY, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pDialog1Texture); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + + RECT kRectangle; + + kRectangle.left = ScreenSizeX / 2; + kRectangle.top = ScreenSizeY / 2 - 24; + kRectangle.right = ScreenSizeX / 2; + kRectangle.bottom = ScreenSizeY / 2 - 24; + + char kMessage[256]; + sprintf_s(kMessage, "Congratulations!\nYou have completed level %d", pModel->nCurrentLevel); + + pFont->DrawTextA(NULL, kMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER | DT_CALCRECT, D3DCOLOR_XRGB(0, 0, 0)); + pFont->DrawTextA(NULL, kMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(0, 0, 0)); + + //RenderDialog(kContext, pModel, kMessage, "Ok"); +} + +/* + * RenderGameOverDialog + */ +void Interface::RenderGameOverDialog(RenderContext& kContext, Model* pModel) +{ + const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + + D3DSURFACE_DESC kDescriptor; + pDialog1Texture->GetLevelDesc(0, &kDescriptor); + + const float fSizeX = (float)kDescriptor.Width; + const float fSizeY = (float)kDescriptor.Height; + + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, fSizeX, fSizeY, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * fSizeX, 0.5f * fSizeY, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pDialog1Texture); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + + RECT kRectangle; + + kRectangle.left = ScreenSizeX / 2; + kRectangle.top = ScreenSizeY / 2 - 24; + kRectangle.right = ScreenSizeX / 2; + kRectangle.bottom = ScreenSizeY / 2 - 24; + + const char* pMessage = "Congratulations!\nYou have won the game!"; + + pFont->DrawTextA(NULL, pMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER | DT_CALCRECT, D3DCOLOR_XRGB(0, 0, 0)); + pFont->DrawTextA(NULL, pMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(0, 0, 0)); + + //RenderDialog(kContext, pModel, pMessage, "Ok"); +} + +/* + * RenderConfirmExitDialog + */ +void Interface::RenderConfirmExitDialog(RenderContext& kContext, Model* pModel) +{ + const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + + D3DSURFACE_DESC kDescriptor; + pDialog1Texture->GetLevelDesc(0, &kDescriptor); + + const float fSizeX = (float)kDescriptor.Width; + const float fSizeY = (float)kDescriptor.Height; + + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, fSizeX, fSizeY, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * fSizeX, 0.5f * fSizeY, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pDialog1Texture); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + + RECT kRectangle; + + kRectangle.left = ScreenSizeX / 2; + kRectangle.top = ScreenSizeY / 2 - 24; + kRectangle.right = ScreenSizeX / 2; + kRectangle.bottom = ScreenSizeY / 2 - 24; + + const char* pMessage = "Are you sure you want to quit the game?"; + + pFont->DrawTextA(NULL, pMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER | DT_CALCRECT, D3DCOLOR_XRGB(0, 0, 0)); + pFont->DrawTextA(NULL, pMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(0, 0, 0)); + + //RenderDialog(kContext, pModel, pMessage, "Yes", "No"); +} + +/* + * RenderDialog + */ +void Interface::RenderDialog(RenderContext& kContext, Model* pModel, const char* pMessage, const char* pChoiceA, const char* pChoiceB) +{ + if(pMessage && pChoiceA) + { + IDirect3DTexture9* pTexture = pChoiceB ? pDialog2Texture : pDialog1Texture; + + D3DSURFACE_DESC kDescriptor; + pTexture->GetLevelDesc(0, &kDescriptor); + + const float fSizeX = (float)kDescriptor.Width; + const float fSizeY = (float)kDescriptor.Height; + + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, fSizeX, fSizeY, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * fSizeX, 0.5f * fSizeY, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f)); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + + RECT kRectangle; + + kRectangle.left = ScreenSizeX / 2; + kRectangle.top = ScreenSizeY / 2 - 24; + kRectangle.right = ScreenSizeX / 2; + kRectangle.bottom = ScreenSizeY / 2 - 24; + + pFont->DrawTextA(NULL, pMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER | DT_CALCRECT, D3DCOLOR_XRGB(0, 0, 0)); + pFont->DrawTextA(NULL, pMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(0, 0, 0)); + + //TODO: Render button text + } +} + +/* + * RenderCursor + */ +void Interface::RenderCursor(RenderContext& kContext, Model* pModel) +{ + const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + + if(pCursorTexture) + { + const float fMouseX = pModel->kInputManager.GetMouseX(); + const float fMouseY = pModel->kInputManager.GetMouseY(); + + if(pModel->kDragController.IsActive()) + { + const uint32 nAction = pModel->kDragController.GetParameter() - Action_Forward; + + D3DSURFACE_DESC kDescriptor; + pActionTexture[nAction]->GetLevelDesc(0, &kDescriptor); + + const float fSizeX = (float)kDescriptor.Width; + const float fSizeY = (float)kDescriptor.Height; + + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, fSizeX, fSizeY, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + (fMouseX - 0.5f * fSizeX) + 0.5f, 0.5f * ScreenSizeY - (fMouseY - 0.5f * fSizeY) + 0.5f, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pActionTexture[nAction]); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + } + + D3DSURFACE_DESC kDescriptor; + pCursorTexture->GetLevelDesc(0, &kDescriptor); + + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, (float)kDescriptor.Width, (float)kDescriptor.Height, 1.0f); + + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + fMouseX + 0.5f, 0.5f * ScreenSizeY - fMouseY + 0.5f, 0.0f); + + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pCursorTexture); + pEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/Interface.h Wed Sep 07 13:47:48 2011 -0700 @@ -0,0 +1,149 @@ +/* + * Interface + */ + +#ifndef __INTERFACE_H__ +#define __INTERFACE_H__ + +#include "Core.h" +#include "RenderContext.h" +#include "Model.h" + +/* + * Interface + */ +class Interface +{ +private: + + /* + * pEffect + */ + ID3DXEffect* pEffect; + + /* + * pFont + */ + ID3DXFont* pFont; + + /* + * pVertexBuffer + */ + IDirect3DVertexBuffer9* pVertexBuffer; + + /* + * pBackgroundTexture + */ + IDirect3DTexture9* pBackgroundTexture; + + /* + * pActionTexture + */ + IDirect3DTexture9* pActionTexture[Action_Count]; + + /* + * pControlTexture + */ + IDirect3DTexture9* pControlTexture[3]; + + /* + * pArrowTexture + */ + IDirect3DTexture9* pArrowTexture[2]; + + /* + * pDialog1Texture + */ + IDirect3DTexture9* pDialog1Texture; + + /* + * pDialog2Texture + */ + IDirect3DTexture9* pDialog2Texture; + + /* + * pCursorTexture + */ + IDirect3DTexture9* pCursorTexture; + +public: + + /* + * Interface + */ + Interface(); + + /* + * Initialize + */ + ErrorCode Initialize(RenderContext& kContext); + + /* + * Terminate + */ + void Terminate(); + + /* + * Render + */ + void Render(RenderContext& kContext, Model* pModel); + +private: + + /* + * SetupVertexBuffer + */ + ErrorCode SetupVertexBuffer(); + + /* + * RenderBackground + */ + void RenderBackground(RenderContext& kContext, Model* pModel); + + /* + * RenderToolbar + */ + void RenderToolbar(RenderContext& kContext, Model* pModel); + + /* + * RenderMain + */ + void RenderMain(RenderContext& kContext, Model* pModel); + + /* + * RenderFunctions + */ + void RenderFunctions(RenderContext& kContext, Model* pModel); + + /* + * RenderControls + */ + void RenderControls(RenderContext& kContext, Model* pModel); + + /* + * RenderLevelDialog + */ + void RenderLevelDialog(RenderContext& kContext, Model* pModel); + + /* + * RenderGameOverDialog + */ + void RenderGameOverDialog(RenderContext& kContext, Model* pModel); + + /* + * RenderConfirmExitDialog + */ + void RenderConfirmExitDialog(RenderContext& kContext, Model* pModel); + + /* + * RenderDialog + */ + void RenderDialog(RenderContext& kContext, Model* pModel, const char* pMessage, const char* pChoiceA, const char* pChoiceB = NULL); + + /* + * RenderCursor + */ + void RenderCursor(RenderContext& kContext, Model* pModel); +}; + +#endif //__INTERFACE_H__
--- a/LightClone/Source/Model.cpp Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/Source/Model.cpp Wed Sep 07 13:47:48 2011 -0700 @@ -12,8 +12,6 @@ nGameState = GameState_Active; nSimulationState = SimulationState_Idle; pFunction = 0; - fMouseX = 0.5f * ScreenSizeX; - fMouseY = 0.5f * ScreenSizeY; nCurrentFunction = 0; nCurrentLevel = 0; @@ -58,6 +56,11 @@ kControlBounds[0] = Rectangle2(1023.0f + 0.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); kControlBounds[1] = Rectangle2(1023.0f + 1.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); kControlBounds[2] = Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); + + kDialog1Bounds[0] = Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); + + kDialog2Bounds[0] = Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); + kDialog2Bounds[1] = Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); } /*
--- a/LightClone/Source/Model.h Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/Source/Model.h Wed Sep 07 13:47:48 2011 -0700 @@ -10,6 +10,7 @@ #include "Environment.h" #include "Code.h" #include "Loader.h" +#include "InputManager.h" #include "DragController.h" /* @@ -110,14 +111,19 @@ Rectangle2 kControlBounds[3]; /* - * fMouseX + * kDialog1Bounds */ - float fMouseX; + Rectangle2 kDialog1Bounds[1]; /* - * fMouseY + * kDialog2Bounds */ - float fMouseY; + Rectangle2 kDialog2Bounds[2]; + + /* + * kInputManager + */ + InputManager kInputManager; /* * kDragController
--- a/LightClone/Source/View.cpp Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/Source/View.cpp Wed Sep 07 13:47:48 2011 -0700 @@ -16,39 +16,6 @@ static const TCHAR* kCaption = L"LightClone"; /* - * pActionTextureName - */ -static const char* pActionTextureName[] = -{ - "Data\\Textures\\Forward.tga", - "Data\\Textures\\RotateCW.tga", - "Data\\Textures\\RotateCCW.tga", - "Data\\Textures\\Jump.tga", - "Data\\Textures\\Light.tga", - "Data\\Textures\\Function1.tga", - "Data\\Textures\\Function2.tga", -}; - -/* - * pControlTextureName - */ -const char* pControlTextureName[] = -{ - "Data\\Textures\\Play.tga", - "Data\\Textures\\Stop.tga", - "Data\\Textures\\Exit.tga", -}; - -/* - * pArrowTextureName - */ -const char* pArrowTextureName[] = -{ - "Data\\Textures\\Left.tga", - "Data\\Textures\\Right.tga", -}; - -/* * pView */ View* View::pView = NULL; @@ -62,19 +29,8 @@ kWindow = NULL; pBlockEffect = NULL; - pInterfaceEffect = NULL; - pInterfaceFont = NULL; pBlockVertexBuffer = NULL; - pInterfaceVertexBuffer = NULL; pBlockTexture = NULL; - pBackgroundTexture = NULL; - pDialog1Texture = NULL; - pDialog2Texture = NULL; - pCursorTexture = NULL; - - memset(pActionTextures, 0, sizeof(pActionTextures)); - memset(pControlTextures, 0, sizeof(pControlTextures)); - memset(pArrowTextures, 0, sizeof(pArrowTextures)); } /* @@ -146,20 +102,6 @@ return Error_Fail; } - eCode = kContext.CreateEffectFromFile("Data\\Shaders\\TexturedQuad.fx", &pInterfaceEffect); - if(eCode != Error_Success) - { - Terminate(); - return Error_Fail; - } - - eCode = kContext.CreateFontFromName("Courier New", 18, FW_BOLD, &pInterfaceFont); - if(eCode != Error_Success) - { - Terminate(); - return Error_Fail; - } - eCode = kContext.CreateTextureFromFile("Data\\Textures\\Block02.tga", &pBlockTexture); if(eCode != Error_Success) { @@ -167,64 +109,6 @@ return Error_Fail; } - eCode = kContext.CreateTextureFromFile("Data\\Textures\\Background00.tga", &pBackgroundTexture); - if(eCode != Error_Success) - { - Terminate(); - return Error_Fail; - } - - for(uint32 i = 0; i < Action_Count; ++i) - { - eCode = kContext.CreateTextureFromFile(pActionTextureName[i], pActionTextures + i); - if(eCode != Error_Success) - { - Terminate(); - return Error_Fail; - } - } - - for(uint32 i = 0; i < sizeof(pControlTextureName) / sizeof(pControlTextureName[0]); ++i) - { - eCode = kContext.CreateTextureFromFile(pControlTextureName[i], pControlTextures + i); - if(eCode != Error_Success) - { - Terminate(); - return Error_Fail; - } - } - - for(uint32 i = 0; i < sizeof(pArrowTextureName) / sizeof(pArrowTextureName[0]); ++i) - { - eCode = kContext.CreateTextureFromFile(pArrowTextureName[i], pArrowTextures + i); - if(eCode != Error_Success) - { - Terminate(); - return Error_Fail; - } - } - - eCode = kContext.CreateTextureFromFile("Data\\Textures\\Dialog1.tga", &pDialog1Texture); - if(eCode != Error_Success) - { - Terminate(); - return Error_Fail; - } - - eCode = kContext.CreateTextureFromFile("Data\\Textures\\Dialog2.tga", &pDialog2Texture); - if(eCode != Error_Success) - { - Terminate(); - return Error_Fail; - } - - eCode = kContext.CreateTextureFromFile("Data\\Textures\\Arrow.tga", &pCursorTexture); - if(eCode != Error_Success) - { - Terminate(); - return Error_Fail; - } - eCode = kContext.CreateVertexBuffer(VerticesPerBlock * sizeof(Vertex::Block), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pBlockVertexBuffer); if(eCode != Error_Success) { @@ -232,14 +116,14 @@ return Error_Fail; } - eCode = kContext.CreateVertexBuffer(TrianglesPerFace * VerticesPerTriangle * sizeof(Vertex::Quad), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pInterfaceVertexBuffer); + eCode = SetupVertexBuffer(); if(eCode != Error_Success) { Terminate(); return Error_Fail; } - return SetupVertexBuffers(); + return kInterface.Initialize(kContext); } /* @@ -247,56 +131,7 @@ */ void View::Terminate() { - if(pCursorTexture) - { - pCursorTexture->Release(); - pCursorTexture = NULL; - } - - if(pDialog1Texture) - { - pDialog1Texture->Release(); - pDialog1Texture = NULL; - } - - if(pDialog2Texture) - { - pDialog2Texture->Release(); - pDialog2Texture = NULL; - } - - for(uint32 i = 0; i < sizeof(pArrowTextures) / sizeof(pArrowTextures[0]); ++i) - { - if(pArrowTextures[i]) - { - pArrowTextures[i]->Release(); - pArrowTextures[i] = NULL; - } - } - - for(uint32 i = 0; i < sizeof(pControlTextures) / sizeof(pControlTextures[0]); ++i) - { - if(pControlTextures[i]) - { - pControlTextures[i]->Release(); - pControlTextures[i] = NULL; - } - } - - for(uint32 i = 0; i < Action_Count; ++i) - { - if(pActionTextures[i]) - { - pActionTextures[i]->Release(); - pActionTextures[i] = NULL; - } - } - - if(pBackgroundTexture) - { - pBackgroundTexture->Release(); - pBackgroundTexture = NULL; - } + kInterface.Terminate(); if(pBlockTexture) { @@ -304,30 +139,12 @@ pBlockTexture = NULL; } - if(pInterfaceVertexBuffer) - { - pInterfaceVertexBuffer->Release(); - pInterfaceVertexBuffer = NULL; - } - if(pBlockVertexBuffer) { pBlockVertexBuffer->Release(); pBlockVertexBuffer = NULL; } - if(pInterfaceFont) - { - pInterfaceFont->Release(); - pInterfaceFont = NULL; - } - - if(pInterfaceEffect) - { - pInterfaceEffect->Release(); - pInterfaceEffect = NULL; - } - if(pBlockEffect) { pBlockEffect->Release(); @@ -391,86 +208,65 @@ } /* - * SetupVertexBuffers + * SetupVertexBuffer */ -ErrorCode View::SetupVertexBuffers() +ErrorCode View::SetupVertexBuffer() { + Vertex::Block* pVertices = NULL; + + HRESULT hResult = pBlockVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD); + if(FAILED(hResult)) { - Vertex::Block* pVertices = NULL; - - HRESULT hResult = pBlockVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD); - if(FAILED(hResult)) - { - return Error_Fail; - } - - const float fU1 = 0.66f; - const float fV1 = 0.66f; - - // front - pVertices[0] = Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 1.00f); - pVertices[1] = Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 0.66f); - pVertices[2] = Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 0.66f); - pVertices[3] = Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 1.00f); - pVertices[4] = Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 0.66f); - pVertices[5] = Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 1.00f); - // back - pVertices[6] = Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 1.00f); - pVertices[7] = Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 0.66f); - pVertices[8] = Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 0.66f); - pVertices[9] = Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 1.00f); - pVertices[10] = Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 0.66f); - pVertices[11] = Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 1.00f); - // left - pVertices[12] = Vertex::Block(-0.5f, 0.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 1.00f); - pVertices[13] = Vertex::Block(-0.5f, 1.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 0.66f); - pVertices[14] = Vertex::Block(-0.5f, 1.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 0.66f); - pVertices[15] = Vertex::Block(-0.5f, 0.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 1.00f); - pVertices[16] = Vertex::Block(-0.5f, 1.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 0.66f); - pVertices[17] = Vertex::Block(-0.5f, 0.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 1.00f); - // right - pVertices[18] = Vertex::Block(+0.5f, 0.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 1.00f); - pVertices[19] = Vertex::Block(+0.5f, 1.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 0.66f); - pVertices[20] = Vertex::Block(+0.5f, 1.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 0.66f); - pVertices[21] = Vertex::Block(+0.5f, 0.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 1.00f); - pVertices[22] = Vertex::Block(+0.5f, 1.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 0.66f); - pVertices[23] = Vertex::Block(+0.5f, 0.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 1.00f); - // top - pVertices[24] = Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.66f); - pVertices[25] = Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.00f); - pVertices[26] = Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.00f); - pVertices[27] = Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.66f); - pVertices[28] = Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.00f); - pVertices[29] = Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.66f); - // bottom - pVertices[30] = Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.66f); - pVertices[31] = Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.00f); - pVertices[32] = Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.00f); - pVertices[33] = Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.66f); - pVertices[34] = Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.00f); - pVertices[35] = Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.66f); - - pBlockVertexBuffer->Unlock(); + return Error_Fail; } - { - Vertex::Quad* pVertices = NULL; - - HRESULT hResult = pInterfaceVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD); - if(FAILED(hResult)) - { - return Error_Fail; - } + const float fU1 = 0.66f; + const float fV1 = 0.66f; - pVertices[0] = Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f); - pVertices[1] = Vertex::Quad(+0.0f, +0.0f, 1.0f, 0.0f, 0.0f); - pVertices[2] = Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f); - pVertices[3] = Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f); - pVertices[4] = Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f); - pVertices[5] = Vertex::Quad(+1.0f, -1.0f, 1.0f, 1.0f, 1.0f); + // front + pVertices[0] = Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 1.00f); + pVertices[1] = Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 0.66f); + pVertices[2] = Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 0.66f); + pVertices[3] = Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 1.00f); + pVertices[4] = Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 0.66f); + pVertices[5] = Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 1.00f); + // back + pVertices[6] = Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 1.00f); + pVertices[7] = Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 0.66f); + pVertices[8] = Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 0.66f); + pVertices[9] = Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 1.00f); + pVertices[10] = Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 0.66f); + pVertices[11] = Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 1.00f); + // left + pVertices[12] = Vertex::Block(-0.5f, 0.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 1.00f); + pVertices[13] = Vertex::Block(-0.5f, 1.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 0.66f); + pVertices[14] = Vertex::Block(-0.5f, 1.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 0.66f); + pVertices[15] = Vertex::Block(-0.5f, 0.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 1.00f); + pVertices[16] = Vertex::Block(-0.5f, 1.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 0.66f); + pVertices[17] = Vertex::Block(-0.5f, 0.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 1.00f); + // right + pVertices[18] = Vertex::Block(+0.5f, 0.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 1.00f); + pVertices[19] = Vertex::Block(+0.5f, 1.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 0.66f); + pVertices[20] = Vertex::Block(+0.5f, 1.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 0.66f); + pVertices[21] = Vertex::Block(+0.5f, 0.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 1.00f); + pVertices[22] = Vertex::Block(+0.5f, 1.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 0.66f); + pVertices[23] = Vertex::Block(+0.5f, 0.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 1.00f); + // top + pVertices[24] = Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.66f); + pVertices[25] = Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.00f); + pVertices[26] = Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.00f); + pVertices[27] = Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.66f); + pVertices[28] = Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.00f); + pVertices[29] = Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.66f); + // bottom + pVertices[30] = Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.66f); + pVertices[31] = Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.00f); + pVertices[32] = Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.00f); + pVertices[33] = Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.66f); + pVertices[34] = Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.00f); + pVertices[35] = Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.66f); - pInterfaceVertexBuffer->Unlock(); - } + pBlockVertexBuffer->Unlock(); return Error_Success; } @@ -505,44 +301,7 @@ */ void View::Render2D() { - Environment* pEnvironment = pModel->GetEnvironment(); - if(pEnvironment) - { - Bot* pBot = pModel->GetBot(); - if(pBot) - { - kContext.SetupCamera2D(pInterfaceEffect); - - uint32 nPasses = 0; - - pInterfaceEffect->SetTechnique(pInterfaceEffect->GetTechnique(0)); - pInterfaceEffect->Begin(&nPasses, 0); - pInterfaceEffect->BeginPass(0); - - //RenderControlPanel(); - RenderBackground(); - RenderToolbar(); - RenderMain(); - RenderFunction(); - RenderControls(); - - if(pModel->nGameState == GameState_Complete) - { - RenderLevelDialog(); - } - else - - if(pModel->nGameState == GameState_Over) - { - RenderGameOverDialog(); - } - - RenderCursor(); - - pInterfaceEffect->EndPass(); - pInterfaceEffect->End(); - } - } + kInterface.Render(kContext, pModel); } /* @@ -589,7 +348,19 @@ D3DXMATRIX kWorldMatrix; D3DXMatrixMultiply(&kWorldMatrix, &kScaleMatrix, &kTranslateMatrix); - RenderBlock(kWorldMatrix, nColor); + const float fAlpha = ((nColor >> 24) & 0xFF) / 255.0f; + const float fRed = ((nColor >> 16) & 0xFF) / 255.0f; + const float fGreen = ((nColor >> 8 ) & 0xFF) / 255.0f; + const float fBlue = ((nColor >> 0 ) & 0xFF) / 255.0f; + + const D3DXVECTOR4 kColorVector(fRed, fGreen, fBlue, fAlpha); + + pBlockEffect->SetMatrix(pBlockEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pBlockEffect->SetVector(pBlockEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pBlockEffect->SetTexture(pBlockEffect->GetParameterByName(NULL, "kTexture"), pBlockTexture); + pBlockEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Block::Declaration, pBlockVertexBuffer, sizeof(Vertex::Block), FacesPerCube * TrianglesPerFace); } } } @@ -615,7 +386,14 @@ D3DXMATRIX kWorldMatrix; D3DXMatrixMultiply(&kWorldMatrix, &kScaleMatrix, &kTranslateMatrix); - RenderBlock(kWorldMatrix, D3DCOLOR_XRGB(0x00, 0x00, 0x00)); + const D3DXVECTOR4 kColorVector(0.0f, 0.0f, 0.0f, 1.0f); + + pBlockEffect->SetMatrix(pBlockEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pBlockEffect->SetVector(pBlockEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pBlockEffect->SetTexture(pBlockEffect->GetParameterByName(NULL, "kTexture"), pBlockTexture); + pBlockEffect->CommitChanges(); + + kContext.DrawTriangles(Vertex::Block::Declaration, pBlockVertexBuffer, sizeof(Vertex::Block), FacesPerCube * TrianglesPerFace); } } } @@ -671,336 +449,6 @@ } /* - * RenderBlock - */ -void View::RenderBlock(const D3DXMATRIX& kWorldMatrix, D3DCOLOR kColor) -{ - const float fAlpha = ((kColor >> 24) & 0xFF) / 255.0f; - const float fRed = ((kColor >> 16) & 0xFF) / 255.0f; - const float fGreen = ((kColor >> 8 ) & 0xFF) / 255.0f; - const float fBlue = ((kColor >> 0 ) & 0xFF) / 255.0f; - - const D3DXVECTOR4 kColorVector(fRed, fGreen, fBlue, fAlpha); - - pBlockEffect->SetMatrix(pBlockEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pBlockEffect->SetVector(pBlockEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pBlockEffect->SetTexture(pBlockEffect->GetParameterByName(NULL, "kTexture"), pBlockTexture); - pBlockEffect->CommitChanges(); - - kContext.DrawTriangles(Vertex::Block::Declaration, pBlockVertexBuffer, sizeof(Vertex::Block), FacesPerCube * TrianglesPerFace); -} - -/* - * RenderBackground - */ -void View::RenderBackground() -{ - const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); - - const float fWidth = 304.0f;//10.0f * ScreenSizeX / 26.0f; - const float fHeight = ScreenSizeY; - const float fX = ScreenSizeX - fWidth; - const float fY = 0.0f; - - D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, fWidth, fHeight, 1.0f); - - D3DXMATRIX kTranslate; - D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + fX + 0.5f, 0.5f * ScreenSizeY - fY + 0.5f, 0.0f); - - D3DXMATRIX kWorldMatrix; - D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); - - pInterfaceEffect->SetMatrix(pInterfaceEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pInterfaceEffect->SetVector(pInterfaceEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pInterfaceEffect->SetTexture(pInterfaceEffect->GetParameterByName(NULL, "kTexture"), pBackgroundTexture); - pInterfaceEffect->CommitChanges(); - - kContext.DrawTriangles(Vertex::Quad::Declaration, pInterfaceVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); -} - -/* - * RenderToolbar - */ -void View::RenderToolbar() -{ - const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); - - for(uint32 i = 0; i < Action_Count; ++i) - { - D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, pModel->kActionBounds[i].Width, pModel->kActionBounds[i].Height, 1.0f); - - D3DXMATRIX kTranslate; - D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->kActionBounds[i].X, 0.5f * ScreenSizeY - pModel->kActionBounds[i].Y, 0.0f); - - D3DXMATRIX kWorldMatrix; - D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); - - pInterfaceEffect->SetMatrix(pInterfaceEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pInterfaceEffect->SetVector(pInterfaceEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pInterfaceEffect->SetTexture(pInterfaceEffect->GetParameterByName(NULL, "kTexture"), pActionTextures[i]); - pInterfaceEffect->CommitChanges(); - - kContext.DrawTriangles(Vertex::Quad::Declaration, pInterfaceVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); - } -} - -/* - * RenderMain - */ -void View::RenderMain() -{ - Code* pCode = pModel->GetFunction(0); - if(pCode) - { - const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); - - for(uint32 i = 0; i < Max(pCode->GetSize(), 16U); ++i) - { - const uint32 nAction = pCode->GetSlot(i); - - if(Action_Forward <= nAction && nAction <= Action_FunctionB) - { - D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, pModel->kMainBounds[i].Width, pModel->kMainBounds[i].Height, 1.0f); - - D3DXMATRIX kTranslate; - D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->kMainBounds[i].X, 0.5f * ScreenSizeY - pModel->kMainBounds[i].Y, 0.0f); - - D3DXMATRIX kWorldMatrix; - D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); - - pInterfaceEffect->SetMatrix(pInterfaceEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pInterfaceEffect->SetVector(pInterfaceEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pInterfaceEffect->SetTexture(pInterfaceEffect->GetParameterByName(NULL, "kTexture"), pActionTextures[nAction - Action_Forward]); - pInterfaceEffect->CommitChanges(); - - kContext.DrawTriangles(Vertex::Quad::Declaration, pInterfaceVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); - } - } - } -} - -/* - * RenderFunction(); - */ -void View::RenderFunction() -{ - Code* pCode = pModel->GetFunction(pModel->nCurrentFunction + 1); - if(pCode) - { - const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); - - for(uint32 i = 0; i < Max(pCode->GetSize(), 8U); ++i) - { - const uint32 nAction = pCode->GetSlot(i); - - if(Action_Forward <= nAction && nAction <= Action_FunctionB) - { - D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, pModel->kFunctionBounds[i].Width, pModel->kFunctionBounds[i].Height, 1.0f); - - D3DXMATRIX kTranslate; - D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->kFunctionBounds[i].X, 0.5f * ScreenSizeY - pModel->kFunctionBounds[i].Y, 0.0f); - - D3DXMATRIX kWorldMatrix; - D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); - - pInterfaceEffect->SetMatrix(pInterfaceEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pInterfaceEffect->SetVector(pInterfaceEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pInterfaceEffect->SetTexture(pInterfaceEffect->GetParameterByName(NULL, "kTexture"), pActionTextures[nAction - Action_Forward]); - pInterfaceEffect->CommitChanges(); - - kContext.DrawTriangles(Vertex::Quad::Declaration, pInterfaceVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); - } - } - } -} - -/* - * RenderControls - */ -void View::RenderControls() -{ - const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); - - for(uint32 i = 0; i < sizeof(pModel->kControlBounds) / sizeof(pModel->kControlBounds[0]); ++i) - { - D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, pModel->kControlBounds[i].Width, pModel->kControlBounds[i].Height, 1.0f); - - D3DXMATRIX kTranslate; - D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->kControlBounds[i].X, 0.5f * ScreenSizeY - pModel->kControlBounds[i].Y, 0.0f); - - D3DXMATRIX kWorldMatrix; - D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); - - pInterfaceEffect->SetMatrix(pInterfaceEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pInterfaceEffect->SetVector(pInterfaceEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pInterfaceEffect->SetTexture(pInterfaceEffect->GetParameterByName(NULL, "kTexture"), pControlTextures[i]); - pInterfaceEffect->CommitChanges(); - - kContext.DrawTriangles(Vertex::Quad::Declaration, pInterfaceVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); - } - - for(uint32 i = 0; i < sizeof(pModel->kArrowBounds) / sizeof(pModel->kArrowBounds[0]); ++i) - { - D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, pModel->kArrowBounds[i].Width, pModel->kArrowBounds[i].Height, 1.0f); - - D3DXMATRIX kTranslate; - D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->kArrowBounds[i].X, 0.5f * ScreenSizeY - pModel->kArrowBounds[i].Y, 0.0f); - - D3DXMATRIX kWorldMatrix; - D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); - - pInterfaceEffect->SetMatrix(pInterfaceEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pInterfaceEffect->SetVector(pInterfaceEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pInterfaceEffect->SetTexture(pInterfaceEffect->GetParameterByName(NULL, "kTexture"), pArrowTextures[i]); - pInterfaceEffect->CommitChanges(); - - kContext.DrawTriangles(Vertex::Quad::Declaration, pInterfaceVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); - } - - const uint32 nColor = D3DCOLOR_XRGB(0, 0, 0); - - RECT kRectangle; - - kRectangle.left = 1008; - kRectangle.top = 199; - kRectangle.right = kRectangle.left + 200; - kRectangle.bottom = kRectangle.top + 200; - - pInterfaceFont->DrawTextA(NULL, "Main", -1, &kRectangle, 0, nColor); - - kRectangle.left = 1008; - kRectangle.top = 472; - kRectangle.right = kRectangle.left + 200; - kRectangle.bottom = kRectangle.top + 200; - - pInterfaceFont->DrawTextA(NULL, "Function", -1, &kRectangle, 0, nColor); - - char kBuffer[16]; - sprintf_s(kBuffer, "%d", pModel->nCurrentFunction + 1); - - kRectangle.left = 1225; - kRectangle.top = 473; - kRectangle.right = kRectangle.left + 200; - kRectangle.bottom = kRectangle.top + 200; - - pInterfaceFont->DrawTextA(NULL, kBuffer, -1, &kRectangle, 0, nColor); -} - -/* - * RenderLevelDialog - */ -void View::RenderLevelDialog() -{ - const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); - - D3DSURFACE_DESC kDescriptor; - pDialog1Texture->GetLevelDesc(0, &kDescriptor); - - const float fSizeX = (float)kDescriptor.Width; - const float fSizeY = (float)kDescriptor.Height; - - D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, fSizeX, fSizeY, 1.0f); - - D3DXMATRIX kTranslate; - //D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->kControlBounds[i].X, 0.5f * ScreenSizeY - pModel->kControlBounds[i].Y, 0.0f); - D3DXMatrixTranslation(&kTranslate, -0.5f * fSizeX, 0.5f * fSizeY, 0.0f); - - D3DXMATRIX kWorldMatrix; - D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); - - pInterfaceEffect->SetMatrix(pInterfaceEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pInterfaceEffect->SetVector(pInterfaceEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pInterfaceEffect->SetTexture(pInterfaceEffect->GetParameterByName(NULL, "kTexture"), pDialog1Texture); - pInterfaceEffect->CommitChanges(); - - kContext.DrawTriangles(Vertex::Quad::Declaration, pInterfaceVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); - - RECT kRectangle; - - kRectangle.left = ScreenSizeX / 2; - kRectangle.top = ScreenSizeY / 2 - 24; - kRectangle.right = ScreenSizeX / 2; - kRectangle.bottom = ScreenSizeY / 2 - 24; - - char kMessage[256]; - sprintf_s(kMessage, "Congratulations!\nYou have completed level %d", pModel->nCurrentLevel); - - pInterfaceFont->DrawTextA(NULL, kMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER | DT_CALCRECT, D3DCOLOR_XRGB(0, 0, 0)); - pInterfaceFont->DrawTextA(NULL, kMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(0, 0, 0)); -} - -/* - * RenderGameOverDialog - */ -void View::RenderGameOverDialog() -{ -} - -/* - * RenderCursor - */ -void View::RenderCursor() -{ - const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); - - if(pCursorTexture) - { - if(pModel->kDragController.IsActive()) - { - const uint32 nAction = pModel->kDragController.GetParameter() - Action_Forward; - - D3DSURFACE_DESC kDescriptor; - pActionTextures[nAction]->GetLevelDesc(0, &kDescriptor); - - const float fSizeX = (float)kDescriptor.Width; - const float fSizeY = (float)kDescriptor.Height; - - D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, fSizeX, fSizeY, 1.0f); - - D3DXMATRIX kTranslate; - D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + (pModel->fMouseX - 0.5f * fSizeX) + 0.5f, 0.5f * ScreenSizeY - (pModel->fMouseY - 0.5f * fSizeY) + 0.5f, 0.0f); - - D3DXMATRIX kWorldMatrix; - D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); - - pInterfaceEffect->SetMatrix(pInterfaceEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pInterfaceEffect->SetVector(pInterfaceEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pInterfaceEffect->SetTexture(pInterfaceEffect->GetParameterByName(NULL, "kTexture"), pActionTextures[nAction]); - pInterfaceEffect->CommitChanges(); - - kContext.DrawTriangles(Vertex::Quad::Declaration, pInterfaceVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); - } - - D3DSURFACE_DESC kDescriptor; - pCursorTexture->GetLevelDesc(0, &kDescriptor); - - D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, (float)kDescriptor.Width, (float)kDescriptor.Height, 1.0f); - - D3DXMATRIX kTranslate; - D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + pModel->fMouseX + 0.5f, 0.5f * ScreenSizeY - pModel->fMouseY + 0.5f, 0.0f); - - D3DXMATRIX kWorldMatrix; - D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); - - pInterfaceEffect->SetMatrix(pInterfaceEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pInterfaceEffect->SetVector(pInterfaceEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pInterfaceEffect->SetTexture(pInterfaceEffect->GetParameterByName(NULL, "kTexture"), pCursorTexture); - pInterfaceEffect->CommitChanges(); - - kContext.DrawTriangles(Vertex::Quad::Declaration, pInterfaceVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); - } -} - -/* * OnMessage */ LRESULT View::OnMessage(UINT nMessage, WPARAM wParam, LPARAM lParam)
--- a/LightClone/Source/View.h Wed Sep 07 13:02:06 2011 -0700 +++ b/LightClone/Source/View.h Wed Sep 07 13:47:48 2011 -0700 @@ -5,13 +5,11 @@ #ifndef __VIEW_H__ #define __VIEW_H__ -//#include <windows.h> -//#include <d3d9.h> -//#include <d3dx9.h> #include "Core.h" #include "Model.h" #include "RenderContext.h" #include "CameraController.h" +#include "Interface.h" /* * View @@ -49,64 +47,19 @@ ID3DXEffect* pBlockEffect; /* - * pInterfaceEffect - */ - ID3DXEffect* pInterfaceEffect; - - /* - * pInterfaceFont - */ - ID3DXFont* pInterfaceFont; - - /* * pBlockVertexBuffer */ IDirect3DVertexBuffer9* pBlockVertexBuffer; /* - * pInterfaceVertexBuffer - */ - IDirect3DVertexBuffer9* pInterfaceVertexBuffer; - - /* * pBlockTexture */ IDirect3DTexture9* pBlockTexture; /* - * pBackgroundTexture - */ - IDirect3DTexture9* pBackgroundTexture; - - /* - * pActionTextures - */ - IDirect3DTexture9* pActionTextures[Action_Count]; - - /* - * pControlTextures - */ - IDirect3DTexture9* pControlTextures[3]; - - /* - * pArrowTextures + * kInterface */ - IDirect3DTexture9* pArrowTextures[2]; - - /* - * pDialog1Texture - */ - IDirect3DTexture9* pDialog1Texture; - - /* - * pDialog2Texture - */ - IDirect3DTexture9* pDialog2Texture; - - /* - * pCursorTexture - */ - IDirect3DTexture9* pCursorTexture; + Interface kInterface; public: @@ -153,9 +106,9 @@ private: /* - * SetupVertexBuffers + * SetupVertexBuffer */ - ErrorCode SetupVertexBuffers(); + ErrorCode SetupVertexBuffer(); /* * Render3D