-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.hh
85 lines (65 loc) · 2.52 KB
/
Game.hh
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include "Controls.hh"
#include "IInputHandler.hh"
#include "IRenderer.hh"
#include "IUiHandler.hh"
#include "RenderState.hh"
#include "Renderer.hh"
#include "RenderingPass.hh"
#include "Screen.hh"
#include <core_utils/CoreObject.hh>
#include <memory>
#include <unordered_map>
namespace pge {
class IRenderer;
using IRendererPtr = std::unique_ptr<IRenderer>;
class IUiHandler;
using IUiHandlerPtr = std::unique_ptr<IUiHandler>;
class IInputHandler;
using IInputHandlerPtr = std::unique_ptr<IInputHandler>;
class Game : public utils::CoreObject
{
public:
Game();
~Game() override = default;
auto getScreen() const noexcept -> Screen;
void setScreen(const Screen &screen);
void generateRenderers(int width, int height, Renderer &engine);
void generateInputHandlers();
void generateUiHandlers(int width, int height, Renderer &engine);
void processUserInput(const controls::State &controls, CoordinateFrame &frame);
void render(const RenderState &state, const RenderingPass pass) const;
/// @brief - Returns whether or not the game has been terminated. The game is
/// terminated when the user wants to exit the app (usually).
bool terminated() const noexcept;
/// @brief - Forward the call to step one step ahead in time to the internal world.
/// @param elapsedSeconds - the duration of the last frame in seconds.
/// @param bool - `true` in case the game continues, and `false` otherwise (i.e. if
/// the game is ended).
bool step(float elapsedSeconds);
void onSavedGameSelected(const std::string &filePath);
private:
/// @brief - Convenience information defining the state of the
/// game. It includes information about whether the menus should
/// be displayed and if the user actions should be interpreted
/// or not.
struct State
{
/// @brief - Defines the current screen selected in this game. Updated whenever
/// the user takes action to change it.
Screen screen{Screen::HOME};
/// @brief - Whether the game was terminated (usually because the app was closed).
bool terminated{false};
};
/// @brief - The definition of the game state.
State m_state{};
std::unordered_map<Screen, IRendererPtr> m_renderers{};
std::unordered_map<Screen, IInputHandlerPtr> m_inputHandlers{};
std::unordered_map<Screen, IUiHandlerPtr> m_uiHandlers{};
/// @brief - Requests the game to be terminated. This is applied to the next
/// iteration of the game loop.
void terminate() noexcept;
void resetUi();
};
using GameShPtr = std::shared_ptr<Game>;
} // namespace pge