changeset 74:40c0b5305de8

Work on removing ScreenManager
author koryspansel
date Tue, 18 Oct 2011 11:56:49 -0700
parents 0574e2cf8bac
children 57c0ce406a68
files LightClone/LightClone.vcproj LightClone/Source/ConfirmScreen.cpp LightClone/Source/ConfirmScreen.h LightClone/Source/Core.h LightClone/Source/GameOverScreen.cpp LightClone/Source/GameOverScreen.h LightClone/Source/GameScreen.cpp LightClone/Source/GameScreen.h LightClone/Source/HelpScreen.cpp LightClone/Source/HelpScreen.h LightClone/Source/LevelOverScreen.cpp LightClone/Source/LevelOverScreen.h LightClone/Source/MainScreen.cpp LightClone/Source/MainScreen.h LightClone/Source/Mediator.cpp LightClone/Source/Mediator.h LightClone/Source/PauseScreen.cpp LightClone/Source/PauseScreen.h
diffstat 18 files changed, 771 insertions(+), 195 deletions(-) [+]
line wrap: on
line diff
--- a/LightClone/LightClone.vcproj	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/LightClone.vcproj	Tue Oct 18 11:56:49 2011 -0700
@@ -302,14 +302,6 @@
 					>
 				</File>
 				<File
-					RelativePath=".\Source\Screen.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\ScreenManager.cpp"
-					>
-				</File>
-				<File
 					RelativePath=".\Source\Service.cpp"
 					>
 				</File>
@@ -334,38 +326,6 @@
 					>
 				</File>
 			</Filter>
-			<Filter
-				Name="Screens"
-				>
-				<File
-					RelativePath=".\Source\ConfirmScreen.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\GameOverScreen.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\GameScreen.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\HelpScreen.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\LevelOverScreen.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\MainScreen.cpp"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\PauseScreen.cpp"
-					>
-				</File>
-			</Filter>
 		</Filter>
 		<Filter
 			Name="Header Files"
@@ -524,14 +484,6 @@
 					>
 				</File>
 				<File
-					RelativePath=".\Source\Screen.h"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\ScreenManager.h"
-					>
-				</File>
-				<File
 					RelativePath=".\Source\Service.h"
 					>
 				</File>
@@ -560,38 +512,6 @@
 					>
 				</File>
 			</Filter>
-			<Filter
-				Name="Screens"
-				>
-				<File
-					RelativePath=".\Source\ConfirmScreen.h"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\GameOverScreen.h"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\GameScreen.h"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\HelpScreen.h"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\LevelOverScreen.h"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\MainScreen.h"
-					>
-				</File>
-				<File
-					RelativePath=".\Source\PauseScreen.h"
-					>
-				</File>
-			</Filter>
 		</Filter>
 		<Filter
 			Name="Resource Files"
--- a/LightClone/Source/ConfirmScreen.cpp	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/ConfirmScreen.cpp	Tue Oct 18 11:56:49 2011 -0700
@@ -3,7 +3,6 @@
  */
 
 #include "ConfirmScreen.h"
-#include "ScreenManager.h"
 
 /*
  * Initialize
@@ -30,8 +29,6 @@
 void ConfirmScreen::Terminate()
 {
 	kInterface.Terminate();
-
-	Screen::Terminate();
 }
 
 /*
@@ -76,12 +73,12 @@
 
 	if(kResultArguments.nResult == DialogResult_Yes)
 	{
-		pScreenManager->Set(NULL);
+		//pScreenManager->Set(NULL);
 	}
 	else
 
 	if(kResultArguments.nResult == DialogResult_No)
 	{
-		pScreenManager->Pop();
+		//pScreenManager->Pop();
 	}
 }
--- a/LightClone/Source/ConfirmScreen.h	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/ConfirmScreen.h	Tue Oct 18 11:56:49 2011 -0700
@@ -6,7 +6,6 @@
 #define __CONFIRMSCREEN_H__
 
 #include "Core.h"
-#include "Screen.h"
 #include "CameraController.h"
 #include "GuiInterface.h"
 #include "Dialog.h"
@@ -14,7 +13,7 @@
 /*
  * ConfirmScreen
  */
-class ConfirmScreen : public Screen
+class ConfirmScreen
 {
 	/*
 	 * kCameraController
--- a/LightClone/Source/Core.h	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/Core.h	Tue Oct 18 11:56:49 2011 -0700
@@ -18,27 +18,27 @@
 #include <tchar.h>
 
 /*
- * WorldState
+ * ApplicationState
  */
 enum
 {
-	WorldState_Main,
-	WorldState_Game,
-	WorldState_Pause,
-	WorldState_Help,
-	WorldState_Confirm,
-	WorldState_Exit,
+	ApplicationState_Main,
+	ApplicationState_Game,
+	ApplicationState_Pause,
+	ApplicationState_Help,
+	ApplicationState_Confirm,
+	ApplicationState_Exit,
 };
 
 /*
- * LogicState
+ * GameState
  */
 enum
 {
-	LogicState_LevelLoad,
-	LogicState_LevelComplete,
-	LogicState_GameActive,
-	LogicState_GameOver,
+	GameState_Load,
+	GameState_Active,
+	GameState_Complete,
+	GameState_Over,
 };
 
 /*
--- a/LightClone/Source/GameOverScreen.cpp	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/GameOverScreen.cpp	Tue Oct 18 11:56:49 2011 -0700
@@ -3,7 +3,6 @@
  */
 
 #include "GameOverScreen.h"
-#include "ScreenManager.h"
 
 /*
  * Initialize
@@ -30,8 +29,6 @@
 void GameOverScreen::Terminate()
 {
 	kInterface.Terminate();
-
-	Screen::Terminate();
 }
 
 /*
@@ -76,6 +73,6 @@
 
 	if(kResultArguments.nResult == DialogResult_Ok)
 	{
-		pScreenManager->Set("Main");
+		//pScreenManager->Set("Main");
 	}
 }
--- a/LightClone/Source/GameOverScreen.h	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/GameOverScreen.h	Tue Oct 18 11:56:49 2011 -0700
@@ -6,7 +6,6 @@
 #define __GAMEOVERSCREEN_H__
 
 #include "Core.h"
-#include "Screen.h"
 #include "CameraController.h"
 #include "GuiInterface.h"
 #include "Dialog.h"
@@ -14,7 +13,7 @@
 /*
  * GameOverScreen
  */
-class GameOverScreen : public Screen
+class GameOverScreen
 {
 	/*
 	 * kCameraController
--- a/LightClone/Source/GameScreen.cpp	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/GameScreen.cpp	Tue Oct 18 11:56:49 2011 -0700
@@ -3,7 +3,6 @@
  */
 
 #include "GameScreen.h"
-#include "ScreenManager.h"
 
 /*
  * Initialize
@@ -55,7 +54,7 @@
 		return eCode;
 	}
 
-	nLogicState			= LogicState_LevelLoad;
+	nGameState			= GameState_Load;
 	nSimulationState	= SimulationState_Idle;
 	nCurrentLevel		= 0;
 
@@ -71,8 +70,6 @@
 	kProgram.Terminate();
 	kBot.Terminate();
 	kEnvironment.Terminate();
-
-	Screen::Terminate();
 }
 
 /*
@@ -101,7 +98,7 @@
  */
 void GameScreen::Render(RenderContext& kContext)
 {
-	if(nLogicState != LogicState_LevelLoad)
+	if(nGameState != GameState_Load)
 	{
 		D3DVIEWPORT9 kOriginal;
 		kContext.GetViewport(&kOriginal);
@@ -413,7 +410,7 @@
 			if(nCount > 0)
 			{
 				nCurrentLevel	= 0;
-				nLogicState		= LogicState_LevelLoad;
+				nGameState		= GameState_Load;
 
 				for(uint32 i = 0; i < nCount; ++i)
 				{
@@ -440,7 +437,7 @@
  */
 void GameScreen::UpdateLogic(float fElapsed)
 {
-	if(nLogicState == LogicState_LevelLoad)
+	if(nGameState == GameState_Load)
 	{
 		char kBuffer[256];
 		sprintf(kBuffer, "Data\\Maps\\Map%02d.map", nCurrentLevel++);
@@ -455,18 +452,18 @@
 				pCode[i]->Clear();
 			}
 
-			nLogicState = LogicState_GameActive;
+			nGameState = GameState_Active;
 		}
 		else
 		{
-			pScreenManager->Push("GameOver");
+			//pScreenManager->Push("GameOver");
 		}
 
 		nSimulationState = SimulationState_Idle;
 	}
 	else
 
-	if(nLogicState == LogicState_GameActive)
+	if(nGameState == GameState_Active)
 	{
 		if(nSimulationState == SimulationState_Active)
 		{
@@ -474,8 +471,8 @@
 			{
 				if(kEnvironment.RequirementsMet())
 				{
-					nLogicState = LogicState_LevelLoad;
-					pScreenManager->Push("LevelOver");
+					nGameState = GameState_Load;
+					//pScreenManager->Push("LevelOver");
 				}
 			}
 		}
@@ -551,5 +548,5 @@
  */
 void GameScreen::OnExit(GuiEventArguments& kArguments)
 {
-	pScreenManager->Push("Confirm");
+	//pScreenManager->Push("Confirm");
 }
--- a/LightClone/Source/GameScreen.h	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/GameScreen.h	Tue Oct 18 11:56:49 2011 -0700
@@ -6,7 +6,6 @@
 #define __GAMESCREEN_H__
 
 #include "Core.h"
-#include "Screen.h"
 #include "CameraController.h"
 #include "GuiInterface.h"
 #include "GuiImage.h"
@@ -20,7 +19,7 @@
 /*
  * GameScreen
  */
-class GameScreen : public Screen
+class GameScreen
 {
 	/*
 	 * pInputManager
@@ -53,9 +52,9 @@
 	Program kProgram;
 
 	/*
-	 * nLogicState
+	 * nGameState
 	 */
-	uint32 nLogicState;
+	uint32 nGameState;
 
 	/*
 	 * nSimulationState
--- a/LightClone/Source/HelpScreen.cpp	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/HelpScreen.cpp	Tue Oct 18 11:56:49 2011 -0700
@@ -17,7 +17,6 @@
  */
 void HelpScreen::Terminate()
 {
-	Screen::Terminate();
 }
 
 /*
--- a/LightClone/Source/HelpScreen.h	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/HelpScreen.h	Tue Oct 18 11:56:49 2011 -0700
@@ -6,12 +6,13 @@
 #define __HELPSCREEN_H__
 
 #include "Core.h"
-#include "Screen.h"
+#include "ServiceProvider.h"
+#include "RenderContext.h"
 
 /*
  * HelpScreen
  */
-class HelpScreen : public Screen
+class HelpScreen
 {
 public:
 
--- a/LightClone/Source/LevelOverScreen.cpp	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/LevelOverScreen.cpp	Tue Oct 18 11:56:49 2011 -0700
@@ -3,7 +3,6 @@
  */
 
 #include "LevelOverScreen.h"
-#include "ScreenManager.h"
 
 /*
  * Initialize
@@ -30,8 +29,6 @@
 void LevelOverScreen::Terminate()
 {
 	kInterface.Terminate();
-
-	Screen::Terminate();
 }
 
 /*
@@ -76,6 +73,5 @@
 
 	if(kResultArguments.nResult == DialogResult_Ok)
 	{
-		pScreenManager->Pop();
 	}
 }
--- a/LightClone/Source/LevelOverScreen.h	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/LevelOverScreen.h	Tue Oct 18 11:56:49 2011 -0700
@@ -6,7 +6,6 @@
 #define __LEVELOVERSCREEN_H__
 
 #include "Core.h"
-#include "Screen.h"
 #include "CameraController.h"
 #include "GuiInterface.h"
 #include "Dialog.h"
@@ -14,7 +13,7 @@
 /*
  * LevelOverScreen
  */
-class LevelOverScreen : public Screen
+class LevelOverScreen
 {
 	/*
 	 * kCameraController
--- a/LightClone/Source/MainScreen.cpp	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/MainScreen.cpp	Tue Oct 18 11:56:49 2011 -0700
@@ -9,7 +9,7 @@
  */
 ErrorCode MainScreen::Initialize(ServiceProvider* pServiceProvider)
 {
-	ErrorCode eCode = Screen::Initialize(pServiceProvider);
+	ErrorCode eCode = Error_Success;
 	if(eCode == Error_Success)
 	{
 		eCode = kInterface.Initialize(pServiceProvider);
@@ -61,7 +61,6 @@
  */
 void MainScreen::Terminate()
 {
-	Screen::Terminate();
 }
 
 /*
--- a/LightClone/Source/MainScreen.h	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/MainScreen.h	Tue Oct 18 11:56:49 2011 -0700
@@ -6,7 +6,6 @@
 #define __MAINSCREEN_H__
 
 #include "Core.h"
-#include "Screen.h"
 #include "GuiInterface.h"
 #include "GuiButton.h"
 #include "GuiImage.h"
@@ -14,7 +13,7 @@
 /*
  * MainScreen
  */
-class MainScreen : public Screen
+class MainScreen
 {
 	/*
 	 * kInterface
--- a/LightClone/Source/Mediator.cpp	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/Mediator.cpp	Tue Oct 18 11:56:49 2011 -0700
@@ -18,14 +18,6 @@
 Mediator::Mediator() : kWindow(this)
 {
 	pGraphicsDevice	= NULL;
-
-	kScreenManager.Register("Main", &kMainScreen);
-	kScreenManager.Register("Help", &kHelpScreen);
-	kScreenManager.Register("Game", &kGameScreen);
-	kScreenManager.Register("Pause", &kPauseScreen);
-	kScreenManager.Register("LevelOver", &kLevelOverScreen);
-	kScreenManager.Register("GameOver", &kGameOverScreen);
-	kScreenManager.Register("Confirm", &kConfirmScreen);
 }
 
 /*
@@ -36,25 +28,14 @@
 	ErrorCode eCode = Initialize();
 	if(eCode == Error_Success)
 	{
-		float fAccumulator = fUpdatePeriod;
-
 		kClock.Reset();
 
-		while(kScreenManager.IsActive())
+		fAccumulator = fUpdatePeriod;
+		while(nApplicationState != ApplicationState_Exit)
 		{
 			ProcessMessages();
-
-			fAccumulator += Min(kClock.GetElapsed(), fUpdatePeriod);
-			while(fAccumulator >= fUpdatePeriod)
-			{
-				Update(fUpdatePeriod);
-				fAccumulator -= fUpdatePeriod;
-			}
-
-			//if(updated)
-			{
-				Render();
-			}
+			ProcessUpdate();
+			ProcessRender();
 		}
 
 		Terminate();
@@ -154,16 +135,45 @@
 		return eCode;
 	}
 
-	eCode = kScreenManager.Initialize(&kServiceProvider);
+	eCode = kEnvironment.Initialize(&kServiceProvider);
 	if(eCode != Error_Success)
 	{
-		TRACE("Error: Failed to initialize screen manager\n");
+		TRACE("Error: Failed to initialize environment\n");
+
+		Terminate();
+		return eCode;
+	}
+
+	eCode = kBot.Initialize(&kServiceProvider);
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to initialize bot\n");
 
 		Terminate();
 		return eCode;
 	}
 
-	kScreenManager.Push("Game");
+	eCode = kProgram.Initialize();
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to initialize program\n");
+
+		Terminate();
+		return eCode;
+	}
+
+	eCode = InitializeInterface(&kServiceProvider);				
+	if(eCode != Error_Success)
+	{
+		TRACE("Error: Failed to initialize interface\n");
+
+		Terminate();
+		return eCode;
+	}
+
+	nGameState			= GameState_Load;
+	nSimulationState	= SimulationState_Idle;
+	nCurrentLevel		= 0;
 
 	return eCode;
 }
@@ -173,7 +183,10 @@
  */
 void Mediator::Terminate()
 {
-	kScreenManager.Terminate();
+	kInterface.Terminate();
+	kProgram.Terminate();
+	kBot.Terminate();
+	kEnvironment.Terminate();
 	kInputManager.Terminate();
 	kResourceManager.Terminate();
 	kContext.Terminate();
@@ -188,7 +201,45 @@
  */
 void Mediator::Update(float fElapsed)
 {
-	kScreenManager.Update(fElapsed);
+	kInputManager.Update(fElapsed);
+
+	if(nApplicationState == ApplicationState_Main)
+	{
+	}
+	else
+
+	if(nApplicationState == ApplicationState_Game)
+	{
+		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);
+	}
+	else
+
+	if(nApplicationState == ApplicationState_Pause)
+	{
+	}
+	else
+
+	if(nApplicationState == ApplicationState_Help)
+	{
+	}
+	else
+
+	if(nApplicationState == ApplicationState_Confirm)
+	{
+	}
+
+	//kScreenManager.Update(fElapsed);
 }
 
 /*
@@ -199,7 +250,57 @@
 	const uint32 nColor = D3DCOLOR_XRGB(32, 32, 32);
 
 	kContext.Begin(nColor);
-	kScreenManager.Render(kContext);
+	//kScreenManager.Render(kContext);
+
+	if(nApplicationState == ApplicationState_Main)
+	{
+	}
+	else
+
+	if(nApplicationState == ApplicationState_Game)
+	{
+		if(nGameState != GameState_Load)
+		{
+			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);
+	}
+	else
+
+	if(nApplicationState == ApplicationState_Pause)
+	{
+	}
+	else
+
+	if(nApplicationState == ApplicationState_Help)
+	{
+	}
+	else
+
+	if(nApplicationState == ApplicationState_Confirm)
+	{
+	}
+
 	kContext.End();
 }
 
@@ -214,11 +315,459 @@
 	{
 		if(kMessage.message == WM_QUIT)
 		{
-			kScreenManager.Set(NULL);
-			break;
+			nApplicationState = ApplicationState_Exit;
+		}
+		else
+		{
+			TranslateMessage(&kMessage);
+			DispatchMessage(&kMessage);
+		}
+	}
+}
+
+/*
+ * ProcessUpdate
+ */
+void Mediator::ProcessUpdate()
+{
+	fAccumulator += Min(kClock.GetElapsed(), fUpdatePeriod);
+	while(fAccumulator >= fUpdatePeriod)
+	{
+		Update(fUpdatePeriod);
+		fAccumulator -= fUpdatePeriod;
+	}
+}
+
+/*
+ * ProcessRender
+ */
+void Mediator::ProcessRender()
+{
+	Render();
+}
+
+/*
+ * Load
+ */
+ErrorCode Mediator::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 Mediator::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, &Mediator::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, &Mediator::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, &Mediator::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, &Mediator::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, &Mediator::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, &Mediator::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, &Mediator::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);
+
+		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);
+	}
+
+	return eCode;
+}
+
+/*
+ * UpdateInput
+ */
+void Mediator::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;
 		}
 
-		TranslateMessage(&kMessage);
-		DispatchMessage(&kMessage);
+		if(!pInputManager->IsKeyDown(DIK_LCONTROL))
+		{
+			if(nCount > 0)
+			{
+				nCurrentLevel	= 0;
+				nGameState		= GameState_Load;
+
+				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 Mediator::UpdateLogic(float fElapsed)
+{
+	if(nGameState == GameState_Load)
+	{
+		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();
+			}
+
+			nGameState = GameState_Active;
+		}
+		else
+		{
+			//pScreenManager->Push("GameOver");
+		}
+
+		nSimulationState = SimulationState_Idle;
+	}
+	else
+
+	if(nGameState == GameState_Active)
+	{
+		if(nSimulationState == SimulationState_Active)
+		{
+			if(kBot.Update(fElapsed))
+			{
+				if(kEnvironment.RequirementsMet())
+				{
+					nGameState = GameState_Load;
+					//pScreenManager->Push("LevelOver");
+				}
+			}
+		}
 	}
 }
+
+/*
+ * OnAction
+ */
+void Mediator::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 Mediator::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 Mediator::OnStop(GuiEventArguments& kArguments)
+{
+	if(nSimulationState == SimulationState_Active)
+	{
+		kEnvironment.Reset();
+
+		kBot.Reset();
+		kBot.SetPosition(kLoader.GetInitialPosition());
+		kBot.SetDirection(kLoader.GetInitialDirection());
+
+		nSimulationState = SimulationState_Idle;
+	}
+}
+
+/*
+ * OnReset
+ */
+void Mediator::OnReset(GuiEventArguments& kArguments)
+{
+	kProgram.Clear();
+
+	for(uint32 i = 0; i < MaximumFunctionCount; ++i)
+	{
+		pCode[i]->Clear();
+	}
+}
+
+/*
+ * OnExit
+ */
+void Mediator::OnExit(GuiEventArguments& kArguments)
+{
+	//pScreenManager->Push("Confirm");
+}
--- a/LightClone/Source/Mediator.h	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/Mediator.h	Tue Oct 18 11:56:49 2011 -0700
@@ -13,14 +13,15 @@
 #include "ResourceManager.h"
 #include "RenderContext.h"
 #include "ServiceProvider.h"
-#include "ScreenManager.h"
-#include "MainScreen.h"
-#include "HelpScreen.h"
-#include "PauseScreen.h"
-#include "GameScreen.h"
-#include "LevelOverScreen.h"
-#include "GameOverScreen.h"
-#include "ConfirmScreen.h"
+#include "CameraController.h"
+#include "Loader.h"
+#include "Environment.h"
+#include "Bot.h"
+#include "GuiInterface.h"
+#include "GuiImage.h"
+#include "GuiButton.h"
+#include "ActionPanel.h"
+#include "Dialog.h"
 
 /*
  * Mediator
@@ -63,44 +64,114 @@
 	ServiceProvider kServiceProvider;
 
 	/*
-	 * kScreenManager
+	 * fAccumulator
+	 */
+	float fAccumulator;
+
+	/*
+	 * nApplicationState
 	 */
-	ScreenManager kScreenManager;
+	uint32 nApplicationState;
+
+	/*
+	 * pInputManager
+	 */
+	InputManager* pInputManager;
+
+	/*
+	 * kCameraController
+	 */
+	CameraController kCameraController;
 
 	/*
-	 * kMainScreen
+	 * kLoader
 	 */
-	MainScreen kMainScreen;
+	Loader kLoader;
+
+	/*
+	 * kEnvironment
+	 */
+	Environment kEnvironment;
 
 	/*
-	 * kHelpScreen
+	 * kBot
+	 */
+	Bot kBot;
+
+	/*
+	 * kProgram
 	 */
-	HelpScreen kHelpScreen;
+	Program kProgram;
+
+	/*
+	 * nGameState
+	 */
+	uint32 nGameState;
+
+	/*
+	 * nSimulationState
+	 */
+	uint32 nSimulationState;
 
 	/*
-	 * kGameScreen
+	 * nCurrentLevel
 	 */
-	GameScreen kGameScreen;
+	uint32 nCurrentLevel;
+
+	/*
+	 * kInterface
+	 */
+	GuiInterface kInterface;
 
 	/*
-	 * kPauseScreen
+	 * pBackground
+	 */
+	GuiImage* pBackground;
+
+	/*
+	 * pButtonPlay
 	 */
-	PauseScreen kPauseScreen;
+	GuiButton* pButtonPlay;
+
+	/*
+	 * pButtonStop
+	 */
+	GuiButton* pButtonStop;
 
 	/*
-	 * kLevelOverScreen
+	 * pButtonReset
+	 */
+	GuiButton* pButtonReset;
+
+	/*
+	 * pButtonExit
 	 */
-	LevelOverScreen kLevelOverScreen;
+	GuiButton* pButtonExit;
+
+	/*
+	 * pToolbar
+	 */
+	ActionPanel* pToolbar;
 
 	/*
-	 * kGameOverScreen
+	 * pCode
 	 */
-	GameOverScreen kGameOverScreen;
+	ActionPanel* pCode[MaximumFunctionCount];
 
 	/*
-	 * kConfirmScreen
+	 * pMessageDialog
+	 */
+	MessageDialog* pMessageDialog;
+
+	/*
+	 * pConfirmDialog
 	 */
-	ConfirmScreen kConfirmScreen;
+	ChoiceDialog* pConfirmDialog;
+
+	/*
+	 * pDebugText
+	 */
+	GuiLabel* pDebugText;
 
 public:
 
@@ -145,6 +216,61 @@
 	 * ProcessMessages
 	 */
 	virtual void ProcessMessages();
+
+	/*
+	 * ProcessUpdate
+	 */
+	void ProcessUpdate();
+
+	/*
+	 * ProcessRender
+	 */
+	void ProcessRender();
+
+	/*
+	 * Load
+	 */
+	ErrorCode Load(const char* pName);
+
+	/*
+	 * 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);
 };
 
 #endif //__MEDIATOR_H__
--- a/LightClone/Source/PauseScreen.cpp	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/PauseScreen.cpp	Tue Oct 18 11:56:49 2011 -0700
@@ -17,7 +17,6 @@
  */
 void PauseScreen::Terminate()
 {
-	Screen::Terminate();
 }
 
 /*
--- a/LightClone/Source/PauseScreen.h	Tue Oct 11 17:44:10 2011 -0700
+++ b/LightClone/Source/PauseScreen.h	Tue Oct 18 11:56:49 2011 -0700
@@ -6,12 +6,13 @@
 #define __PAUSESCREEN_H__
 
 #include "Core.h"
-#include "Screen.h"
+#include "ServiceProvider.h"
+#include "RenderContext.h"
 
 /*
  * PauseScreen
  */
-class PauseScreen : public Screen
+class PauseScreen
 {
 public: