Mercurial > LightClone
changeset 38:2caa7c7e2cb5
Refactored program; Added dialog
author | koryspansel |
---|---|
date | Wed, 21 Sep 2011 21:40:19 -0700 |
parents | 58a16d529d95 |
children | d0ce73ced12e |
files | LightClone/LightClone.vcproj LightClone/Source/Bot.cpp LightClone/Source/Bot.h LightClone/Source/CodePanel.cpp LightClone/Source/CodePanel.h LightClone/Source/Dialog.cpp LightClone/Source/Dialog.h LightClone/Source/Program.cpp LightClone/Source/Program.h LightClone/Source/World.cpp LightClone/Source/World.h |
diffstat | 11 files changed, 230 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
--- a/LightClone/LightClone.vcproj Wed Sep 21 20:30:29 2011 -0700 +++ b/LightClone/LightClone.vcproj Wed Sep 21 21:40:19 2011 -0700 @@ -197,6 +197,10 @@ > </File> <File + RelativePath=".\Source\Dialog.cpp" + > + </File> + <File RelativePath=".\Source\Environment.cpp" > </File> @@ -351,6 +355,10 @@ > </File> <File + RelativePath=".\Source\Dialog.h" + > + </File> + <File RelativePath=".\Source\Environment.h" > </File>
--- a/LightClone/Source/Bot.cpp Wed Sep 21 20:30:29 2011 -0700 +++ b/LightClone/Source/Bot.cpp Wed Sep 21 21:40:19 2011 -0700 @@ -174,39 +174,11 @@ } /* - * AddFunction - */ -/* -void Bot::AddFunction(uint32 nFunction, uint32 nSize) -{ - kMachine.AddFunction((uint8)nFunction, (uint8)nSize * 2); -} -*/ - -/* * Upload */ -/* -ErrorCode Bot::Upload(Code* pCode, uint32 nCount) +ErrorCode Bot::Upload(const Program& kProgram) { - ErrorCode eCode = Error_Success; - - kMachine.Reset(); - kMachine.ClearMemory(); - - kMachine.RemoveAllFunctions(); - kMachine.AddFunction(0, (uint8)MainFunctionLength * 2); - - for(uint32 i = 0; i < nCount && eCode == Error_Success; ++i) - { - kMachine.AddFunction(i + 1, (uint8)pCode[i].GetSize() * 2); - - uint32 nSize = kMachine.GetFunctionSize(i); - uint8* pData = kMachine.GetFunctionMemory(i); - - eCode = Compile(pCode + i, pData, nSize); - } - + ErrorCode eCode = kProgram.Upload(kMachine); if(eCode == Error_Success) { nState = BotState_Evaluate; @@ -214,15 +186,6 @@ return eCode; } -*/ - -/* - * GetVirtualMachine - */ -VirtualMachine& Bot::GetVirtualMachine() -{ - return kMachine; -} /* * Update @@ -380,8 +343,8 @@ const D3DXVECTOR3& kPosition = GetWorldPosition(); const D3DXVECTOR3& kOrientation = GetWorldOrientation(); - const float fOffsetX = -0.5f * (pEnvironment->GetWidth() * pEnvironment->GetScale().x); - const float fOffsetZ = -0.5f * (pEnvironment->GetHeight() * pEnvironment->GetScale().z); + const float fOffsetX = -0.5f * (pEnvironment->GetWidth() * pEnvironment->GetScale().x) + 0.5f * pEnvironment->GetScale().x; + const float fOffsetZ = -0.5f * (pEnvironment->GetHeight() * pEnvironment->GetScale().z) + 0.5f * pEnvironment->GetScale().z; uint32 nPasses = 0;
--- a/LightClone/Source/Bot.h Wed Sep 21 20:30:29 2011 -0700 +++ b/LightClone/Source/Bot.h Wed Sep 21 21:40:19 2011 -0700 @@ -12,6 +12,7 @@ #include "Environment.h" #include "Code.h" #include "Clock.h" +#include "Program.h" /* * BotState @@ -188,19 +189,9 @@ const D3DXVECTOR3 GetWorldOrientation() const; /* - * AddFunction - */ - //void AddFunction(uint32 nFunction, uint32 nSize); - - /* * Upload */ - //ErrorCode Upload(Code* pCode, uint32 nCount); - - /* - * GetVirtualMachine - */ - VirtualMachine& GetVirtualMachine(); + ErrorCode Upload(const Program& kProgram); /* * Update @@ -215,11 +206,6 @@ private: /* - * Compile - */ - //ErrorCode Compile(Code* pCode, uint8* pData, uint32 nSize); - - /* * SetupVertexBuffer */ ErrorCode SetupVertexBuffer();
--- a/LightClone/Source/CodePanel.cpp Wed Sep 21 20:30:29 2011 -0700 +++ b/LightClone/Source/CodePanel.cpp Wed Sep 21 21:40:19 2011 -0700 @@ -55,11 +55,19 @@ } /* - * SetSlot + * SetAction */ -void CodePanel::SetSlot(uint32 nSlot, uint32 nAction) +void CodePanel::SetAction(uint32 nIndex, uint32 nAction) { - pSlot[nSlot].SetAction(nAction); + pSlot[nIndex].SetAction(nAction); +} + +/* + * GetAction + */ +uint32 CodePanel::GetAction(uint32 nIndex) const +{ + return pSlot[nIndex].GetAction(); } /*
--- a/LightClone/Source/CodePanel.h Wed Sep 21 20:30:29 2011 -0700 +++ b/LightClone/Source/CodePanel.h Wed Sep 21 21:40:19 2011 -0700 @@ -73,9 +73,14 @@ void SetAvailableSlots(uint32 nCount); /* - * SetSlot + * SetAction */ - void SetSlot(uint32 nSlot, uint32 nAction); + void SetAction(uint32 nIndex, uint32 nAction); + + /* + * GetAction + */ + uint32 GetAction(uint32 nIndex) const; /* * Clear
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/Dialog.cpp Wed Sep 21 21:40:19 2011 -0700 @@ -0,0 +1,5 @@ +/* + * Dialog + */ + +#include "Dialog.h"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/Dialog.h Wed Sep 21 21:40:19 2011 -0700 @@ -0,0 +1,88 @@ +/* + * Dialog + */ + +#ifndef __DIALOG_H__ +#define __DIALOG_H__ + +#include "Core.h" +#include "GuiImage.h" +#include "GuiLabel.h" +#include "GuiButton.h" + +/* + * Dialog + */ +template<uint32 ButtonCount> +class Dialog : public GuiImage +{ + /* + * kLabel + */ + GuiLabel kLabel; + + /* + * kButton + */ + GuiButton kButton[ButtonCount]; + +public: + + /* + * Dialog + */ + Dialog() : GuiImage() + { + } + + /* + * Initialize + */ + virtual ErrorCode Initialize(ResourceManager* pResourceManager) + { + ErrorCode eCode = GuiImage::Initialize(pResourceManager); + if(eCode == Error_Success) + { + SetTexture("Data\\Textures\\Dialog.tga", true); + //SetDimensions(300.0f, 200.0f); + + kLabel.Initialize(pResourceManager); + kLabel.SetPosition(150.0f, 50.0f); + kLabel.SetLabelFlag(GuiLabelFlag_CenterX); + + Add(&kLabel); + + for(uint32 i = 0; i < ButtonCount; ++i) + { + kButton[i].Initialize(pResourceManager); + kButton[i].SetTexture(GuiButtonState_Normal, "Data\\Textures\\ButtonN.tga", true); + kButton[i].SetTexture(GuiButtonState_Hover, "Data\\Textures\\ButtonH.tga"); + kButton[i].SetTexture(GuiButtonState_Down, "Data\\Textures\\ButtonD.tga"); + kButton[i].Subscribe(GuiButton::EventClick, &Dialog::OnClick, this); + + Add(&kButton[i]); + } + } + + return eCode; + } + +private: + + /* + * OnClick + */ + void OnClick(GuiEventArguments& kArguments) + { + if(kArguments.pSource == &kButton[0]) + { + } + else + + if(kArguments.pSource == &kButton[1]) + { + } + } +}; + +#endif //__DIALOG_H__
--- a/LightClone/Source/Program.cpp Wed Sep 21 20:30:29 2011 -0700 +++ b/LightClone/Source/Program.cpp Wed Sep 21 21:40:19 2011 -0700 @@ -5,24 +5,6 @@ #include "Program.h" /* - * CalculateSize - */ -uint32 Program::Function::CalculateSize() -{ - uint32 nSize = 0; - - for(uint32 i = 0; i < MaximumInstructionCount; ++i) - { - if(nInstruction[i] > 0) - { - ++nSize; - } - } - - return nSize; -} - -/* * Program */ Program::Program() @@ -34,7 +16,7 @@ */ ErrorCode Program::Initialize() { - return Error_Success; + return Clear(), Error_Success; } /* @@ -45,16 +27,34 @@ } /* + * SetAction + */ +void Program::SetAction(uint32 nFunction, uint32 nIndex, uint32 nAction) +{ + if(nFunction < FunctionCount && nIndex < Function::MaximumInstructionCount) + { + kFunction[nFunction].nInstruction[nIndex] = nAction; + } +} + +/* * Clear */ void Program::Clear() { + for(uint32 i = 0; i < FunctionCount; ++i) + { + for(uint32 j = 0; j < Function::MaximumInstructionCount; ++j) + { + kFunction[i].nInstruction[j] = Action_Default; + } + } } /* * Upload */ -ErrorCode Program::Upload(VirtualMachine& kMachine) +ErrorCode Program::Upload(VirtualMachine& kMachine) const { ErrorCode eCode = Error_Success; @@ -62,7 +62,7 @@ kMachine.ClearMemory(); kMachine.RemoveAllFunctions(); - for(uint32 i = 0; i < nFunctionCount && eCode == Error_Success; ++i) + for(uint32 i = 0; i < FunctionCount && eCode == Error_Success; ++i) { kMachine.AddFunction(i, kFunction[i].CalculateSize()); @@ -78,7 +78,7 @@ /* * Compile */ -ErrorCode Program::Compile(uint32 nIndex, uint8* pData, uint32 nSize) +ErrorCode Program::Compile(uint32 nIndex, uint8* pData, uint32 nSize) const { for(uint32 i = 0; i < Function::MaximumInstructionCount; ++i) {
--- a/LightClone/Source/Program.h Wed Sep 21 20:30:29 2011 -0700 +++ b/LightClone/Source/Program.h Wed Sep 21 21:40:19 2011 -0700 @@ -14,9 +14,9 @@ class Program { /* - * MaximumFunctionCount + * FunctionCount */ - static const uint32 MaximumFunctionCount = 3; + static const uint32 FunctionCount = 3; /* * Function @@ -36,19 +36,24 @@ /* * CalculateSize */ - uint32 CalculateSize(); + uint32 CalculateSize() const + { + uint32 nSize = 0; + for(uint32 i = 0; i < MaximumInstructionCount; ++i) + { + if(nInstruction[i] > 0) + ++nSize; + } + + return nSize; + } }; /* * kFunction */ - Function kFunction[MaximumFunctionCount]; - - /* - * nFunctionCount - */ - uint32 nFunctionCount; + Function kFunction[FunctionCount]; public: @@ -68,6 +73,11 @@ void Terminate(); /* + * SetAction + */ + void SetAction(uint32 nFunction, uint32 nIndex, uint32 nAction); + + /* * Clear */ void Clear(); @@ -75,14 +85,14 @@ /* * Upload */ - ErrorCode Upload(VirtualMachine& kMachine); + ErrorCode Upload(VirtualMachine& kMachine) const; private: /* * Compile */ - ErrorCode Compile(uint32 nFunction, uint8* pData, uint32 nSize); + ErrorCode Compile(uint32 nFunction, uint8* pData, uint32 nSize) const; }; #endif //__PROGRAM_H__
--- a/LightClone/Source/World.cpp Wed Sep 21 20:30:29 2011 -0700 +++ b/LightClone/Source/World.cpp Wed Sep 21 21:40:19 2011 -0700 @@ -145,6 +145,7 @@ { //kDialog.Reset("Some message"); //kDialog.AddButton(DialogButton_Ok, "Ok", 0.0f, 0.0f, 0.0f, 0.0f); + //pLevelDialog->SetFlag(GuiElementFlag_Visible); nGameState = GameState_Complete; } @@ -153,6 +154,12 @@ kInterface.Update(fElapsed); } + else + + if(nGameState == GameState_Complete) + { + kInterface.Update(fElapsed); + } } /* @@ -209,13 +216,13 @@ pToolbar->Initialize(pResourceManager); pToolbar->SetTexture("Data\\Textures\\PanelA.png"); pToolbar->SetPosition(16, 16.0f); - pToolbar->SetSlot(0, Action_Forward); - pToolbar->SetSlot(1, Action_RotateCW); - pToolbar->SetSlot(2, Action_RotateCCW); - pToolbar->SetSlot(3, Action_Jump); - pToolbar->SetSlot(4, Action_Light); - pToolbar->SetSlot(5, Action_FunctionA); - pToolbar->SetSlot(6, Action_FunctionB); + pToolbar->SetAction(0, Action_Forward); + pToolbar->SetAction(1, Action_RotateCW); + pToolbar->SetAction(2, Action_RotateCCW); + pToolbar->SetAction(3, Action_Jump); + pToolbar->SetAction(4, Action_Light); + pToolbar->SetAction(5, Action_FunctionA); + pToolbar->SetAction(6, Action_FunctionB); pToolbar->SetPermanent(true); GuiLabel* pMainLabel = new GuiLabel(); @@ -229,6 +236,7 @@ pMain->Initialize(pResourceManager); pMain->SetTexture("Data\\Textures\\PanelB.png"); pMain->SetPosition(16.0f, 160.0f); + pMain->Subscribe(CodePanel::EventAction, &World::OnAction, this); GuiLabel* pFunctionALabel = new GuiLabel(); pFunctionALabel->Initialize(pResourceManager); @@ -241,7 +249,7 @@ pFunctionA->Initialize(pResourceManager); pFunctionA->SetTexture("Data\\Textures\\PanelA.png"); pFunctionA->SetPosition(16.0f, 360.0f); - //pFunctionA->Upload( + pFunctionA->Subscribe(CodePanel::EventAction, &World::OnAction, this); GuiLabel* pFunctionBLabel = new GuiLabel(); pFunctionBLabel->Initialize(pResourceManager); @@ -254,6 +262,7 @@ pFunctionB->Initialize(pResourceManager); pFunctionB->SetTexture("Data\\Textures\\PanelA.png"); pFunctionB->SetPosition(16.0f, 504.0f); + pFunctionB->Subscribe(CodePanel::EventAction, &World::OnAction, this); const float fButtonPadding = 32.0f; const float fButtonSpacing = 8.0f; @@ -315,6 +324,7 @@ pBackground->Add(pButtonReset); pBackground->Add(pButtonExit); + /* pLevelDialog = new GuiImage(); pLevelDialog->Initialize(pResourceManager); pLevelDialog->ClearFlag(GuiElementFlag_Visible); @@ -348,10 +358,11 @@ pGameDialogOk->Subscribe(GuiButton::EventClick, &World::OnExit, this); pGameDialog->Add(pGameDialogOk); + */ kInterface.Add(pBackground); - kInterface.Add(pLevelDialog); - kInterface.Add(pGameDialog); + //kInterface.Add(pLevelDialog); + //kInterface.Add(pGameDialog); } return eCode; @@ -416,6 +427,31 @@ } /* + * OnAction + */ +void World::OnAction(GuiEventArguments& kArguments) +{ + ActionArguments& kActionArguments = (ActionArguments&)kArguments; + + if(kArguments.pSource == pMain) + { + kProgram.SetAction(0, kActionArguments.nSlot, pMain->GetAction(kActionArguments.nSlot)); + } + else + + if(kArguments.pSource == pFunctionA) + { + kProgram.SetAction(1, kActionArguments.nSlot, pFunctionA->GetAction(kActionArguments.nSlot)); + } + else + + if(kArguments.pSource == pFunctionB) + { + kProgram.SetAction(2, kActionArguments.nSlot, pFunctionB->GetAction(kActionArguments.nSlot)); + } +} + +/* * OnPlay */ void World::OnPlay(GuiEventArguments& kArguments) @@ -427,8 +463,7 @@ kBot.Reset(); kBot.SetPosition(kLoader.GetInitialPosition()); kBot.SetDirection(kLoader.GetInitialDirection()); - - kProgram.Upload(kBot.GetVirtualMachine()); + kBot.Upload(kProgram); nSimulationState = SimulationState_Active; }
--- a/LightClone/Source/World.h Wed Sep 21 20:30:29 2011 -0700 +++ b/LightClone/Source/World.h Wed Sep 21 21:40:19 2011 -0700 @@ -20,6 +20,7 @@ #include "GuiButton.h" #include "CodePanel.h" #include "Program.h" +#include "Dialog.h" /* * World @@ -129,22 +130,27 @@ /* * pLevelDialog */ - GuiImage* pLevelDialog; + //GuiImage* pLevelDialog; /* * pLevelDialogOk */ - GuiButton* pLevelDialogOk; + //GuiButton* pLevelDialogOk; /* * pGameDialog */ - GuiImage* pGameDialog; + //GuiImage* pGameDialog; /* * pGameDialogOk */ - GuiButton* pGameDialogOk; + //GuiButton* pGameDialogOk; + + /* + * kLevelDialog + */ + Dialog<1> kLevelDialog; public: @@ -226,6 +232,11 @@ void ProcessInput(float fElapsed); /* + * OnAction + */ + void OnAction(GuiEventArguments& kArguments); + + /* * OnPlay */ void OnPlay(GuiEventArguments& kArguments);