Hummingbird Framework
 All Classes Functions Variables Modules Pages
Game.h
1 #ifndef HB_GAME_H
2 #define HB_GAME_H
3 #include <functional>
4 #include <string>
5 #include <vector>
6 #include <map>
7 #include "GameObject.h"
8 #include "Clock.h"
9 #include "Plugin.h"
10 #include "Log.h"
11 
12 namespace hb
13 {
23  class Game
24  {
25  public:
34  class Scene
35  {
36  public:
42  Scene(const std::string& name, std::function<void(void)>&& init);
47  Scene(const Scene& other);
52  Scene(Scene&& other);
56  ~Scene();
57 
61  void init();
66  void exit();
70  const std::string& getName() const;
74  void setExit(std::function<void(void)>&& exit);
75 
76  protected:
77  std::function<void(void)> m_init, m_exit;
78  std::string m_name;
79  };
80 
81  ~Game();
86  static void addScene(Scene& scene);
91  static void addScene(Scene&& scene);
102  static void setScene(const std::string& name);
109  static void run();
117  static void running(bool running);
122  static bool isRunning();
129  template<typename T>
130  static void addPlugin()
131  {
132  T* t = new T();
133  s_plugins.push_back(t);
134  }
135 
136 
137  private:
138  Game();
139  static void changeScene();
140 
141  static bool s_game_running, s_change_scene;
142  static std::map<std::string, Scene>::iterator s_current_scene, s_next_scene;
143  static std::map<std::string, Scene> s_scenes;
144  static std::vector<Plugin*> s_plugins;
145  };
146 }
147 #endif
Game class.
Definition: Game.h:23
static void addScene(Scene &scene)
Add a Scene to the Game.
static void setScene(const std::string &name)
Set Scene with name name as the current Scene.
static bool isRunning()
Get if the Game is running.
Scene(const std::string &name, std::function< void(void)> &&init)
Class constructor.
Scene of a Game.
Definition: Game.h:34
static void addPlugin()
Add Plugin to the Game.
Definition: Game.h:130
void exit()
Called when Scene is being unset (Game is changing the current Scene or Game is ending).
const std::string & getName() const
Get Scene's name.
static void running(bool running)
Set if the Game is running.
Definition: Box2DPlugin.h:6
void init()
Called when Scene is being set.
void setExit(std::function< void(void)> &&exit)
Set Scene's exit function.
~Scene()
Class destructor.
static void run()
Run the Game.