changeset 71:bc8afcf7e1ec

Refactor world into game screen
author koryspansel <koryspansel@bendbroadband.com>
date Tue, 11 Oct 2011 13:20:43 -0700
parents ffaeccdc105e
children 9a9be3d8632e
files LightClone/LightClone.vcproj LightClone/Source/FixedStack.h LightClone/Source/FixedString.h LightClone/Source/GameScreen.cpp LightClone/Source/GameScreen.h LightClone/Source/HashMap.h LightClone/Source/Mediator.cpp LightClone/Source/Screen.cpp LightClone/Source/Screen.h LightClone/Source/ScreenManager.cpp LightClone/Source/ScreenManager.h LightClone/Source/World.cpp LightClone/Source/World.h
diffstat 13 files changed, 970 insertions(+), 986 deletions(-) [+]
line wrap: on
line diff
--- a/LightClone/LightClone.vcproj	Tue Oct 11 12:09:04 2011 -0700
+++ b/LightClone/LightClone.vcproj	Tue Oct 11 13:20:43 2011 -0700
@@ -226,10 +226,6 @@
 				RelativePath=".\Source\VirtualMachine.cpp"
 				>
 			</File>
-			<File
-				RelativePath=".\Source\World.cpp"
-				>
-			</File>
 			<Filter
 				Name="Gui"
 				>
@@ -408,10 +404,6 @@
 				RelativePath=".\Source\VirtualMachine.h"
 				>
 			</File>
-			<File
-				RelativePath=".\Source\World.h"
-				>
-			</File>
 			<Filter
 				Name="Gui"
 				>
--- a/LightClone/Source/FixedStack.h	Tue Oct 11 12:09:04 2011 -0700
+++ b/LightClone/Source/FixedStack.h	Tue Oct 11 13:20:43 2011 -0700
@@ -85,7 +85,7 @@
 	 */
 	Type& operator[](uint32 nIndex)
 	{
-		ASSERT(nIndex < nTop + 1);
+		ASSERT(nIndex < (uint32)(nTop + 1));
 		return kStack[nIndex];
 	}
 
@@ -94,7 +94,7 @@
 	 */
 	const Type& operator[](uint32 nIndex) const
 	{
-		ASSERT(nIndex < nTop + 1);
+		ASSERT(nIndex < (uint32)(nTop + 1));
 		return kStack[nIndex];
 	}
 };
--- a/LightClone/Source/FixedString.h	Tue Oct 11 12:09:04 2011 -0700
+++ b/LightClone/Source/FixedString.h	Tue Oct 11 13:20:43 2011 -0700
@@ -70,9 +70,12 @@
 	 */
 	FixedString(const char* pValue) : nLength(0)
 	{
-		while(*pValue)
+		if(pValue)
 		{
-			kString[nLength++] = *pValue++;
+			while(*pValue)
+			{
+				kString[nLength++] = *pValue++;
+			}
 		}
 
 		kString[nLength] = 0;
--- a/LightClone/Source/GameScreen.cpp	Tue Oct 11 12:09:04 2011 -0700
+++ b/LightClone/Source/GameScreen.cpp	Tue Oct 11 13:20:43 2011 -0700
@@ -9,15 +9,55 @@
  */
 ErrorCode GameScreen::Initialize(ServiceProvider* pServiceProvider)
 {
-	ErrorCode eCode = kWorld.Initialize(pServiceProvider);
+	ErrorCode eCode = kEnvironment.Initialize(pServiceProvider);
 	if(eCode != Error_Success)
 	{
-		TRACE("Error: Failed to initialize world\n");
+		TRACE("Error: Failed to initialize environment\n");
+
+		Terminate();
+		return eCode;
+	}
+
+	eCode = kBot.Initialize(pServiceProvider);
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to initialize bot\n");
 
 		Terminate();
 		return eCode;
 	}
 
+	eCode = kProgram.Initialize();
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to initialize program\n");
+
+		Terminate();
+		return eCode;
+	}
+
+	eCode = pServiceProvider->GetService("InputManager", &pInputManager);
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to acquire input manager\n");
+
+		Terminate();
+		return eCode;
+	}
+
+	eCode = InitializeInterface(pServiceProvider);				
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to initialize interface\n");
+
+		Terminate();
+		return eCode;
+	}
+
+	nLogicState			= LogicState_LevelLoad;
+	nSimulationState	= SimulationState_Idle;
+	nCurrentLevel		= 0;
+
 	return eCode;
 }
 
@@ -26,7 +66,10 @@
  */
 void GameScreen::Terminate()
 {
-	kWorld.Terminate();
+	kInterface.Terminate();
+	kProgram.Terminate();
+	kBot.Terminate();
+	kEnvironment.Terminate();
 
 	Screen::Terminate();
 }
@@ -36,7 +79,20 @@
  */
 void GameScreen::Update(float fElapsed)
 {
-	kWorld.Update(fElapsed);
+	pInputManager->Update(fElapsed);
+
+	UpdateInput(fElapsed);
+	UpdateLogic(fElapsed);
+
+	{
+		const D3DXVECTOR3& kCameraPosition = kCameraController.GetLocation();
+
+		char kBuffer[256];
+		sprintf_s(kBuffer, "Camera: <%.2f, %.2f, %.2f> (%.2f, %.2f, %.2f)", kCameraPosition.x, kCameraPosition.y, kCameraPosition.z, kCameraController.fCameraDistance, kCameraController.fCameraYaw, kCameraController.fCameraPitch);
+		pDebugText->SetText(kBuffer);
+	}
+
+	kInterface.Update(fElapsed);
 }
 
 /*
@@ -44,5 +100,522 @@
  */
 void GameScreen::Render(RenderContext& kContext)
 {
-	kWorld.Render(kContext);
+	if(nLogicState != LogicState_LevelLoad)
+	{
+		D3DVIEWPORT9 kOriginal;
+		kContext.GetViewport(&kOriginal);
+
+		D3DVIEWPORT9 kViewport;
+		kViewport.X			= 0;
+		kViewport.Y			= 0;
+		kViewport.Width		= ScreenSizeX - 280;	// minus size of interface
+		kViewport.Height	= ScreenSizeY;
+		kViewport.MinZ		= kOriginal.MinZ;
+		kViewport.MaxZ		= kOriginal.MaxZ;
+
+		kContext.SetViewport(kViewport);
+
+		kCameraController.SetMode(CameraMode_3D);
+	
+		kEnvironment.Render(kContext, kCameraController);
+		kBot.Render(kContext, kCameraController);
+
+		kContext.SetViewport(kOriginal);
+	}
+
+	kCameraController.SetMode(CameraMode_2D);
+	kInterface.Render(kContext, kCameraController);
+}
+
+/*
+ * Load
+ */
+ErrorCode GameScreen::Load(const char* pName)
+{
+	ErrorCode eCode = kLoader.Load(pName);
+	if(eCode == Error_Success)
+	{
+		const Size& kSize = kLoader.GetSize();
+
+		eCode = kEnvironment.Setup(kSize.X, kSize.Y);
+		if(eCode == Error_Success)
+		{
+			for(uint32 nY = 0; nY < kSize.Y; ++nY)
+			{
+				for(uint32 nX = 0; nX < kSize.X; ++nX)
+				{
+					kEnvironment.SetType(nX, nY, kLoader.GetTowerType(nX, nY));
+					kEnvironment.SetAltitude(nX, nY, kLoader.GetTowerHeight(nX, nY));
+				}
+			}
+
+			kBot.Setup(&kEnvironment);
+			kBot.SetPosition(kLoader.GetInitialPosition());
+			kBot.SetDirection(kLoader.GetInitialDirection());
+
+			//kCameraController.SetDistance(
+		}
+	}
+
+	return eCode;
+}
+
+/*
+ * InitializeInterface
+ */
+ErrorCode GameScreen::InitializeInterface(ServiceProvider* pServiceProvider)
+{
+	ErrorCode eCode = kInterface.Initialize(pServiceProvider);
+	if(eCode == Error_Success)
+	{
+		pBackground = new GuiImage();
+		pBackground->Initialize(pServiceProvider);
+		pBackground->SetTexture("Data\\Textures\\Background04.tga", true);
+		pBackground->SetPosition(ScreenSizeX - pBackground->GetWidth(), 0.0f);
+		pBackground->SetDepth(512.0f);
+
+		pToolbar = new ActionPanel(4, 2);
+		pToolbar->Initialize(pServiceProvider);
+		pToolbar->SetTexture("Data\\Textures\\PanelA.png");
+		pToolbar->SetPosition(16, 16.0f);
+		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);
+		pToolbar->SetDepth(256.0f);
+
+		GuiLabel* pMainLabel = new GuiLabel();
+		pMainLabel->Initialize(pServiceProvider);
+		pMainLabel->SetFont("Courier New", 16);
+		pMainLabel->SetText("Main:");
+		pMainLabel->SetColor(D3DCOLOR_XRGB(0, 0, 0));
+		pMainLabel->SetPosition(26.0f, 149.0f);
+		pMainLabel->SetDepth(256.0f);
+
+		pCode[0] = new ActionPanel(4, 3);
+		pCode[0]->Initialize(pServiceProvider);
+		pCode[0]->SetTexture("Data\\Textures\\PanelB.png");
+		pCode[0]->SetPosition(16.0f, 160.0f);
+		pCode[0]->Subscribe(ActionPanel::EventAction, &GameScreen::OnAction, this);
+		pCode[0]->SetDepth(256.0f);
+
+		GuiLabel* pFunctionALabel = new GuiLabel();
+		pFunctionALabel->Initialize(pServiceProvider);
+		pFunctionALabel->SetFont("Courier New", 16);
+		pFunctionALabel->SetText("Function 1:");
+		pFunctionALabel->SetColor(D3DCOLOR_XRGB(0, 0, 0));
+		pFunctionALabel->SetPosition(26.0f, 349.0f);
+
+		pCode[1] = new ActionPanel(4, 2);
+		pCode[1]->Initialize(pServiceProvider);
+		pCode[1]->SetTexture("Data\\Textures\\PanelA.png");
+		pCode[1]->SetPosition(16.0f, 360.0f);
+		pCode[1]->Subscribe(ActionPanel::EventAction, &GameScreen::OnAction, this);
+
+		GuiLabel* pFunctionBLabel = new GuiLabel();
+		pFunctionBLabel->Initialize(pServiceProvider);
+		pFunctionBLabel->SetFont("Courier New", 16);
+		pFunctionBLabel->SetText("Function 2:");
+		pFunctionBLabel->SetColor(D3DCOLOR_XRGB(0, 0, 0));
+		pFunctionBLabel->SetPosition(26.0f, 493.0f);
+
+		pCode[2] = new ActionPanel(4, 2);
+		pCode[2]->Initialize(pServiceProvider);
+		pCode[2]->SetTexture("Data\\Textures\\PanelA.png");
+		pCode[2]->SetPosition(16.0f, 504.0f);
+		pCode[2]->Subscribe(ActionPanel::EventAction, &GameScreen::OnAction, this);
+
+		const float fButtonPadding	= 32.0f;
+		const float fButtonSpacing	= 8.0f;
+		const float fButtonSize		= 48.0f;
+
+		pButtonPlay = new GuiButton();
+		pButtonPlay->Initialize(pServiceProvider);
+		pButtonPlay->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button2N.png", true);
+		pButtonPlay->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Button2H.png", true);
+		pButtonPlay->SetTexture(GuiButtonState_Down, "Data\\Textures\\Button2D.png", true);
+		pButtonPlay->SetFont("Courier New", 16, FW_BOLD);
+		pButtonPlay->SetText("Play");
+		pButtonPlay->SetColor(D3DCOLOR_XRGB(0, 0, 0));
+		pButtonPlay->SetPosition(fButtonPadding + 0.0f * (fButtonSize + fButtonSpacing), 652.0f);
+		pButtonPlay->Subscribe(GuiButton::EventClick, &GameScreen::OnPlay, this);
+
+		pButtonStop = new GuiButton();
+		pButtonStop->Initialize(pServiceProvider);
+		pButtonStop->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button2N.png", true);
+		pButtonStop->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Button2H.png", true);
+		pButtonStop->SetTexture(GuiButtonState_Down, "Data\\Textures\\Button2D.png", true);
+		pButtonStop->SetFont("Courier New", 16, FW_BOLD);
+		pButtonStop->SetText("Stop");
+		pButtonStop->SetColor(D3DCOLOR_XRGB(0, 0, 0));
+		pButtonStop->SetPosition(fButtonPadding + 1.0f * (fButtonSize + fButtonSpacing), 652.0f);
+		pButtonStop->Subscribe(GuiButton::EventClick, &GameScreen::OnStop, this);
+
+		pButtonReset = new GuiButton();
+		pButtonReset->Initialize(pServiceProvider);
+		pButtonReset->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button2N.png", true);
+		pButtonReset->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Button2H.png", true);
+		pButtonReset->SetTexture(GuiButtonState_Down, "Data\\Textures\\Button2D.png", true);
+		pButtonReset->SetFont("Courier New", 16, FW_BOLD);
+		pButtonReset->SetText("Reset");
+		pButtonReset->SetColor(D3DCOLOR_XRGB(0, 0, 0));
+		pButtonReset->SetPosition(fButtonPadding + 2.0f * (fButtonSize + fButtonSpacing), 652.0f);
+		pButtonReset->Subscribe(GuiButton::EventClick, &GameScreen::OnReset, this);
+
+		pButtonExit = new GuiButton();
+		pButtonExit->Initialize(pServiceProvider);
+		pButtonExit->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button2N.png", true);
+		pButtonExit->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Button2H.png", true);
+		pButtonExit->SetTexture(GuiButtonState_Down, "Data\\Textures\\Button2D.png", true);
+		pButtonExit->SetFont("Courier New", 16, FW_BOLD);
+		pButtonExit->SetText("Exit");
+		pButtonExit->SetColor(D3DCOLOR_XRGB(0, 0, 0));
+		pButtonExit->SetPosition(fButtonPadding + 3.0f * (fButtonSize + fButtonSpacing), 652.0f);
+		pButtonExit->Subscribe(GuiButton::EventClick, &GameScreen::OnExit, this);
+
+		pBackground->Add(pToolbar);
+		pBackground->Add(pMainLabel);
+		pBackground->Add(pCode[0]);
+		pBackground->Add(pFunctionALabel);
+		pBackground->Add(pCode[1]);
+		pBackground->Add(pFunctionBLabel);
+		pBackground->Add(pCode[2]);
+		pBackground->Add(pButtonPlay);
+		pBackground->Add(pButtonStop);
+		pBackground->Add(pButtonReset);
+		pBackground->Add(pButtonExit);
+
+		pMessageDialog = new MessageDialog();
+		pMessageDialog->Initialize(pServiceProvider);
+		pMessageDialog->Subscribe(GuiDialog::EventResult, &GameScreen::OnResult, this);
+
+		const D3DXVECTOR2& kMessageSize = pMessageDialog->GetDimensions();
+		pMessageDialog->SetPosition(0.5f * ((ScreenSizeX - pBackground->GetWidth()) - kMessageSize.x), 0.5f * (ScreenSizeY - kMessageSize.y));
+
+		pConfirmDialog = new ChoiceDialog();
+		pConfirmDialog->Initialize(pServiceProvider);
+		pConfirmDialog->Subscribe(GuiDialog::EventResult, &GameScreen::OnConfirm, this);
+
+		const D3DXVECTOR2& kConfigSize = pConfirmDialog->GetDimensions();
+		pConfirmDialog->SetPosition(0.5f * ((ScreenSizeX - pBackground->GetWidth()) - kConfigSize.x), 0.5f * (ScreenSizeY - kConfigSize.y));
+
+		pDebugText = new GuiLabel();
+		pDebugText->Initialize(pServiceProvider);
+		pDebugText->SetFont("Courier New", 16);
+		pDebugText->SetPosition(10.0f, 10.0f);
+		pDebugText->SetText("Debug");
+		pDebugText->SetColor(D3DCOLOR_XRGB(255, 255, 255));
+
+		kInterface.Add(pBackground);
+		kInterface.Add(pDebugText);
+		kInterface.Add(pMessageDialog);
+		kInterface.Add(pConfirmDialog);
+	}
+
+	return eCode;
 }
+
+/*
+ * UpdateInput
+ */
+void GameScreen::UpdateInput(float fElapsed)
+{
+	#if defined(_DEBUG)
+	if(pInputManager->IsKeyDown(DIK_LEFT))
+	{
+		kCameraController.Yaw(0.01f);
+	}
+	else
+
+	if(pInputManager->IsKeyDown(DIK_RIGHT))
+	{
+		kCameraController.Yaw(-0.01f);
+	}
+
+	if(pInputManager->IsKeyDown(DIK_UP))
+	{
+		kCameraController.Pitch(0.01f);
+	}
+	else
+
+	if(pInputManager->IsKeyDown(DIK_DOWN))
+	{
+		kCameraController.Pitch(-0.01f);
+	}
+
+	if(pInputManager->IsKeyDown(DIK_NEXT))
+	{
+		kCameraController.Move(0.1f);
+	}
+	else
+
+	if(pInputManager->IsKeyDown(DIK_PRIOR))
+	{
+		kCameraController.Move(-0.1f);
+	}
+
+	static bool bControl = false;
+	static uint32 nBuffer[4] = {0};
+	static uint32 nCount = 0;
+
+	if(bControl)
+	{
+		if(pInputManager->IsKeyDown(DIK_0) && !pInputManager->WasKeyDown(DIK_0))
+		{
+			nBuffer[nCount++] = 0;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_1) && !pInputManager->WasKeyDown(DIK_1))
+		{
+			nBuffer[nCount++] = 1;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_2) && !pInputManager->WasKeyDown(DIK_2))
+		{
+			nBuffer[nCount++] = 2;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_3) && !pInputManager->WasKeyDown(DIK_3))
+		{
+			nBuffer[nCount++] = 3;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_4) && !pInputManager->WasKeyDown(DIK_4))
+		{
+			nBuffer[nCount++] = 4;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_5) && !pInputManager->WasKeyDown(DIK_5))
+		{
+			nBuffer[nCount++] = 5;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_6) && !pInputManager->WasKeyDown(DIK_6))
+		{
+			nBuffer[nCount++] = 6;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_7) && !pInputManager->WasKeyDown(DIK_7))
+		{
+			nBuffer[nCount++] = 7;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_8) && !pInputManager->WasKeyDown(DIK_8))
+		{
+			nBuffer[nCount++] = 8;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_9) && !pInputManager->WasKeyDown(DIK_9))
+		{
+			nBuffer[nCount++] = 9;
+		}
+
+		if(!pInputManager->IsKeyDown(DIK_LCONTROL))
+		{
+			if(nCount > 0)
+			{
+				nCurrentLevel	= 0;
+				nLogicState		= LogicState_LevelLoad;
+
+				for(uint32 i = 0; i < nCount; ++i)
+				{
+					nCurrentLevel += (uint32)(nBuffer[i] * powf(10.0f, (float)i));
+				}
+			}
+
+			bControl = false;
+		}
+	}
+	else
+	{
+		if(pInputManager->IsKeyDown(DIK_LCONTROL))
+		{
+			bControl = true;
+			nCount = 0;
+		}
+	}
+	#endif
+}
+
+/*
+ * UpdateLogic
+ */
+void GameScreen::UpdateLogic(float fElapsed)
+{
+	if(nLogicState == LogicState_LevelLoad)
+	{
+		char kBuffer[256];
+		sprintf(kBuffer, "Data\\Maps\\Map%02d.map", nCurrentLevel++);
+
+		ErrorCode eCode = Load(kBuffer);
+		if(eCode == Error_Success)
+		{
+			kProgram.Clear();
+
+			for(uint32 i = 0; i < MaximumFunctionCount; ++i)
+			{
+				pCode[i]->Clear();
+			}
+
+			nLogicState = LogicState_GameActive;
+		}
+		else
+		{
+			pMessageDialog->SetButton(0, "Ok", 0);
+			pMessageDialog->SetMessage("Congratulations!\nYou have completed the game");
+			pMessageDialog->Show();
+
+			nLogicState = LogicState_GameOver;
+		}
+
+		nSimulationState = SimulationState_Idle;
+	}
+	else
+
+	if(nLogicState == LogicState_GameActive)
+	{
+		if(nSimulationState == SimulationState_Active)
+		{
+			if(kBot.Update(fElapsed))
+			{
+				if(kEnvironment.RequirementsMet())
+				{
+					pMessageDialog->SetButton(0, "Ok", 0);
+					pMessageDialog->SetMessage("Congratulations!\nYou have completed level %d", nCurrentLevel);
+					pMessageDialog->Show();
+
+					nLogicState = LogicState_LevelComplete;
+				}
+			}
+		}
+	}
+}
+
+/*
+ * OnAction
+ */
+void GameScreen::OnAction(GuiEventArguments& kArguments)
+{
+	ActionArguments& kActionArguments = (ActionArguments&)kArguments;
+
+	for(uint32 i = 0; i < MaximumFunctionCount; ++i)
+	{
+		if(kArguments.pSource == pCode[i])
+		{
+			kProgram.SetAction(i, kActionArguments.nSlot, pCode[i]->GetAction(kActionArguments.nSlot));
+		}
+	}
+}
+
+/*
+ * OnPlay
+ */
+void GameScreen::OnPlay(GuiEventArguments& kArguments)
+{
+	if(nSimulationState == SimulationState_Idle)
+	{
+		kEnvironment.Reset();
+
+		kBot.Reset();
+		kBot.SetPosition(kLoader.GetInitialPosition());
+		kBot.SetDirection(kLoader.GetInitialDirection());
+		kBot.Upload(kProgram);
+
+		nSimulationState = SimulationState_Active;
+	}
+}
+
+/*
+ * OnStop
+ */
+void GameScreen::OnStop(GuiEventArguments& kArguments)
+{
+	if(nSimulationState == SimulationState_Active)
+	{
+		kEnvironment.Reset();
+
+		kBot.Reset();
+		kBot.SetPosition(kLoader.GetInitialPosition());
+		kBot.SetDirection(kLoader.GetInitialDirection());
+
+		nSimulationState = SimulationState_Idle;
+	}
+}
+
+/*
+ * OnReset
+ */
+void GameScreen::OnReset(GuiEventArguments& kArguments)
+{
+	kProgram.Clear();
+
+	for(uint32 i = 0; i < MaximumFunctionCount; ++i)
+	{
+		pCode[i]->Clear();
+	}
+}
+
+/*
+ * OnExit
+ */
+void GameScreen::OnExit(GuiEventArguments& kArguments)
+{
+	pConfirmDialog->SetMessage("Are you sure you want to exit?");
+	pConfirmDialog->SetButton(0, "Yes", DialogResult_Yes);
+	pConfirmDialog->SetButton(1, "No", DialogResult_No);
+	pConfirmDialog->Show();
+
+	//nWorldState = WorldState_Confirm;
+}
+
+/*
+ * OnResult
+ */
+void GameScreen::OnResult(GuiEventArguments& kArguments)
+{
+	if(nLogicState == LogicState_LevelComplete)
+	{
+		nLogicState = LogicState_LevelLoad;
+	}
+	else
+
+	if(nLogicState == LogicState_GameOver)
+	{
+		nCurrentLevel	= 0;
+		nLogicState		= LogicState_LevelLoad;
+
+		//TODO: Return to main menu
+		//nWorldState = WorldState_Main;
+	}
+}
+
+/*
+ * OnConfirm
+ */
+void GameScreen::OnConfirm(GuiEventArguments& kArguments)
+{
+	GuiResultArguments& kResultArguments = (GuiResultArguments&)kArguments;
+
+	if(kResultArguments.nResult == DialogResult_Yes)
+	{
+	}
+	else
+
+	if(kResultArguments.nResult == DialogResult_No)
+	{
+		//nWorldState = WorldState_Game;
+	}
+}
--- a/LightClone/Source/GameScreen.h	Tue Oct 11 12:09:04 2011 -0700
+++ b/LightClone/Source/GameScreen.h	Tue Oct 11 13:20:43 2011 -0700
@@ -7,7 +7,25 @@
 
 #include "Core.h"
 #include "Screen.h"
-#include "World.h"
+#include "CameraController.h"
+#include "GuiInterface.h"
+#include "GuiImage.h"
+#include "GuiButton.h"
+#include "ActionPanel.h"
+#include "Dialog.h"
+#include "Loader.h"
+#include "Environment.h"
+#include "Bot.h"
+
+/*
+ * MessageDialog
+ */
+typedef Dialog<1> MessageDialog;
+
+/*
+ * ChoiceDialog
+ */
+typedef Dialog<2> ChoiceDialog;
 
 /*
  * GameScreen
@@ -15,9 +33,104 @@
 class GameScreen : public Screen
 {
 	/*
-	 * kWorld
+	 * pInputManager
+	 */
+	InputManager* pInputManager;
+
+	/*
+	 * kCameraController
+	 */
+	CameraController kCameraController;
+
+	/*
+	 * kLoader
+	 */
+	Loader kLoader;
+
+	/*
+	 * kEnvironment
+	 */
+	Environment kEnvironment;
+
+	/*
+	 * kBot
+	 */
+	Bot kBot;
+
+	/*
+	 * kProgram
+	 */
+	Program kProgram;
+
+	/*
+	 * nLogicState
+	 */
+	uint32 nLogicState;
+
+	/*
+	 * nSimulationState
+	 */
+	uint32 nSimulationState;
+
+	/*
+	 * nCurrentLevel
+	 */
+	uint32 nCurrentLevel;
+
+	/*
+	 * kInterface
 	 */
-	World kWorld;
+	GuiInterface kInterface;
+
+	/*
+	 * pBackground
+	 */
+	GuiImage* pBackground;
+
+	/*
+	 * pButtonPlay
+	 */
+	GuiButton* pButtonPlay;
+
+	/*
+	 * pButtonStop
+	 */
+	GuiButton* pButtonStop;
+
+	/*
+	 * pButtonReset
+	 */
+	GuiButton* pButtonReset;
+
+	/*
+	 * pButtonExit
+	 */
+	GuiButton* pButtonExit;
+
+	/*
+	 * pToolbar
+	 */
+	ActionPanel* pToolbar;
+
+	/*
+	 * pCode
+	 */
+	ActionPanel* pCode[MaximumFunctionCount];
+
+	/*
+	 * pMessageDialog
+	 */
+	MessageDialog* pMessageDialog;
+
+	/*
+	 * pConfirmDialog
+	 */
+	ChoiceDialog* pConfirmDialog;
+
+	/*
+	 * pDebugText
+	 */
+	GuiLabel* pDebugText;
 
 public:
 
@@ -40,6 +153,63 @@
 	 * Render
 	 */
 	virtual void Render(RenderContext& kContext);
+
+	/*
+	 * Load
+	 */
+	ErrorCode Load(const char* pName);
+
+private:
+
+	/*
+	 * InitializeInterface
+	 */
+	ErrorCode InitializeInterface(ServiceProvider* pServiceProvider);
+
+	/*
+	 * UpdateInput
+	 */
+	void UpdateInput(float fElapsed);
+
+	/*
+	 * UpdateLogic
+	 */
+	void UpdateLogic(float fElapsed);
+
+	/*
+	 * OnAction
+	 */
+	void OnAction(GuiEventArguments& kArguments);
+
+	/*
+	 * OnPlay
+	 */
+	void OnPlay(GuiEventArguments& kArguments);
+
+	/*
+	 * OnStop
+	 */
+	void OnStop(GuiEventArguments& kArguments);
+
+	/*
+	 * OnReset
+	 */
+	void OnReset(GuiEventArguments& kArguments);
+
+	/*
+	 * OnExit
+	 */
+	void OnExit(GuiEventArguments& kArguments);
+
+	/*
+	 * OnResult
+	 */
+	void OnResult(GuiEventArguments& kArguments);
+
+	/*
+	 * OnConfirm
+	 */
+	void OnConfirm(GuiEventArguments& kArguments);
 };
 
 #endif //__GAMESCREEN_H__
--- a/LightClone/Source/HashMap.h	Tue Oct 11 12:09:04 2011 -0700
+++ b/LightClone/Source/HashMap.h	Tue Oct 11 13:20:43 2011 -0700
@@ -57,7 +57,7 @@
 		/*
 		 * Node
 		 */
-		Node(Key& kNodeKey) : kKey(kNodeKey), pNext(NULL)
+		Node(const Key& kNodeKey) : kKey(kNodeKey), pNext(NULL)
 		{
 			uint8* pData = (uint8*)&kValue;
 			for(uint32 i = 0; i < sizeof(kValue); ++i)
@@ -118,7 +118,7 @@
 	/*
 	 * Add
 	 */
-	Value* Add(Key& kKey)
+	Value* Add(const Key& kKey)
 	{
 		const uint32 nSlot = GetSlot(kKey);
 
--- a/LightClone/Source/Mediator.cpp	Tue Oct 11 12:09:04 2011 -0700
+++ b/LightClone/Source/Mediator.cpp	Tue Oct 11 13:20:43 2011 -0700
@@ -37,8 +37,7 @@
 
 		kClock.Reset();
 
-		//TODO: While screen manager is active
-		while(true)
+		while(kScreenManager.IsActive())
 		{
 			ProcessMessages();
 
@@ -161,6 +160,8 @@
 		return eCode;
 	}
 
+	kScreenManager.Push("Game");
+
 	return eCode;
 }
 
@@ -184,6 +185,7 @@
  */
 void Mediator::Update(float fElapsed)
 {
+	kScreenManager.Update(fElapsed);
 }
 
 /*
@@ -209,8 +211,7 @@
 	{
 		if(kMessage.message == WM_QUIT)
 		{
-			//kWorld.Deactivate();
-			//TODO: kScreenManager.Deactivate();
+			kScreenManager.Set(NULL);
 			break;
 		}
 
--- a/LightClone/Source/Screen.cpp	Tue Oct 11 12:09:04 2011 -0700
+++ b/LightClone/Source/Screen.cpp	Tue Oct 11 13:20:43 2011 -0700
@@ -41,17 +41,30 @@
 }
 
 /*
- * SetScreenManager
+ * OnEnter
  */
-void Screen::SetScreenManager(ScreenManager* pManager)
+void Screen::OnEnter()
 {
-	pScreenManager = pManager;
+}
+
+/*
+ * OnExit
+ */
+void Screen::OnExit()
+{
 }
 
 /*
- * GetScreenManager
+ * OnPause
  */
-ScreenManager* Screen::GetScreenManager()
+void Screen::OnPause()
 {
-	return pScreenManager;
 }
+
+/*
+ * OnResume
+ */
+void Screen::OnResume()
+{
+}
+
--- a/LightClone/Source/Screen.h	Tue Oct 11 12:09:04 2011 -0700
+++ b/LightClone/Source/Screen.h	Tue Oct 11 13:20:43 2011 -0700
@@ -10,16 +10,18 @@
 #include "RenderContext.h"
 
 /*
- * ScreenManager
- */
-class ScreenManager;
-
-/*
  * Screen
  */
 class Screen
 {
 	/*
+	 * ScreenManager
+	 */
+	friend class ScreenManager;
+
+protected:
+
+	/*
 	 * pScreenManager
 	 */
 	ScreenManager* pScreenManager;
@@ -51,15 +53,31 @@
 	 */
 	virtual void Render(RenderContext& kContext);
 
+protected:
+
 	/*
-	 * SetScreenManager
+	 * OnEnter
+	 *	Called when this screen is pushed onto the display stack
 	 */
-	void SetScreenManager(ScreenManager* pManager);
+	virtual void OnEnter();
 
 	/*
-	 * GetScreenManager
+	 * OnExit
+	 *	Called when this screen is popped from the display stack
 	 */
-	ScreenManager* GetScreenManager();
+	virtual void OnExit();
+
+	/*
+	 * OnPause
+	 *	Called when another screen is pushed on top of this screen
+	 */
+	virtual void OnPause();
+
+	/*
+	 * OnResume
+	 *	Called when this screen returns to the top of the stack
+	 */
+	virtual void OnResume();
 };
 
 #endif //__SCREEN_H__
--- a/LightClone/Source/ScreenManager.cpp	Tue Oct 11 12:09:04 2011 -0700
+++ b/LightClone/Source/ScreenManager.cpp	Tue Oct 11 13:20:43 2011 -0700
@@ -7,7 +7,7 @@
 /*
  * ScreenManager
  */
-ScreenManager::ScreenManager()
+ScreenManager::ScreenManager() : bDirty(false)
 {
 }
 
@@ -20,19 +20,20 @@
 
 	if(pInstance)
 	{
-		FixedString<> kName(pName);
-
-		Screen** pScreen = kScreens.Find(kName);
+		Screen** pScreen = kScreens.Find(pName);
+		
 		if(!pScreen)
-			pScreen = kScreens.Add(kName);
+		{
+			pScreen = kScreens.Add(pName);
+		}
 
 		if(pScreen)
 		{
 			(*pScreen) = pInstance;
-			(*pScreen)->SetScreenManager(this);
+			(*pScreen)->pScreenManager = this;
+
+			eCode = Error_Success;
 		}
-
-		eCode = Error_Success;
 	}
 
 	return eCode;
@@ -43,7 +44,17 @@
  */
 ErrorCode ScreenManager::Initialize(ServiceProvider* pServiceProvider)
 {
-	return Error_Success;
+	ErrorCode eCode = Error_Success;
+
+	ScreenMap::Iterator kScreen		= kScreens.Begin();
+	ScreenMap::Iterator kScreenEnd	= kScreens.End();
+
+	for(; kScreen != kScreenEnd && eCode == Error_Success; ++kScreen)
+	{
+		eCode = (*kScreen)->Initialize(pServiceProvider);
+	}
+
+	return eCode;
 }
 
 /*
@@ -51,6 +62,13 @@
  */
 void ScreenManager::Terminate()
 {
+	ScreenMap::Iterator kScreen		= kScreens.Begin();
+	ScreenMap::Iterator kScreenEnd	= kScreens.End();
+
+	for(; kScreen != kScreenEnd; ++kScreen)
+	{
+		(*kScreen)->Terminate();
+	}
 }
 
 /*
@@ -58,6 +76,12 @@
  */
 void ScreenManager::Update(float fElapsed)
 {
+	bDirty = false;
+
+	for(int32 i = kStack.Size() - 1; i >= 0 && !bDirty; --i)
+	{
+		kStack[i]->Update(fElapsed);
+	}
 }
 
 /*
@@ -65,4 +89,105 @@
  */
 void ScreenManager::Render(RenderContext& kContext)
 {
+	const int32 nSize = kStack.Size();
+
+	for(int32 i = 0; i < nSize; ++i)
+	{
+		kStack[i]->Render(kContext);
+	}
 }
+
+/*
+ * Set
+ */
+void ScreenManager::Set(const char* pName)
+{
+	while(kStack.Size() > 1)
+	{
+		Screen* pScreen = kStack.Pop();
+		ASSERT(pScreen != NULL);
+
+		pScreen->OnExit();
+
+		Screen* pTop = kStack.Peek();
+		ASSERT(pTop != NULL);
+
+		pTop->OnResume();
+	}
+
+	if(kStack.Size() > 0)
+	{
+		ASSERT(kStack.Size() == 1);
+
+		Screen* pScreen = kStack.Pop();
+		ASSERT(pScreen != NULL);
+
+		pScreen->OnExit();
+	}
+
+	Screen** pInstance = kScreens.Find(pName);
+	if(pInstance)
+	{
+		ASSERT(*pInstance != NULL);
+		(*pInstance)->OnEnter();
+
+		kStack.Push(*pInstance);
+	}
+
+	bDirty = true;
+}
+
+/*
+ * Push
+ */
+void ScreenManager::Push(const char* pName)
+{
+	Screen** pInstance = kScreens.Find(pName);
+	ASSERT(pInstance != NULL);
+
+	if(kStack.Size() > 0)
+	{
+		Screen* pTop = kStack.Peek();
+		ASSERT(pTop != NULL);
+
+		pTop->OnPause();
+	}
+
+	ASSERT(*pInstance != NULL);
+	(*pInstance)->OnEnter();
+
+	kStack.Push(*pInstance);
+
+	bDirty = true;
+}
+
+/*
+ * Pop
+ */
+void ScreenManager::Pop()
+{
+	ASSERT(kStack.Size() > 0);
+
+	Screen* pScreen = kStack.Pop();
+	ASSERT(pScreen != NULL);
+
+	pScreen->OnExit();
+
+	if(kStack.Size() > 0)
+	{
+		Screen* pTop = kStack.Peek();
+		ASSERT(pTop != NULL);
+
+		pTop->OnResume();
+	}
+
+	bDirty = true;
+}
+
+/*
+ * IsActive
+ */
+bool ScreenManager::IsActive() const
+{
+	return kStack.Size() > 0;
+}
\ No newline at end of file
--- a/LightClone/Source/ScreenManager.h	Tue Oct 11 12:09:04 2011 -0700
+++ b/LightClone/Source/ScreenManager.h	Tue Oct 11 13:20:43 2011 -0700
@@ -37,6 +37,11 @@
 	 */
 	ScreenStack kStack;
 
+	/*
+	 * bDirty
+	 */
+	bool bDirty;
+
 public:
 
 	/*
@@ -68,6 +73,26 @@
 	 * Render
 	 */
 	void Render(RenderContext& kContext);
+
+	/*
+	 * Set
+	 */
+	void Set(const char* pName);
+
+	/*
+	 * Push
+	 */
+	void Push(const char* pName);
+
+	/*
+	 * Pop
+	 */
+	void Pop();
+
+	/*
+	 * IsActive
+	 */
+	bool IsActive() const;
 };
 
 #endif //__SCREENMANAGER_H__
--- a/LightClone/Source/World.cpp	Tue Oct 11 12:09:04 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,683 +0,0 @@
-/*
- * World
- */
-
-#include "World.h"
-#include "VertexTypes.h"
-#include "GuiLabel.h"
-#include "GuiImage.h"
-#include "GuiButton.h"
-
-/*
- * World
- */
-World::World()
-{
-	nWorldState			= WorldState_Game;
-	nLogicState			= LogicState_LevelLoad;
-	nSimulationState	= SimulationState_Idle;
-	nCurrentLevel		= 0;
-}
-
-/*
- * Initialize
- */
-ErrorCode World::Initialize(ServiceProvider* pServiceProvider)
-{
-	ErrorCode eCode = kEnvironment.Initialize(pServiceProvider);
-	if(eCode != Error_Success)
-	{
-		TRACE("Error: Failed to initialize environment\n");
-
-		Terminate();
-		return eCode;
-	}
-
-	eCode = kBot.Initialize(pServiceProvider);
-	if(eCode != Error_Success)
-	{
-		TRACE("Error: Failed to initialize bot\n");
-
-		Terminate();
-		return eCode;
-	}
-
-	eCode = kProgram.Initialize();
-	if(eCode != Error_Success)
-	{
-		TRACE("Error: Failed to initialize program\n");
-
-		Terminate();
-		return eCode;
-	}
-
-	eCode = InitializeInterface(pServiceProvider);				
-	if(eCode != Error_Success)
-	{
-		TRACE("Error: Failed to initialize interface\n");
-
-		Terminate();
-		return eCode;
-	}
-
-	eCode = pServiceProvider->GetService("InputManager", &pInputManager);
-	if(eCode != Error_Success)
-	{
-		TRACE("Error: Failed to acquire input manager\n");
-
-		Terminate();
-		return eCode;
-	}
-
-	nWorldState			= WorldState_Game;
-	nLogicState			= LogicState_LevelLoad;
-	nSimulationState	= SimulationState_Idle;
-	nCurrentLevel		= 0;
-
-	return eCode;
-}
-
-/*
- * Terminate
- */
-void World::Terminate()
-{
-	kInterface.Terminate();
-	kProgram.Terminate();
-	kBot.Terminate();
-	kEnvironment.Terminate();
-}
-
-/*
- * Activate
- */
-void World::Activate()
-{
-	nWorldState	= WorldState_Game;
-	nLogicState	= LogicState_LevelLoad;
-}
-
-/*
- * Deactivate
- */
-void World::Deactivate()
-{
-	nWorldState = WorldState_Exit;
-}
-
-/*
- * IsActive
- */
-bool World::IsActive()
-{
-	return nWorldState != WorldState_Exit;
-}
-
-/*
- * Load
- */
-ErrorCode World::Load(const char* pName)
-{
-	ErrorCode eCode = kLoader.Load(pName);
-	if(eCode == Error_Success)
-	{
-		const Size& kSize = kLoader.GetSize();
-
-		eCode = kEnvironment.Setup(kSize.X, kSize.Y);
-		if(eCode == Error_Success)
-		{
-			for(uint32 nY = 0; nY < kSize.Y; ++nY)
-			{
-				for(uint32 nX = 0; nX < kSize.X; ++nX)
-				{
-					kEnvironment.SetType(nX, nY, kLoader.GetTowerType(nX, nY));
-					kEnvironment.SetAltitude(nX, nY, kLoader.GetTowerHeight(nX, nY));
-				}
-			}
-
-			kBot.Setup(&kEnvironment);
-			kBot.SetPosition(kLoader.GetInitialPosition());
-			kBot.SetDirection(kLoader.GetInitialDirection());
-
-			//kCameraController.SetDistance(
-		}
-	}
-
-	return eCode;
-}
-
-/*
- * Update
- */
-void World::Update(float fElapsed)
-{
-	pInputManager->Update(fElapsed);
-
-	if(nWorldState == WorldState_Main)
-	{
-	}
-	else
-
-	if(nWorldState == WorldState_Game)
-	{
-		UpdateInput(fElapsed);
-		UpdateLogic(fElapsed);
-	}
-	else
-
-	if(nWorldState == WorldState_Pause)
-	{
-	}
-	else
-
-	if(nWorldState == WorldState_Help)
-	{
-	}
-
-	const D3DXVECTOR3& kCameraPosition = kCameraController.GetLocation();
-
-
-	char kBuffer[256];
-	sprintf_s(kBuffer, "Camera: <%.2f, %.2f, %.2f> (%.2f, %.2f, %.2f)", kCameraPosition.x, kCameraPosition.y, kCameraPosition.z, kCameraController.fCameraDistance, kCameraController.fCameraYaw, kCameraController.fCameraPitch);
-	pDebugText->SetText(kBuffer);
-
-	kInterface.Update(fElapsed);
-}
-
-/*
- * Render
- */
-void World::Render(RenderContext& kContext)
-{
-	if(nWorldState == WorldState_Game || nWorldState == WorldState_Confirm)
-	{
-		D3DVIEWPORT9 kOriginal;
-		kContext.GetViewport(&kOriginal);
-
-		D3DVIEWPORT9 kViewport;
-		kViewport.X			= 0;
-		kViewport.Y			= 0;
-		kViewport.Width		= ScreenSizeX - 280;	// minus size of interface
-		kViewport.Height	= ScreenSizeY;
-		kViewport.MinZ		= kOriginal.MinZ;
-		kViewport.MaxZ		= kOriginal.MaxZ;
-
-		kContext.SetViewport(kViewport);
-
-		kCameraController.SetMode(CameraMode_3D);
-		kEnvironment.Render(kContext, kCameraController);
-		kBot.Render(kContext, kCameraController);
-
-		kContext.SetViewport(kOriginal);
-	}
-
-	kCameraController.SetMode(CameraMode_2D);
-	kInterface.Render(kContext, kCameraController);
-}
-
-/*
- * InitializeInterface
- */
-ErrorCode World::InitializeInterface(ServiceProvider* pServiceProvider)
-{
-	ErrorCode eCode = kInterface.Initialize(pServiceProvider);
-	if(eCode == Error_Success)
-	{
-		pBackground = new GuiImage();
-		pBackground->Initialize(pServiceProvider);
-		pBackground->SetTexture("Data\\Textures\\Background04.tga", true);
-		pBackground->SetPosition(ScreenSizeX - pBackground->GetWidth(), 0.0f);
-		pBackground->SetDepth(512.0f);
-
-		pToolbar = new ActionPanel(4, 2);
-		pToolbar->Initialize(pServiceProvider);
-		pToolbar->SetTexture("Data\\Textures\\PanelA.png");
-		pToolbar->SetPosition(16, 16.0f);
-		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);
-		pToolbar->SetDepth(256.0f);
-
-		GuiLabel* pMainLabel = new GuiLabel();
-		pMainLabel->Initialize(pServiceProvider);
-		pMainLabel->SetFont("Courier New", 16);
-		pMainLabel->SetText("Main:");
-		pMainLabel->SetColor(D3DCOLOR_XRGB(0, 0, 0));
-		pMainLabel->SetPosition(26.0f, 149.0f);
-		pMainLabel->SetDepth(256.0f);
-
-		pCode[0] = new ActionPanel(4, 3);
-		pCode[0]->Initialize(pServiceProvider);
-		pCode[0]->SetTexture("Data\\Textures\\PanelB.png");
-		pCode[0]->SetPosition(16.0f, 160.0f);
-		pCode[0]->Subscribe(ActionPanel::EventAction, &World::OnAction, this);
-		pCode[0]->SetDepth(256.0f);
-
-		GuiLabel* pFunctionALabel = new GuiLabel();
-		pFunctionALabel->Initialize(pServiceProvider);
-		pFunctionALabel->SetFont("Courier New", 16);
-		pFunctionALabel->SetText("Function 1:");
-		pFunctionALabel->SetColor(D3DCOLOR_XRGB(0, 0, 0));
-		pFunctionALabel->SetPosition(26.0f, 349.0f);
-
-		pCode[1] = new ActionPanel(4, 2);
-		pCode[1]->Initialize(pServiceProvider);
-		pCode[1]->SetTexture("Data\\Textures\\PanelA.png");
-		pCode[1]->SetPosition(16.0f, 360.0f);
-		pCode[1]->Subscribe(ActionPanel::EventAction, &World::OnAction, this);
-
-		GuiLabel* pFunctionBLabel = new GuiLabel();
-		pFunctionBLabel->Initialize(pServiceProvider);
-		pFunctionBLabel->SetFont("Courier New", 16);
-		pFunctionBLabel->SetText("Function 2:");
-		pFunctionBLabel->SetColor(D3DCOLOR_XRGB(0, 0, 0));
-		pFunctionBLabel->SetPosition(26.0f, 493.0f);
-
-		pCode[2] = new ActionPanel(4, 2);
-		pCode[2]->Initialize(pServiceProvider);
-		pCode[2]->SetTexture("Data\\Textures\\PanelA.png");
-		pCode[2]->SetPosition(16.0f, 504.0f);
-		pCode[2]->Subscribe(ActionPanel::EventAction, &World::OnAction, this);
-
-		const float fButtonPadding	= 32.0f;
-		const float fButtonSpacing	= 8.0f;
-		const float fButtonSize		= 48.0f;
-
-		pButtonPlay = new GuiButton();
-		pButtonPlay->Initialize(pServiceProvider);
-		pButtonPlay->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button2N.png", true);
-		pButtonPlay->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Button2H.png", true);
-		pButtonPlay->SetTexture(GuiButtonState_Down, "Data\\Textures\\Button2D.png", true);
-		pButtonPlay->SetFont("Courier New", 16, FW_BOLD);
-		pButtonPlay->SetText("Play");
-		pButtonPlay->SetColor(D3DCOLOR_XRGB(0, 0, 0));
-		pButtonPlay->SetPosition(fButtonPadding + 0.0f * (fButtonSize + fButtonSpacing), 652.0f);
-		pButtonPlay->Subscribe(GuiButton::EventClick, &World::OnPlay, this);
-
-		pButtonStop = new GuiButton();
-		pButtonStop->Initialize(pServiceProvider);
-		pButtonStop->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button2N.png", true);
-		pButtonStop->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Button2H.png", true);
-		pButtonStop->SetTexture(GuiButtonState_Down, "Data\\Textures\\Button2D.png", true);
-		pButtonStop->SetFont("Courier New", 16, FW_BOLD);
-		pButtonStop->SetText("Stop");
-		pButtonStop->SetColor(D3DCOLOR_XRGB(0, 0, 0));
-		pButtonStop->SetPosition(fButtonPadding + 1.0f * (fButtonSize + fButtonSpacing), 652.0f);
-		pButtonStop->Subscribe(GuiButton::EventClick, &World::OnStop, this);
-
-		pButtonReset = new GuiButton();
-		pButtonReset->Initialize(pServiceProvider);
-		pButtonReset->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button2N.png", true);
-		pButtonReset->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Button2H.png", true);
-		pButtonReset->SetTexture(GuiButtonState_Down, "Data\\Textures\\Button2D.png", true);
-		pButtonReset->SetFont("Courier New", 16, FW_BOLD);
-		pButtonReset->SetText("Reset");
-		pButtonReset->SetColor(D3DCOLOR_XRGB(0, 0, 0));
-		pButtonReset->SetPosition(fButtonPadding + 2.0f * (fButtonSize + fButtonSpacing), 652.0f);
-		pButtonReset->Subscribe(GuiButton::EventClick, &World::OnReset, this);
-
-		pButtonExit = new GuiButton();
-		pButtonExit->Initialize(pServiceProvider);
-		pButtonExit->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button2N.png", true);
-		pButtonExit->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Button2H.png", true);
-		pButtonExit->SetTexture(GuiButtonState_Down, "Data\\Textures\\Button2D.png", true);
-		pButtonExit->SetFont("Courier New", 16, FW_BOLD);
-		pButtonExit->SetText("Exit");
-		pButtonExit->SetColor(D3DCOLOR_XRGB(0, 0, 0));
-		pButtonExit->SetPosition(fButtonPadding + 3.0f * (fButtonSize + fButtonSpacing), 652.0f);
-		pButtonExit->Subscribe(GuiButton::EventClick, &World::OnExit, this);
-
-		pBackground->Add(pToolbar);
-		pBackground->Add(pMainLabel);
-		pBackground->Add(pCode[0]);
-		pBackground->Add(pFunctionALabel);
-		pBackground->Add(pCode[1]);
-		pBackground->Add(pFunctionBLabel);
-		pBackground->Add(pCode[2]);
-		pBackground->Add(pButtonPlay);
-		pBackground->Add(pButtonStop);
-		pBackground->Add(pButtonReset);
-		pBackground->Add(pButtonExit);
-
-		pMessageDialog = new MessageDialog();
-		pMessageDialog->Initialize(pServiceProvider);
-		pMessageDialog->Subscribe(GuiDialog::EventResult, &World::OnResult, this);
-
-		const D3DXVECTOR2& kMessageSize = pMessageDialog->GetDimensions();
-		pMessageDialog->SetPosition(0.5f * ((ScreenSizeX - pBackground->GetWidth()) - kMessageSize.x), 0.5f * (ScreenSizeY - kMessageSize.y));
-
-		pConfirmDialog = new ChoiceDialog();
-		pConfirmDialog->Initialize(pServiceProvider);
-		pConfirmDialog->Subscribe(GuiDialog::EventResult, &World::OnConfirm, this);
-
-		const D3DXVECTOR2& kConfigSize = pConfirmDialog->GetDimensions();
-		pConfirmDialog->SetPosition(0.5f * ((ScreenSizeX - pBackground->GetWidth()) - kConfigSize.x), 0.5f * (ScreenSizeY - kConfigSize.y));
-
-		pDebugText = new GuiLabel();
-		pDebugText->Initialize(pServiceProvider);
-		pDebugText->SetFont("Courier New", 16);
-		pDebugText->SetPosition(10.0f, 10.0f);
-		pDebugText->SetText("Debug");
-		pDebugText->SetColor(D3DCOLOR_XRGB(255, 255, 255));
-
-		kInterface.Add(pBackground);
-		kInterface.Add(pDebugText);
-		kInterface.Add(pMessageDialog);
-		kInterface.Add(pConfirmDialog);
-	}
-
-	return eCode;
-}
-
-/*
- * UpdateInput
- */
-void World::UpdateInput(float fElapsed)
-{
-	#if defined(_DEBUG)
-	if(pInputManager->IsKeyDown(DIK_LEFT))
-	{
-		kCameraController.Yaw(0.01f);
-	}
-	else
-
-	if(pInputManager->IsKeyDown(DIK_RIGHT))
-	{
-		kCameraController.Yaw(-0.01f);
-	}
-
-	if(pInputManager->IsKeyDown(DIK_UP))
-	{
-		kCameraController.Pitch(0.01f);
-	}
-	else
-
-	if(pInputManager->IsKeyDown(DIK_DOWN))
-	{
-		kCameraController.Pitch(-0.01f);
-	}
-
-	if(pInputManager->IsKeyDown(DIK_NEXT))
-	{
-		kCameraController.Move(0.1f);
-	}
-	else
-
-	if(pInputManager->IsKeyDown(DIK_PRIOR))
-	{
-		kCameraController.Move(-0.1f);
-	}
-
-	static bool bControl = false;
-	static uint32 nBuffer[4] = {0};
-	static uint32 nCount = 0;
-
-	if(bControl)
-	{
-		if(pInputManager->IsKeyDown(DIK_0) && !pInputManager->WasKeyDown(DIK_0))
-		{
-			nBuffer[nCount++] = 0;
-		}
-		else
-
-		if(pInputManager->IsKeyDown(DIK_1) && !pInputManager->WasKeyDown(DIK_1))
-		{
-			nBuffer[nCount++] = 1;
-		}
-		else
-
-		if(pInputManager->IsKeyDown(DIK_2) && !pInputManager->WasKeyDown(DIK_2))
-		{
-			nBuffer[nCount++] = 2;
-		}
-		else
-
-		if(pInputManager->IsKeyDown(DIK_3) && !pInputManager->WasKeyDown(DIK_3))
-		{
-			nBuffer[nCount++] = 3;
-		}
-		else
-
-		if(pInputManager->IsKeyDown(DIK_4) && !pInputManager->WasKeyDown(DIK_4))
-		{
-			nBuffer[nCount++] = 4;
-		}
-		else
-
-		if(pInputManager->IsKeyDown(DIK_5) && !pInputManager->WasKeyDown(DIK_5))
-		{
-			nBuffer[nCount++] = 5;
-		}
-		else
-
-		if(pInputManager->IsKeyDown(DIK_6) && !pInputManager->WasKeyDown(DIK_6))
-		{
-			nBuffer[nCount++] = 6;
-		}
-		else
-
-		if(pInputManager->IsKeyDown(DIK_7) && !pInputManager->WasKeyDown(DIK_7))
-		{
-			nBuffer[nCount++] = 7;
-		}
-		else
-
-		if(pInputManager->IsKeyDown(DIK_8) && !pInputManager->WasKeyDown(DIK_8))
-		{
-			nBuffer[nCount++] = 8;
-		}
-		else
-
-		if(pInputManager->IsKeyDown(DIK_9) && !pInputManager->WasKeyDown(DIK_9))
-		{
-			nBuffer[nCount++] = 9;
-		}
-
-		if(!pInputManager->IsKeyDown(DIK_LCONTROL))
-		{
-			if(nCount > 0)
-			{
-				nCurrentLevel	= 0;
-				nLogicState		= LogicState_LevelLoad;
-
-				for(uint32 i = 0; i < nCount; ++i)
-				{
-					nCurrentLevel += (uint32)(nBuffer[i] * powf(10.0f, (float)i));
-				}
-			}
-
-			bControl = false;
-		}
-	}
-	else
-	{
-		if(pInputManager->IsKeyDown(DIK_LCONTROL))
-		{
-			bControl = true;
-			nCount = 0;
-		}
-	}
-	#endif
-}
-
-/*
- * UpdateLogic
- */
-void World::UpdateLogic(float fElapsed)
-{
-	if(nLogicState == LogicState_LevelLoad)
-	{
-		char kBuffer[256];
-		sprintf(kBuffer, "Data\\Maps\\Map%02d.map", nCurrentLevel++);
-
-		ErrorCode eCode = Load(kBuffer);
-		if(eCode == Error_Success)
-		{
-			kProgram.Clear();
-
-			for(uint32 i = 0; i < MaximumFunctionCount; ++i)
-			{
-				pCode[i]->Clear();
-			}
-
-			nLogicState = LogicState_GameActive;
-		}
-		else
-		{
-			pMessageDialog->SetButton(0, "Ok", 0);
-			pMessageDialog->SetMessage("Congratulations!\nYou have completed the game");
-			pMessageDialog->Show();
-
-			nLogicState = LogicState_GameOver;
-		}
-
-		nSimulationState = SimulationState_Idle;
-	}
-	else
-
-	if(nLogicState == LogicState_GameActive)
-	{
-		if(nSimulationState == SimulationState_Active)
-		{
-			if(kBot.Update(fElapsed))
-			{
-				if(kEnvironment.RequirementsMet())
-				{
-					pMessageDialog->SetButton(0, "Ok", 0);
-					pMessageDialog->SetMessage("Congratulations!\nYou have completed level %d", nCurrentLevel);
-					pMessageDialog->Show();
-
-					nLogicState = LogicState_LevelComplete;
-				}
-			}
-		}
-	}
-}
-
-/*
- * OnAction
- */
-void World::OnAction(GuiEventArguments& kArguments)
-{
-	ActionArguments& kActionArguments = (ActionArguments&)kArguments;
-
-	for(uint32 i = 0; i < MaximumFunctionCount; ++i)
-	{
-		if(kArguments.pSource == pCode[i])
-		{
-			kProgram.SetAction(i, kActionArguments.nSlot, pCode[i]->GetAction(kActionArguments.nSlot));
-		}
-	}
-}
-
-/*
- * OnPlay
- */
-void World::OnPlay(GuiEventArguments& kArguments)
-{
-	if(nSimulationState == SimulationState_Idle)
-	{
-		kEnvironment.Reset();
-
-		kBot.Reset();
-		kBot.SetPosition(kLoader.GetInitialPosition());
-		kBot.SetDirection(kLoader.GetInitialDirection());
-		kBot.Upload(kProgram);
-
-		nSimulationState = SimulationState_Active;
-	}
-}
-
-/*
- * OnStop
- */
-void World::OnStop(GuiEventArguments& kArguments)
-{
-	if(nSimulationState == SimulationState_Active)
-	{
-		kEnvironment.Reset();
-
-		kBot.Reset();
-		kBot.SetPosition(kLoader.GetInitialPosition());
-		kBot.SetDirection(kLoader.GetInitialDirection());
-
-		nSimulationState = SimulationState_Idle;
-	}
-}
-
-/*
- * OnReset
- */
-void World::OnReset(GuiEventArguments& kArguments)
-{
-	kProgram.Clear();
-
-	for(uint32 i = 0; i < MaximumFunctionCount; ++i)
-	{
-		pCode[i]->Clear();
-	}
-}
-
-/*
- * OnExit
- */
-void World::OnExit(GuiEventArguments& kArguments)
-{
-	pConfirmDialog->SetMessage("Are you sure you want to exit?");
-	pConfirmDialog->SetButton(0, "Yes", DialogResult_Yes);
-	pConfirmDialog->SetButton(1, "No", DialogResult_No);
-	pConfirmDialog->Show();
-
-	nWorldState = WorldState_Confirm;
-}
-
-/*
- * OnResult
- */
-void World::OnResult(GuiEventArguments& kArguments)
-{
-	if(nWorldState == WorldState_Game)
-	{
-		if(nLogicState == LogicState_LevelComplete)
-		{
-			nLogicState = LogicState_LevelLoad;
-		}
-		else
-
-		if(nLogicState == LogicState_GameOver)
-		{
-			nCurrentLevel	= 0;
-			nLogicState		= LogicState_LevelLoad;
-
-			//TODO: Return to main menu
-			nWorldState = WorldState_Main;
-		}
-	}
-}
-
-/*
- * OnConfirm
- */
-void World::OnConfirm(GuiEventArguments& kArguments)
-{
-	if(nWorldState == WorldState_Confirm)
-	{
-		GuiResultArguments& kResultArguments = (GuiResultArguments&)kArguments;
-
-		if(kResultArguments.nResult == DialogResult_Yes)
-		{
-			Deactivate();
-		}
-		else
-
-		if(kResultArguments.nResult == DialogResult_No)
-		{
-			nWorldState = WorldState_Game;
-		}
-	}
-}
--- a/LightClone/Source/World.h	Tue Oct 11 12:09:04 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,253 +0,0 @@
-/*
- * World
- */
-
-#ifndef __WORLD_H__
-#define __WORLD_H__
-
-#include "Core.h"
-#include "ResourceManager.h"
-#include "RenderContext.h"
-#include "Environment.h"
-#include "Bot.h"
-#include "Loader.h"
-#include "CameraController.h"
-#include "InputManager.h"
-#include "GuiInterface.h"
-#include "GuiImage.h"
-#include "GuiButton.h"
-#include "ActionPanel.h"
-#include "Program.h"
-#include "Dialog.h"
-
-/*
- * MessageDialog
- */
-typedef Dialog<1> MessageDialog;
-
-/*
- * ChoiceDialog
- */
-typedef Dialog<2> ChoiceDialog;
-
-/*
- * World
- */
-class World
-{
-	/*
-	 * pInputManager
-	 */
-	InputManager* pInputManager;
-
-	/*
-	 * kLoader
-	 */
-	Loader kLoader;
-
-	/*
-	 * kEnvironment
-	 */
-	Environment kEnvironment;
-
-	/*
-	 * kBot
-	 */
-	Bot kBot;
-
-	/*
-	 * kProgram
-	 */
-	Program kProgram;
-
-	/*
-	 * nWorldState
-	 */
-	uint32 nWorldState;
-
-	/*
-	 * nLogicState
-	 */
-	uint32 nLogicState;
-
-	/*
-	 * nSimulationState
-	 */
-	uint32 nSimulationState;
-
-	/*
-	 * nCurrentLevel
-	 */
-	uint32 nCurrentLevel;
-
-	/*
-	 * kCameraController
-	 */
-	CameraController kCameraController;
-
-	/*
-	 * kInterface
-	 */
-	GuiInterface kInterface;
-
-	/*
-	 * pBackground
-	 */
-	GuiImage* pBackground;
-
-	/*
-	 * pButtonPlay
-	 */
-	GuiButton* pButtonPlay;
-
-	/*
-	 * pButtonStop
-	 */
-	GuiButton* pButtonStop;
-
-	/*
-	 * pButtonReset
-	 */
-	GuiButton* pButtonReset;
-
-	/*
-	 * pButtonExit
-	 */
-	GuiButton* pButtonExit;
-
-	/*
-	 * pToolbar
-	 */
-	ActionPanel* pToolbar;
-
-	/*
-	 * pCode
-	 */
-	ActionPanel* pCode[MaximumFunctionCount];
-
-	/*
-	 * pMessageDialog
-	 */
-	MessageDialog* pMessageDialog;
-
-	/*
-	 * pConfirmDialog
-	 */
-	ChoiceDialog* pConfirmDialog;
-
-	/*
-	 * pDebugText
-	 */
-	GuiLabel* pDebugText;
-
-public:
-	
-	/*
-	 * World
-	 */
-	World();
-
-	/*
-	 * Initialize
-	 */
-	ErrorCode Initialize(ServiceProvider* pServiceProvider);
-
-	/*
-	 * Terminate
-	 */
-	void Terminate();
-
-	/*
-	 * Activate
-	 */
-	void Activate();
-
-	/*
-	 * Deactivate
-	 */
-	void Deactivate();
-
-	/*
-	 * IsActive
-	 */
-	bool IsActive();
-
-	/*
-	 * Load
-	 */
-	ErrorCode Load(const char* pName);
-
-	/*
-	 * Update
-	 */
-	void Update(float fElapsed);
-
-	/*
-	 * Render
-	 */
-	void Render(RenderContext& kContext);
-
-private:
-
-	/*
-	 * InitializeInterface
-	 */
-	ErrorCode InitializeInterface(ServiceProvider* pServiceProvider);
-
-	/*
-	 * 	RenderEnvironment
-	 */
-	void RenderEnvironment(RenderContext& kContext, Environment* pEnvironment);
-
-	/*
-	 * RenderBot
-	 */
-	void RenderBot(RenderContext& kContext, Environment* pEnvironment, Bot* pBot);
-
-	/*
-	 * UpdateInput
-	 */
-	void UpdateInput(float fElapsed);
-
-	/*
-	 * UpdateLogic
-	 */
-	void UpdateLogic(float fElapsed);
-
-	/*
-	 * OnAction
-	 */
-	void OnAction(GuiEventArguments& kArguments);
-
-	/*
-	 * OnPlay
-	 */
-	void OnPlay(GuiEventArguments& kArguments);
-
-	/*
-	 * OnStop
-	 */
-	void OnStop(GuiEventArguments& kArguments);
-
-	/*
-	 * OnReset
-	 */
-	void OnReset(GuiEventArguments& kArguments);
-
-	/*
-	 * OnExit
-	 */
-	void OnExit(GuiEventArguments& kArguments);
-
-	/*
-	 * OnResult
-	 */
-	void OnResult(GuiEventArguments& kArguments);
-
-	/*
-	 * OnConfirm
-	 */
-	void OnConfirm(GuiEventArguments& kArguments);
-};
-
-#endif //__WORLD_H__