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