#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_GAME_STATES_DEFAULTGAMESTATEMANAGER_H #define NUCLEX_GAME_STATES_DEFAULTGAMESTATEMANAGER_H #include #include #include "GameStateManager.h" #include "../Drawable.h" #include "../Updateable.h" namespace Nuclex { namespace Game { namespace States { // ------------------------------------------------------------------------------------------- // /// Stacked game state manager that forwards Draw() and Update() calls /// /// /// This game state manager will call the Updateable.Update() and Drawable.Draw() methods /// when any of those interfaces are implemented by the game states pushed onto its stack. /// /// /// To figure out whether a game state implements these interfaces, a dynamic_cast will be /// performed during the Push() call. All active updateables and drawables are then kept /// in separate list, allowing very cheap frame-by-frame processing. /// /// class DefaultGameStateManager : public GameStateManager, public virtual Drawable, public virtual Updateable { /// Stores a game state and the modality it was activated with private: typedef std::pair, Modality::Enum> GameStateModalityPair; /// Initializes a new game state manager public: NUCLEX_GAME_API DefaultGameStateManager(); /// /// Destroys the game state manager, leaving and dropping any active game state /// public: NUCLEX_GAME_API virtual ~DefaultGameStateManager(); /// Returns the currently active game state /// The lastmost game state on the stack public: NUCLEX_GAME_API virtual std::shared_ptr Peek() const; /// Appends a new game state to the stack /// Game state that will be pushed onto the stack /// Whether the state completely obscures the state below it public: NUCLEX_GAME_API virtual void Push( const std::shared_ptr &state, Modality::Enum modality = Modality::Exclusive ); /// Removes the lastmost game state from the stack /// The state that has been removed from the stack public: NUCLEX_GAME_API virtual std::shared_ptr Pop(); /// Advances the time of the active game states /// Provides the elapsed real world and simulation time public: NUCLEX_GAME_API void Update(const GameTime &gameTime); /// /// Instructs the active game states to render themselves or to update the scene graph /// /// Provides the elapsed real world and simulation time public: NUCLEX_GAME_API void Draw(const GameTime &gameTime); /// /// Adds the specified game state to the exposed Drawables or Updateables if it /// implements the Drawable or Updateable interfaces /// /// /// State that will be checked for implementing the Drawable or Updateable interfaces /// private: void addToDrawablesOrUpdateables(GameState *gameState); /// /// Removes the specified game state to the exposed Drawables or Updateables if it /// implements the Drawable or Updateable interfaces /// /// /// State that will be checked for implementing the Drawable or Updateable interfaces /// private: void removeFromDrawablesOrUpdateables(GameState *gameState); /// /// Rebuilds the separate updateable and drawable queues when an Hiding state has /// been popped from the stack /// private: void rebuildUpdateableAndDrawableQueues(); /// Notifies all previously exposed states that they have been hidden private: void notifyHiddenStates(); /// Notifies all currently exposed states that they have been revealed private: void notifyRevealedStates(); /// Stores the currently active game states private: std::vector activeStates; /// All drawable game states from the last Hiding state private: std::vector exposedDrawables; /// All updateable game states from the last Hiding state private: std::vector exposedUpdateables; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Game::States #endif // NUCLEX_GAME_STATES_DEFAULTGAMESTATEMANAGER_H