-
Notifications
You must be signed in to change notification settings - Fork 1
/
Engine.h
85 lines (64 loc) · 1.78 KB
/
Engine.h
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
#pragma once
/*
The class that handles all the states and their changes
It also handles views for textbox, inventory and minimap
*/
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include "Inventory.h"
#include <stack>
#include <queue>
class Scene;
class Engine
{
public:
Engine() {}
Engine(sf::RenderWindow * app, double gameWidth, double gameHeight);
~Engine();
sf::RenderWindow* app;
double width;
double height;
double fullWidth;
double fullHeight;
Inventory inv;
bool mute = false;
// view management
sf::View gameView;
// reset the views before using them (viewport is already set)
// the flags whether the view is drawn
sf::View textBox;
bool textBoxOn = false;
sf::View inventory;
bool inventoryOn = false;
sf::View miniMap;
bool miniMapOn = false;
sf::View fullScreen;
void Init(sf::RenderWindow * app, double gameWidth, double gameHeight);
void Cleanup();
void Pause();
void Resume();
//calls the present scene's version of the same functions
void HandleEvents(sf::Event* event);
void Update(double dt);
void Draw();
//queues control commands to be called by handleChange()
void changeScene(Scene* newScene);
void pushScene(Scene* newScene);
void popScene();
//called at the beginning of frame (loop iteration) to handle Scene change
void handleChange();
bool running() { return app->isOpen(); }
void close() { app->close(); }
private:
std::stack <Scene*> _scenes;
enum StateControl { change, push, pop };
std::queue <Scene*> _sceneQ;
std::queue <StateControl> _sceneControlQ;
//control functions called called by handleChange()
void _changeScene(Scene* newScene);
void _pushScene(Scene* newScene);
void _popScene();
};
// usefull macros for inventory
#define INVI(x) (game->inv.intVal[x])
#define INVD(x) (game->inv.doubleVal[x])