Mercurial > LightClone
changeset 31:0b729faa4e73
Fixed resource leak; Corrected button state logic
author | koryspansel |
---|---|
date | Tue, 20 Sep 2011 20:41:07 -0700 |
parents | d9e9ce8219f8 |
children | c227be6a15fe |
files | LightClone/Source/Environment.cpp LightClone/Source/GuiButton.cpp LightClone/Source/GuiInterface.cpp LightClone/Source/HashMap.h LightClone/Source/InputManager.cpp LightClone/Source/ResourceManager.cpp LightClone/Source/World.cpp |
diffstat | 7 files changed, 58 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/LightClone/Source/Environment.cpp Mon Sep 19 14:55:26 2011 -0700 +++ b/LightClone/Source/Environment.cpp Tue Sep 20 20:41:07 2011 -0700 @@ -37,7 +37,7 @@ ErrorCode eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\Environment.fx", &pEffect); if(eCode == Error_Success) { - eCode = pResourceManager->CreateTextureFromFile("Data\\Textures\\Block02.tga", &pTexture); + eCode = pResourceManager->CreateTextureFromFile("Data\\Textures\\Block04.tga", &pTexture); if(eCode == Error_Success) { eCode = pResourceManager->CreateVertexBuffer(VerticesPerBlock * sizeof(Vertex::Block), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pVertexBuffer);
--- a/LightClone/Source/GuiButton.cpp Mon Sep 19 14:55:26 2011 -0700 +++ b/LightClone/Source/GuiButton.cpp Tue Sep 20 20:41:07 2011 -0700 @@ -16,6 +16,8 @@ */ GuiButton::GuiButton() : nState(GuiButtonState_Normal), pEffect(NULL), pVertexBuffer(NULL), pFont(NULL) { + SetFlag(GuiElementFlag_Pickable); + memset(pTexture, 0, sizeof(pTexture)); } @@ -183,6 +185,10 @@ */ void GuiButton::OnMouseLeave() { + if(!pInterface->IsCursorAcquiredBy(this)) + { + nState = GuiButtonState_Normal; + } } /* @@ -191,6 +197,7 @@ void GuiButton::OnMouseDown(uint32 nButton, float fX, float fY) { pInterface->AcquireCursor(this); + nState = GuiButtonState_Down; } /*
--- a/LightClone/Source/GuiInterface.cpp Mon Sep 19 14:55:26 2011 -0700 +++ b/LightClone/Source/GuiInterface.cpp Tue Sep 20 20:41:07 2011 -0700 @@ -117,7 +117,7 @@ { if(pCaptureElement) { - pElement->OnMouseDown(nButton, fMouseX, fMouseY); + pCaptureElement->OnMouseDown(nButton, fMouseX, fMouseY); } else @@ -217,7 +217,7 @@ */ bool GuiInterface::IsCursorAcquiredBy(GuiElement* pElement) const { - return pDragElement == pElement; + return pCaptureElement == pElement; } /*
--- a/LightClone/Source/HashMap.h Mon Sep 19 14:55:26 2011 -0700 +++ b/LightClone/Source/HashMap.h Tue Sep 20 20:41:07 2011 -0700 @@ -120,7 +120,7 @@ */ Value* Add(Key& kKey) { - uint32 nSlot = GetSlot(kKey); + const uint32 nSlot = GetSlot(kKey); Node* pNode = new Node(kKey); pNode->pNext = pTable[nSlot]; @@ -134,6 +134,33 @@ */ void Remove(const Key& kKey) { + const uint32 nSlot = GetSlot(kKey); + + Node* pNode = pTable[nSlot]; + Node* pLast = NULL; + + while(pNode) + { + if(pNode->kKey == kKey) + break; + + pLast = pNode; + pNode = pNode->pNext; + } + + if(pNode) + { + if(pLast) + { + pLast->pNext = pNode->pNext; + } + else + { + pTable[nSlot] = pNode->pNext; + } + + delete pNode; + } } /*
--- a/LightClone/Source/InputManager.cpp Mon Sep 19 14:55:26 2011 -0700 +++ b/LightClone/Source/InputManager.cpp Tue Sep 20 20:41:07 2011 -0700 @@ -282,7 +282,7 @@ */ bool InputManager::IsButtonReleased(uint32 nButton) const { - return ((kCurrentMouseState.rgbButtons[nButton] & 0x80) == 0) && ((kPreviousMouseState.rgbButtons[nButton] & 0x80) == 0); + return ((kCurrentMouseState.rgbButtons[nButton] & 0x80) == 0) && ((kPreviousMouseState.rgbButtons[nButton] & 0x80) != 0); } /*
--- a/LightClone/Source/ResourceManager.cpp Mon Sep 19 14:55:26 2011 -0700 +++ b/LightClone/Source/ResourceManager.cpp Tue Sep 20 20:41:07 2011 -0700 @@ -99,13 +99,20 @@ if(pGraphicsDevice) { - IDirect3DTexture9** pInstance = kTextureCache.Find(ResourcePath(pName)); + ResourcePath kPath(pName); + + IDirect3DTexture9** pInstance = kTextureCache.Find(kPath); if(!pInstance) { - pInstance = kTextureCache.Add(ResourcePath(pName)); + pInstance = kTextureCache.Add(kPath); if(pInstance) { eCode = CreateTextureHelper(pGraphicsDevice, pName, pInstance); + if(eCode != Error_Success || !pInstance) + { + kTextureCache.Remove(kPath); + eCode = Error_Fail; + } } } else
--- a/LightClone/Source/World.cpp Mon Sep 19 14:55:26 2011 -0700 +++ b/LightClone/Source/World.cpp Tue Sep 20 20:41:07 2011 -0700 @@ -89,7 +89,7 @@ eCode = InitializeInterface(pResourceManager); if(eCode == Error_Success) { - nCurrentLevel = 0; + nCurrentLevel = 2; nGameState = GameState_LoadMap; } } @@ -304,7 +304,7 @@ pFunctionMain = new GuiImage(); pFunctionMain->Initialize(pResourceManager); - pFunctionMain->SetTexture("Data\\Textures\\Panel.tga", true); + //pFunctionMain->SetTexture("Data\\Textures\\Panel.tga", true); pFunctionMain->SetPosition(1000.0f, 100.0f); for(uint32 i = 0; i < sizeof(pToolbarSlot) / sizeof(pToolbarSlot[0]); ++i) @@ -319,14 +319,14 @@ pFunctionA = new GuiImage(); pFunctionA->Initialize(pResourceManager); - pFunctionA->SetTexture("Data\\Textures\\Panel.tga", true); + //pFunctionA->SetTexture("Data\\Textures\\Panel.tga", true); pFunctionA->SetPosition(1000.0f, 400.0f); //TODO: Add slots for function a pFunctionB = new GuiImage(); pFunctionB->Initialize(pResourceManager); - pFunctionB->SetTexture("Data\\Textures\\Panel.tga", true); + //pFunctionB->SetTexture("Data\\Textures\\Panel.tga", true); pFunctionB->SetPosition(1000.0f, 600.0f); //TODO: Add slots for function b @@ -334,12 +334,16 @@ pButtonPlay = new GuiButton(); pButtonPlay->Initialize(pResourceManager); pButtonPlay->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Play.tga", true); + pButtonPlay->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Play.tga", true); + pButtonPlay->SetTexture(GuiButtonState_Down, "Data\\Textures\\Play.tga", true); pButtonPlay->SetPosition(1023.0f + 0.0f * 54.0f, 640.0f); pButtonPlay->Subscribe(GuiButton::EventClick, &World::OnPlay, this); pButtonStop = new GuiButton(); pButtonStop->Initialize(pResourceManager); pButtonStop->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Stop.tga", true); + pButtonStop->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Stop.tga", true); + pButtonStop->SetTexture(GuiButtonState_Down, "Data\\Textures\\Stop.tga", true); pButtonStop->SetPosition(1023.0f + 1.0f * 54.0f, 640.0f); pButtonStop->Subscribe(GuiButton::EventClick, &World::OnStop, this); @@ -354,6 +358,8 @@ pButtonExit = new GuiButton(); pButtonExit->Initialize(pResourceManager); pButtonExit->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Exit.tga", true); + pButtonExit->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Stop.tga", true); + pButtonExit->SetTexture(GuiButtonState_Down, "Data\\Textures\\Play.tga", true); pButtonExit->SetPosition(1023.0f + 3.0f * 54.0f, 640.0f); pButtonExit->Subscribe(GuiButton::EventClick, &World::OnExit, this);