# HG changeset patch
# User koryspansel
# Date 1316666419 25200
# Node ID 2caa7c7e2cb562a28f6bdb8e71b41ebd568d5b54
# Parent 58a16d529d95cf8f8a6116e042f92ade7355b5ee
Refactored program; Added dialog
diff -r 58a16d529d95 -r 2caa7c7e2cb5 LightClone/LightClone.vcproj
--- 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 @@
>
+
+
@@ -351,6 +355,10 @@
>
+
+
diff -r 58a16d529d95 -r 2caa7c7e2cb5 LightClone/Source/Bot.cpp
--- 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;
diff -r 58a16d529d95 -r 2caa7c7e2cb5 LightClone/Source/Bot.h
--- 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();
diff -r 58a16d529d95 -r 2caa7c7e2cb5 LightClone/Source/CodePanel.cpp
--- 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();
}
/*
diff -r 58a16d529d95 -r 2caa7c7e2cb5 LightClone/Source/CodePanel.h
--- 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
diff -r 58a16d529d95 -r 2caa7c7e2cb5 LightClone/Source/Dialog.cpp
--- /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"
diff -r 58a16d529d95 -r 2caa7c7e2cb5 LightClone/Source/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
+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__
diff -r 58a16d529d95 -r 2caa7c7e2cb5 LightClone/Source/Program.cpp
--- 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)
{
diff -r 58a16d529d95 -r 2caa7c7e2cb5 LightClone/Source/Program.h
--- 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__
diff -r 58a16d529d95 -r 2caa7c7e2cb5 LightClone/Source/World.cpp
--- 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;
}
diff -r 58a16d529d95 -r 2caa7c7e2cb5 LightClone/Source/World.h
--- 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);