From c18ed560119fc38cadc8a6bfa4b544b4e79b852a Mon Sep 17 00:00:00 2001 From: gered Date: Tue, 2 Apr 2013 12:14:09 -0400 Subject: [PATCH] some minor cleanups and new asserts --- src/states/gamestate.cpp | 5 +-- src/states/gamestate.h | 14 ++++----- src/states/gwengamestate.cpp | 2 +- src/states/gwengamestate.h | 2 +- src/states/gwengamestateuicontroller.cpp | 2 ++ src/states/gwengamestateuicontroller.h | 8 ++--- src/states/stateinfo.h | 2 +- src/states/statemanager.cpp | 1 + src/states/statemanager.h | 39 +++++++++++++++++++----- 9 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/states/gamestate.cpp b/src/states/gamestate.cpp index 4b425f5..56eb611 100644 --- a/src/states/gamestate.cpp +++ b/src/states/gamestate.cpp @@ -11,13 +11,14 @@ GameState::GameState(GameApp *gameApp, StateManager *stateManager) : EventListenerEx(gameApp->GetEventManager()) { STACK_TRACE; + ASSERT(gameApp != NULL); + ASSERT(stateManager != NULL); + m_gameApp = gameApp; m_stateManager = stateManager; m_effectManager = new EffectManager(); - ASSERT(m_effectManager != NULL); m_processManager = new ProcessManager(this); - ASSERT(m_processManager != NULL); m_isFinished = FALSE; m_returnValue = 0; diff --git a/src/states/gamestate.h b/src/states/gamestate.h index d976eac..be25b61 100644 --- a/src/states/gamestate.h +++ b/src/states/gamestate.h @@ -43,18 +43,18 @@ public: template T* As(); template const T* As() const; - GameApp* GetGameApp() const { return m_gameApp; } - ProcessManager* GetProcessManager() const { return m_processManager; } - EffectManager* GetEffectManager() const { return m_effectManager; } + GameApp* GetGameApp() const { return m_gameApp; } + ProcessManager* GetProcessManager() const { return m_processManager; } + EffectManager* GetEffectManager() const { return m_effectManager; } BOOL IsTransitioning() const; BOOL IsTopState() const; - BOOL IsFinished() const { return m_isFinished; } - BOOL HasReturnValue() const { return m_hasReturnValue; } - uint32_t GetReturnValue() const { return m_returnValue; } + BOOL IsFinished() const { return m_isFinished; } + BOOL HasReturnValue() const { return m_hasReturnValue; } + uint32_t GetReturnValue() const { return m_returnValue; } protected: - StateManager* GetStateManager() const { return m_stateManager; } + StateManager* GetStateManager() const { return m_stateManager; } void SetFinished(); void SetFinished(uint32_t returnValue); diff --git a/src/states/gwengamestate.cpp b/src/states/gwengamestate.cpp index 4f913c2..a2e1dab 100644 --- a/src/states/gwengamestate.cpp +++ b/src/states/gwengamestate.cpp @@ -4,7 +4,7 @@ #include "gwengamestateuicontroller.h" GwenGameState::GwenGameState(GameApp *gameApp, StateManager *stateManager) -: GameState(gameApp, stateManager) + : GameState(gameApp, stateManager) { STACK_TRACE; m_gwenController = NULL; diff --git a/src/states/gwengamestate.h b/src/states/gwengamestate.h index f661629..5568f8f 100644 --- a/src/states/gwengamestate.h +++ b/src/states/gwengamestate.h @@ -19,7 +19,7 @@ public: static GAMESTATE_TYPE typeName = "GwenGameState"; return typeName; } - GAMESTATE_TYPE GetTypeOf() const { return GetType(); } + GAMESTATE_TYPE GetTypeOf() const { return GetType(); } GwenGameState(GameApp *gameApp, StateManager *stateManager); virtual ~GwenGameState(); diff --git a/src/states/gwengamestateuicontroller.cpp b/src/states/gwengamestateuicontroller.cpp index cf433e6..802b604 100644 --- a/src/states/gwengamestateuicontroller.cpp +++ b/src/states/gwengamestateuicontroller.cpp @@ -14,6 +14,8 @@ GwenGameStateUIController::GwenGameStateUIController(GwenGameState *gameState) { STACK_TRACE; + ASSERT(gameState != NULL); + m_gameState = gameState; m_canvas = NULL; m_inputProcessor = NULL; diff --git a/src/states/gwengamestateuicontroller.h b/src/states/gwengamestateuicontroller.h index adf5209..15643ab 100644 --- a/src/states/gwengamestateuicontroller.h +++ b/src/states/gwengamestateuicontroller.h @@ -58,13 +58,13 @@ protected: Gwen::Controls::Canvas* InitializeGwen(const stl::string &skinFilename, const stl::string &fontFilename, uint8_t fontSize); void ResizeAndScaleCanvas(); - GwenGameState* GetGameState() const { return m_gameState; } - Gwen::Controls::Canvas* GetCanvas() const { return m_canvas; } + GwenGameState* GetGameState() const { return m_gameState; } + Gwen::Controls::Canvas* GetCanvas() const { return m_canvas; } void EnableGwenInput(BOOL enable); - float GetAlpha() const { return m_alpha; } - float GetScale() const { return m_scale; } + float GetAlpha() const { return m_alpha; } + float GetScale() const { return m_scale; } void SetAlpha(float alpha); void SetScale(float scale); diff --git a/src/states/stateinfo.h b/src/states/stateinfo.h index 085761e..adeb61d 100644 --- a/src/states/stateinfo.h +++ b/src/states/stateinfo.h @@ -21,7 +21,7 @@ struct StateInfo BOOL isInactive; BOOL isBeingPopped; - const stl::string& GetDescriptor() const { return m_descriptor; } + const stl::string& GetDescriptor() const { return m_descriptor; } private: void SetDescriptor(); diff --git a/src/states/statemanager.cpp b/src/states/statemanager.cpp index 61b2120..09984d3 100644 --- a/src/states/statemanager.cpp +++ b/src/states/statemanager.cpp @@ -13,6 +13,7 @@ StateManager::StateManager(GameApp *gameApp) { STACK_TRACE; + ASSERT(gameApp != NULL); m_gameApp = gameApp; m_stateReturnValue = 0; m_hasStateReturnValue = FALSE; diff --git a/src/states/statemanager.h b/src/states/statemanager.h index bfb46df..55f09dc 100644 --- a/src/states/statemanager.h +++ b/src/states/statemanager.h @@ -43,15 +43,15 @@ public: void OnUpdate(float delta); BOOL IsTransitioning() const; - BOOL IsEmpty() const { return (m_states.empty() && m_pushQueue.empty() && m_swapQueue.empty()); } - BOOL IsTop(const GameState *state) const { return GetTop()->gameState == state; } - BOOL IsTransitioning(const GameState *state) const { return GetStateInfoFor(state)->isTransitioning; } + BOOL IsEmpty() const; + BOOL IsTop(const GameState *state) const; + BOOL IsTransitioning(const GameState *state) const; - GameState* GetTopState() const { return GetTop()->gameState; } - GameState* GetTopNonOverlayState() const { return GetTopNonOverlay()->gameState; } + GameState* GetTopState() const; + GameState* GetTopNonOverlayState() const; - uint32_t GetLastReturnValue() const { return m_stateReturnValue; } - BOOL HasLastReturnValue() const { return m_hasStateReturnValue; } + uint32_t GetLastReturnValue() const { return m_stateReturnValue; } + BOOL HasLastReturnValue() const { return m_hasStateReturnValue; } private: void QueueForPush(StateInfo *newStateInfo); @@ -151,6 +151,31 @@ T* StateManager::SwapTopNonOverlayWith(const stl::string &name) return newState; } +inline BOOL StateManager::IsEmpty() const +{ + return (m_states.empty() && m_pushQueue.empty() && m_swapQueue.empty()); +} + +inline BOOL StateManager::IsTop(const GameState *state) const +{ + return GetTop()->gameState == state; +} + +inline BOOL StateManager::IsTransitioning(const GameState *state) const +{ + return GetStateInfoFor(state)->isTransitioning; +} + +inline GameState* StateManager::GetTopState() const +{ + return GetTop()->gameState; +} + +inline GameState* StateManager::GetTopNonOverlayState() const +{ + return GetTopNonOverlay()->gameState; +} + inline StateInfo* StateManager::GetTop() const { if (m_states.empty())