Mercurial > LightClone
changeset 70:ffaeccdc105e
Work on screen manager
author | koryspansel |
---|---|
date | Tue, 11 Oct 2011 12:09:04 -0700 |
parents | d1be174e5585 |
children | bc8afcf7e1ec |
files | LightClone/LightClone.vcproj LightClone/Source/FixedStack.h LightClone/Source/GameScreen.cpp LightClone/Source/GameScreen.h LightClone/Source/HelpScreen.cpp LightClone/Source/HelpScreen.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 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 | 18 files changed, 585 insertions(+), 107 deletions(-) [+] |
line wrap: on
line diff
--- a/LightClone/LightClone.vcproj Mon Oct 10 09:49:54 2011 -0700 +++ b/LightClone/LightClone.vcproj Tue Oct 11 12:09:04 2011 -0700 @@ -338,6 +338,26 @@ > </File> </Filter> + <Filter + Name="Screens" + > + <File + RelativePath=".\Source\GameScreen.cpp" + > + </File> + <File + RelativePath=".\Source\HelpScreen.cpp" + > + </File> + <File + RelativePath=".\Source\MainScreen.cpp" + > + </File> + <File + RelativePath=".\Source\PauseScreen.cpp" + > + </File> + </Filter> </Filter> <Filter Name="Header Files" @@ -536,6 +556,26 @@ > </File> </Filter> + <Filter + Name="Screens" + > + <File + RelativePath=".\Source\GameScreen.h" + > + </File> + <File + RelativePath=".\Source\HelpScreen.h" + > + </File> + <File + RelativePath=".\Source\MainScreen.h" + > + </File> + <File + RelativePath=".\Source\PauseScreen.h" + > + </File> + </Filter> </Filter> <Filter Name="Resource Files"
--- a/LightClone/Source/FixedStack.h Mon Oct 10 09:49:54 2011 -0700 +++ b/LightClone/Source/FixedStack.h Tue Oct 11 12:09:04 2011 -0700 @@ -43,14 +43,7 @@ */ ErrorCode Push(Type kValue) { - ErrorCode eCode = Error_Success; - - if(nTop < Bottom) - { - kStack[++nTop] = kValue; - } - - return eCode; + return (nTop < Bottom) ? kStack[++nTop] = kValue, Error_Success : Error_Fail; } /* @@ -58,8 +51,8 @@ */ Type Pop() { - ErrorCode eCode = Error_Fail; - return eCode; + ASSERT(nTop > -1); + return kStack[nTop--]; } /* @@ -67,6 +60,8 @@ */ const Type& Peek() { + ASSERT(nTop > -1); + return kStack[nTop]; } /* @@ -82,23 +77,7 @@ */ uint32 Size() const { - return nSize; - } - - /* - * Find - */ - int32 Find(Type& kValue) const - { - for(uint32 i = 0; i < nSize; ++i) - { - if(pList[i] == kValue) - { - return (int32)i; - } - } - - return -1; + return nTop + 1; } /* @@ -106,8 +85,8 @@ */ Type& operator[](uint32 nIndex) { - ASSERT(nIndex < nSize); - return pList[nIndex]; + ASSERT(nIndex < nTop + 1); + return kStack[nIndex]; } /* @@ -115,36 +94,8 @@ */ const Type& operator[](uint32 nIndex) const { - ASSERT(nIndex < nSize); - return pList[nIndex]; - } - -private: - - /* - * Resize - */ - ErrorCode Resize(uint32 nAmount) - { - if(nAmount > nCapacity) - { - Type* pArray = new Type[2 * nAmount]; - - if(pList) - { - for(uint32 i = 0; i < nSize; ++i) - { - pArray[i] = pList[i]; - } - - delete[] pList; - } - - pList = pArray; - nCapacity = 2 * nAmount; - } - - return Error_Success; + ASSERT(nIndex < nTop + 1); + return kStack[nIndex]; } };
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/GameScreen.cpp Tue Oct 11 12:09:04 2011 -0700 @@ -0,0 +1,48 @@ +/* + * GameScreen + */ + +#include "GameScreen.h" + +/* + * Initialize + */ +ErrorCode GameScreen::Initialize(ServiceProvider* pServiceProvider) +{ + ErrorCode eCode = kWorld.Initialize(pServiceProvider); + if(eCode != Error_Success) + { + TRACE("Error: Failed to initialize world\n"); + + Terminate(); + return eCode; + } + + return eCode; +} + +/* + * Terminate + */ +void GameScreen::Terminate() +{ + kWorld.Terminate(); + + Screen::Terminate(); +} + +/* + * Update + */ +void GameScreen::Update(float fElapsed) +{ + kWorld.Update(fElapsed); +} + +/* + * Render + */ +void GameScreen::Render(RenderContext& kContext) +{ + kWorld.Render(kContext); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/GameScreen.h Tue Oct 11 12:09:04 2011 -0700 @@ -0,0 +1,45 @@ +/* + * GameScreen + */ + +#ifndef __GAMESCREEN_H__ +#define __GAMESCREEN_H__ + +#include "Core.h" +#include "Screen.h" +#include "World.h" + +/* + * GameScreen + */ +class GameScreen : public Screen +{ + /* + * kWorld + */ + World kWorld; + +public: + + /* + * Initialize + */ + virtual ErrorCode Initialize(ServiceProvider* pServiceProvider); + + /* + * Terminate + */ + virtual void Terminate(); + + /* + * Update + */ + virtual void Update(float fElapsed); + + /* + * Render + */ + virtual void Render(RenderContext& kContext); +}; + +#endif //__GAMESCREEN_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/HelpScreen.cpp Tue Oct 11 12:09:04 2011 -0700 @@ -0,0 +1,35 @@ +/* + * HelpScreen + */ + +#include "HelpScreen.h" + +/* + * Initialize + */ +ErrorCode HelpScreen::Initialize(ServiceProvider* pServiceProvider) +{ + return Error_Success; +} + +/* + * Terminate + */ +void HelpScreen::Terminate() +{ + Screen::Terminate(); +} + +/* + * Update + */ +void HelpScreen::Update(float fElapsed) +{ +} + +/* + * Render + */ +void HelpScreen::Render(RenderContext& kContext) +{ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/HelpScreen.h Tue Oct 11 12:09:04 2011 -0700 @@ -0,0 +1,39 @@ +/* + * HelpScreen + */ + +#ifndef __HELPSCREEN_H__ +#define __HELPSCREEN_H__ + +#include "Core.h" +#include "Screen.h" + +/* + * HelpScreen + */ +class HelpScreen : public Screen +{ +public: + + /* + * Initialize + */ + virtual ErrorCode Initialize(ServiceProvider* pServiceProvider); + + /* + * Terminate + */ + virtual void Terminate(); + + /* + * Update + */ + virtual void Update(float fElapsed); + + /* + * Render + */ + virtual void Render(RenderContext& kContext); +}; + +#endif //__HELPSCREEN_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/MainScreen.cpp Tue Oct 11 12:09:04 2011 -0700 @@ -0,0 +1,79 @@ +/* + * MainScreen + */ + +#include "MainScreen.h" + +/* + * Initialize + */ +ErrorCode MainScreen::Initialize(ServiceProvider* pServiceProvider) +{ + ErrorCode eCode = Screen::Initialize(pServiceProvider); + if(eCode == Error_Success) + { + eCode = kInterface.Initialize(pServiceProvider); + if(eCode == Error_Success) + { + pBackground = new GuiImage(); + pBackground->Initialize(pServiceProvider); + pBackground->SetTexture("Data\\Textures\\MainBackground.tga", true); + + pButtonStart = new GuiButton(); + pButtonStart->Initialize(pServiceProvider); + pButtonStart->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button2N.png", true); + pButtonStart->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Button2H.png"); + pButtonStart->SetTexture(GuiButtonState_Down, "Data\\Textures\\Button2D.png"); + pButtonStart->SetFont("Courier New", 16); + pButtonStart->SetText("Start"); + pButtonStart->SetPosition(800.0f, 400.0f); + + pButtonHelp = new GuiButton(); + pButtonHelp->Initialize(pServiceProvider);; + pButtonHelp->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button2N.png", true); + pButtonHelp->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Button2H.png"); + pButtonHelp->SetTexture(GuiButtonState_Down, "Data\\Textures\\Button2D.png"); + pButtonHelp->SetFont("Courier New", 16); + pButtonHelp->SetText("Help"); + pButtonHelp->SetPosition(800.0f, 440.0f); + + pButtonExit = new GuiButton(); + pButtonExit->Initialize(pServiceProvider); + pButtonExit->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button2N.png", true); + pButtonExit->SetTexture(GuiButtonState_Hover, "Data\\Textures\\Button2H.png"); + pButtonExit->SetTexture(GuiButtonState_Down, "Data\\Textures\\Button2D.png"); + pButtonExit->SetFont("Courier New", 16); + pButtonExit->SetText("Exit"); + pButtonExit->SetPosition(800.0f, 480.0f); + + kInterface.Add(pBackground); + kInterface.Add(pButtonStart); + kInterface.Add(pButtonHelp); + kInterface.Add(pButtonExit); + } + } + + return eCode; +} + +/* + * Terminate + */ +void MainScreen::Terminate() +{ + Screen::Terminate(); +} + +/* + * Update + */ +void MainScreen::Update(float fElapsed) +{ +} + +/* + * Render + */ +void MainScreen::Render(RenderContext& kContext) +{ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/MainScreen.h Tue Oct 11 12:09:04 2011 -0700 @@ -0,0 +1,67 @@ +/* + * MainScreen + */ + +#ifndef __MAINSCREEN_H__ +#define __MAINSCREEN_H__ + +#include "Core.h" +#include "Screen.h" +#include "GuiInterface.h" +#include "GuiButton.h" +#include "GuiImage.h" + +/* + * MainScreen + */ +class MainScreen : public Screen +{ + /* + * kInterface + */ + GuiInterface kInterface; + + /* + * pBackground + */ + GuiImage* pBackground; + + /* + * pButtonStart + */ + GuiButton* pButtonStart; + + /* + * pButtonHelp + */ + GuiButton* pButtonHelp; + + /* + * pButtonExit + */ + GuiButton* pButtonExit; + +public: + + /* + * Initialize + */ + virtual ErrorCode Initialize(ServiceProvider* pServiceProvider); + + /* + * Terminate + */ + virtual void Terminate(); + + /* + * Update + */ + virtual void Update(float fElapsed); + + /* + * Render + */ + virtual void Render(RenderContext& kContext); +}; + +#endif //__MAINSCREEN_H__
--- a/LightClone/Source/Mediator.cpp Mon Oct 10 09:49:54 2011 -0700 +++ b/LightClone/Source/Mediator.cpp Tue Oct 11 12:09:04 2011 -0700 @@ -18,6 +18,11 @@ Mediator::Mediator() : kWindow(this) { pGraphicsDevice = NULL; + + kScreenManager.Register("Main", &kMainScreen); + kScreenManager.Register("Help", &kHelpScreen); + kScreenManager.Register("Game", &kGameScreen); + kScreenManager.Register("Pause", &kPauseScreen); } /* @@ -32,7 +37,8 @@ kClock.Reset(); - while(kWorld.IsActive()) + //TODO: While screen manager is active + while(true) { ProcessMessages(); @@ -144,12 +150,12 @@ Terminate(); return eCode; - } + } - eCode = kWorld.Initialize(&kServiceProvider); + eCode = kScreenManager.Initialize(&kServiceProvider); if(eCode != Error_Success) { - TRACE("Error: Failed to initialize world\n"); + TRACE("Error: Failed to initialize screen manager\n"); Terminate(); return eCode; @@ -163,7 +169,7 @@ */ void Mediator::Terminate() { - kWorld.Terminate(); + kScreenManager.Terminate(); kInputManager.Terminate(); kResourceManager.Terminate(); kContext.Terminate(); @@ -178,7 +184,6 @@ */ void Mediator::Update(float fElapsed) { - kWorld.Update(fElapsed); } /* @@ -186,7 +191,11 @@ */ void Mediator::Render() { - kWorld.Render(kContext); + const uint32 nColor = D3DCOLOR_XRGB(32, 32, 32); + + kContext.Begin(nColor); + kScreenManager.Render(kContext); + kContext.End(); } /* @@ -200,7 +209,8 @@ { if(kMessage.message == WM_QUIT) { - kWorld.Deactivate(); + //kWorld.Deactivate(); + //TODO: kScreenManager.Deactivate(); break; }
--- a/LightClone/Source/Mediator.h Mon Oct 10 09:49:54 2011 -0700 +++ b/LightClone/Source/Mediator.h Tue Oct 11 12:09:04 2011 -0700 @@ -14,6 +14,11 @@ #include "RenderContext.h" #include "World.h" #include "ServiceProvider.h" +#include "ScreenManager.h" +#include "MainScreen.h" +#include "HelpScreen.h" +#include "PauseScreen.h" +#include "GameScreen.h" /* * Mediator @@ -56,9 +61,29 @@ ServiceProvider kServiceProvider; /* - * kWorld + * kScreenManager + */ + ScreenManager kScreenManager; + + /* + * kMainScreen + */ + MainScreen kMainScreen; + + /* + * kHelpScreen */ - World kWorld; + HelpScreen kHelpScreen; + + /* + * kGameScreen + */ + GameScreen kGameScreen; + + /* + * kPauseScreen + */ + PauseScreen kPauseScreen; public:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/PauseScreen.cpp Tue Oct 11 12:09:04 2011 -0700 @@ -0,0 +1,35 @@ +/* + * PauseScreen + */ + +#include "PauseScreen.h" + +/* + * Initialize + */ +ErrorCode PauseScreen::Initialize(ServiceProvider* pServiceProvider) +{ + return Error_Success; +} + +/* + * Terminate + */ +void PauseScreen::Terminate() +{ + Screen::Terminate(); +} + +/* + * Update + */ +void PauseScreen::Update(float fElapsed) +{ +} + +/* + * Render + */ +void PauseScreen::Render(RenderContext& kContext) +{ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/PauseScreen.h Tue Oct 11 12:09:04 2011 -0700 @@ -0,0 +1,39 @@ +/* + * PauseScreen + */ + +#ifndef __PAUSESCREEN_H__ +#define __PAUSESCREEN_H__ + +#include "Core.h" +#include "Screen.h" + +/* + * PauseScreen + */ +class PauseScreen : public Screen +{ +public: + + /* + * Initialize + */ + virtual ErrorCode Initialize(ServiceProvider* pServiceProvider); + + /* + * Terminate + */ + virtual void Terminate(); + + /* + * Update + */ + virtual void Update(float fElapsed); + + /* + * Render + */ + virtual void Render(RenderContext& kContext); +}; + +#endif //__PAUSESCREEN_H__
--- a/LightClone/Source/Screen.cpp Mon Oct 10 09:49:54 2011 -0700 +++ b/LightClone/Source/Screen.cpp Tue Oct 11 12:09:04 2011 -0700 @@ -14,7 +14,7 @@ /* * Initialize */ -ErrorCode Screen::Initialize() +ErrorCode Screen::Initialize(ServiceProvider* pServiceProvider) { return Error_Success; } @@ -36,6 +36,22 @@ /* * Render */ -void Screen::Render() +void Screen::Render(RenderContext& kContext) { } + +/* + * SetScreenManager + */ +void Screen::SetScreenManager(ScreenManager* pManager) +{ + pScreenManager = pManager; +} + +/* + * GetScreenManager + */ +ScreenManager* Screen::GetScreenManager() +{ + return pScreenManager; +}
--- a/LightClone/Source/Screen.h Mon Oct 10 09:49:54 2011 -0700 +++ b/LightClone/Source/Screen.h Tue Oct 11 12:09:04 2011 -0700 @@ -6,12 +6,24 @@ #define __SCREEN_H__ #include "Core.h" +#include "ServiceProvider.h" +#include "RenderContext.h" + +/* + * ScreenManager + */ +class ScreenManager; /* * Screen */ class Screen { + /* + * pScreenManager + */ + ScreenManager* pScreenManager; + public: /* @@ -22,7 +34,7 @@ /* * Initialize */ - virtual ErrorCode Initialize(); + virtual ErrorCode Initialize(ServiceProvider* pServiceProvider); /* * Terminate @@ -37,7 +49,17 @@ /* * Render */ - virtual void Render(); + virtual void Render(RenderContext& kContext); + + /* + * SetScreenManager + */ + void SetScreenManager(ScreenManager* pManager); + + /* + * GetScreenManager + */ + ScreenManager* GetScreenManager(); }; #endif //__SCREEN_H__
--- a/LightClone/Source/ScreenManager.cpp Mon Oct 10 09:49:54 2011 -0700 +++ b/LightClone/Source/ScreenManager.cpp Tue Oct 11 12:09:04 2011 -0700 @@ -12,9 +12,36 @@ } /* + * Register + */ +ErrorCode ScreenManager::Register(const char* pName, Screen* pInstance) +{ + ErrorCode eCode = Error_Fail; + + if(pInstance) + { + FixedString<> kName(pName); + + Screen** pScreen = kScreens.Find(kName); + if(!pScreen) + pScreen = kScreens.Add(kName); + + if(pScreen) + { + (*pScreen) = pInstance; + (*pScreen)->SetScreenManager(this); + } + + eCode = Error_Success; + } + + return eCode; +} + +/* * Initialize */ -ErrorCode ScreenManager::Initialize() +ErrorCode ScreenManager::Initialize(ServiceProvider* pServiceProvider) { return Error_Success; } @@ -36,6 +63,6 @@ /* * Render */ -void ScreenManager::Render() +void ScreenManager::Render(RenderContext& kContext) { }
--- a/LightClone/Source/ScreenManager.h Mon Oct 10 09:49:54 2011 -0700 +++ b/LightClone/Source/ScreenManager.h Tue Oct 11 12:09:04 2011 -0700 @@ -7,12 +7,36 @@ #include "Core.h" #include "Screen.h" +#include "HashMap.h" +#include "FixedString.h" +#include "FixedStack.h" +#include "RenderContext.h" /* * ScreenManager */ class ScreenManager { + /* + * ScreenMap + */ + typedef HashMap<FixedString<>, Screen*, FixedString<>::Hash> ScreenMap; + + /* + * ScreenStack + */ + typedef FixedStack<Screen*, 32> ScreenStack; + + /* + * kScreens + */ + ScreenMap kScreens; + + /* + * kStack + */ + ScreenStack kStack; + public: /* @@ -21,9 +45,14 @@ ScreenManager(); /* + * Register + */ + ErrorCode Register(const char* pName, Screen* pInstance); + + /* * Initialize */ - ErrorCode Initialize(); + ErrorCode Initialize(ServiceProvider* pServiceProvider); /* * Terminate @@ -38,7 +67,7 @@ /* * Render */ - void Render(); + void Render(RenderContext& kContext); }; #endif //__SCREENMANAGER_H__
--- a/LightClone/Source/World.cpp Mon Oct 10 09:49:54 2011 -0700 +++ b/LightClone/Source/World.cpp Tue Oct 11 12:09:04 2011 -0700 @@ -189,10 +189,6 @@ */ void World::Render(RenderContext& kContext) { - const uint32 nColor = D3DCOLOR_XRGB(32, 32, 32); - - kContext.Begin(nColor); - if(nWorldState == WorldState_Game || nWorldState == WorldState_Confirm) { D3DVIEWPORT9 kOriginal; @@ -201,7 +197,7 @@ D3DVIEWPORT9 kViewport; kViewport.X = 0; kViewport.Y = 0; - kViewport.Width = ScreenSizeX - 280; + kViewport.Width = ScreenSizeX - 280; // minus size of interface kViewport.Height = ScreenSizeY; kViewport.MinZ = kOriginal.MinZ; kViewport.MaxZ = kOriginal.MaxZ; @@ -217,8 +213,6 @@ kCameraController.SetMode(CameraMode_2D); kInterface.Render(kContext, kCameraController); - - kContext.End(); } /* @@ -371,9 +365,6 @@ pDebugText->SetText("Debug"); pDebugText->SetColor(D3DCOLOR_XRGB(255, 255, 255)); - //pHud = new GuiElement(); - //pHud->Add(pBackground); - kInterface.Add(pBackground); kInterface.Add(pDebugText); kInterface.Add(pMessageDialog);
--- a/LightClone/Source/World.h Mon Oct 10 09:49:54 2011 -0700 +++ b/LightClone/Source/World.h Tue Oct 11 12:09:04 2011 -0700 @@ -91,26 +91,6 @@ GuiInterface kInterface; /* - * pMenuMain - */ - GuiElement* pMenuMain; - - /* - * pMenuHelp - */ - GuiElement* pMenuHelp; - - /* - * pMenuPause - */ - GuiElement* pMenuPause; - - /* - * pHud - */ - GuiElement* pHud; - - /* * pBackground */ GuiImage* pBackground;