Dragonfly  4.4
A text-based game engine
GameManager.h
1 ///
2 /// The game manager
3 ///
4 
5 #ifndef __GAME_MANAGER_H__
6 #define __GAME_MANAGER_H__
7 
8 #include "Manager.h"
9 
10 #define DF_VERSION 4.4 /// Dragonfly version
11 
12 // Two-letter acronym for easier access to manager.
13 #define GM df::GameManager::getInstance()
14 
15 namespace df {
16 
17 /// Default Dragonfly cofiguration file.
18 /// Override with DRAGONFLY_CONFIG environment variable.
19 const std::string CONFIG_FILENAME = "df-config.txt";
20 
21 /// Default frame time (game loop time) in milliseconds (33 ms == 30 f/s).
22 const int FRAME_TIME_DEFAULT = 33;
23 
24 class GameManager : public Manager {
25 
26  private:
27  GameManager(); ///< Private since a singleton.
28  GameManager(GameManager const&); ///< Don't allow copy.
29  void operator=(GameManager const&); ///< Don't allow assignment.
30  bool m_game_over; ///< True -> game loop should stop.
31  int m_frame_time; ///< Target time per game loop, in millisec.
32  int m_step_count; ///< Count of game loop iterations.
33 
34  public:
35  /// Get the singleton instance of the GameManager.
36  static GameManager &getInstance();
37 
38  /// Startup all GameManager services.
39  int startUp();
40 
41  /// Game manager only accepts step events.
42  /// Return false if other event.
43  bool isValid(std::string event_name) const;
44 
45  /// Shut down GameManager services.
46  void shutDown();
47 
48  /// Run game loop.
49  void run();
50 
51  /// Set game over status to indicated value.
52  /// If true (default), will stop game loop.
53  void setGameOver(bool game_over=true);
54 
55  /// Get game over status.
56  bool getGameOver() const;
57 
58  /// Return frame time.
59  /// Frame time is target time for each game loop, in milliseconds.
60  int getFrameTime() const;
61 
62  /// Return game loop step count.
63  int getStepCount() const;
64 };
65 
66 } // end of namespace df
67 #endif // __GAME_MANAGER_H__
bool m_game_over
True -> game loop should stop.
Definition: GameManager.h:30
GameManager()
Private since a singleton.
int startUp()
Startup all GameManager services.
void operator=(GameManager const &)
Don&#39;t allow assignment.
void setGameOver(bool game_over=true)
Set game over status to indicated value.
static GameManager & getInstance()
Get the singleton instance of the GameManager.
const std::string CONFIG_FILENAME
Default Dragonfly cofiguration file.
Definition: GameManager.h:19
A 2-d bounding box.
Definition: Box.h:10
void shutDown()
Shut down GameManager services.
void run()
Run game loop.
int m_step_count
Count of game loop iterations.
Definition: GameManager.h:32
bool getGameOver() const
Get game over status.
const int FRAME_TIME_DEFAULT
Default frame time (game loop time) in milliseconds (33 ms == 30 f/s).
Definition: GameManager.h:22
Definition: GameManager.h:24
int m_frame_time
Target time per game loop, in millisec.
Definition: GameManager.h:31
int getStepCount() const
Return game loop step count.
int getFrameTime() const
Return frame time.
Definition: Manager.h:20
bool isValid(std::string event_name) const
Game manager only accepts step events.