Guest

GameManager.h

By: a guest on Feb 27th, 2010  |  syntax: C++  |  size: 1.90 KB  |  hits: 439  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1.  
  2. #ifndef GAMEMANAGER_H
  3. #define GAMEMANAGER_H
  4.  
  5.  
  6. //------------------------------------------------------------------------
  7. //
  8. //  Name:   GameManager.h
  9. //
  10. //  Desc:   Manages the game states.
  11. //
  12. //  Author: Nikko Bertoa 2010 (nicobertoa@gmail.com)
  13. //
  14. //------------------------------------------------------------------------
  15.  
  16.  
  17. //
  18. // Headers
  19. //
  20. #include "ImageManager.hpp"
  21. #include "Fps.h"
  22.  
  23.  
  24. // Forward
  25. class State;
  26.  
  27.  
  28. class GameManager
  29. {
  30.  
  31. public:
  32.  
  33.     GameManager();
  34.  
  35.     virtual ~GameManager();
  36.  
  37.     //use these methods to initialize the machine
  38.     void SetCurrentState(State* s) { m_pCurrentState = s; }
  39.     State* CurrentState()const { return m_pCurrentState; }
  40.     void SetGlobalState(State* s) { m_pGlobalState = s; }
  41.     State* GlobalState()const { return m_pGlobalState; }
  42.     void SetPreviousState(State* s) { m_pPreviousState = s; }
  43.     State* PreviousState()const { return m_pPreviousState; }
  44.  
  45.     void Run();
  46.  
  47.     void Exit();
  48.  
  49.     //change to a new state
  50.     void  ChangeState(State* pNewState);
  51.  
  52.     //change state back to the previous state
  53.     void  RevertToPreviousState() { ChangeState(m_pPreviousState); }
  54.  
  55.     //returns true if the current state's type is equal to the type of the
  56.     //class passed as a parameter.
  57.     // m_pCurrentState's entity_type == st's entity_type
  58.     bool  IsInState(const State* st)const { return typeid(*m_pCurrentState) == typeid(st); }
  59.  
  60.  
  61. private:
  62.  
  63.     //call this to update the machine
  64.     void  Update();
  65.     void DrawFPS();
  66.  
  67.     State* m_pCurrentState;
  68.  
  69.     //a record of the last state the agent was in
  70.     State* m_pPreviousState;
  71.  
  72.     //this is called every time the FSM is updated
  73.     State* m_pGlobalState;
  74.  
  75.     sftools::ImageManager m_imgManager;
  76.  
  77.     sf::RenderWindow m_screen;
  78.  
  79.     Fps m_fpsManager;
  80.     sf::Font* m_font;
  81.     sf::String* m_fpsText;
  82.  
  83.     bool m_close;
  84.  
  85. };
  86.  
  87.  
  88. #endif // GAMEMANAGER_H