/
GameBase.hpp
63 lines (46 loc) · 1.56 KB
/
GameBase.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef GAMEBASE_HPP
#define GAMEBASE_HPP
#include <map>
#include <memory>
#include <SFML/Graphics/RenderWindow.hpp>
#include <string>
#include <type_traits>
#include "Options.hpp"
#include "res/Manager.hpp"
#include "SceneChangeEvent.hpp"
class Game;
class Scene;
// Sub-class it and override initialize() to add scenes, and maybe window.setTitle( "YOUR_GAME" )
class GameBase : public res::Manager
{
public:
GameBase( unsigned int theUpdateRate, unsigned int theRenderRate );
virtual ~GameBase();
void run();
void close();
template< class SCENE, typename... PARAMS >
typename std::enable_if< std::is_base_of< Scene, SCENE >::value, void >::type
changeScenes( const PARAMS&... params );
template< class SCENE, typename... PARAMS >
typename std::enable_if< std::is_base_of< Scene, SCENE >::value, void >::type
changeScenes( const SceneChangeEvent& event, const PARAMS&... params );
unsigned int getUpdateRate() const;
unsigned int getRenderRate() const;
sf::RenderWindow& getWindow();
const sf::RenderWindow& getWindow() const;
Options options;
protected:
sf::RenderWindow window;
virtual void initialize();
virtual void terminate();
void addScene( const std::string& name, std::shared_ptr< Scene > scene );
private:
const unsigned int updateRate;
const unsigned int renderRate;
bool isRunning;
std::shared_ptr< Scene > currentScene; // I'd use unique, but then moving from next -> current would be an issue
std::shared_ptr< Scene > nextScene;
Game* getGame();
};
#include "GameBase.inl"
#endif // GAMEBASE_HPP