-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.h
More file actions
122 lines (112 loc) · 3.78 KB
/
Copy pathgame.h
File metadata and controls
122 lines (112 loc) · 3.78 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef __GAME_GAME_H
#define __GAME_GAME_H
#define GAME_GETTER(t, n) \
t get_##n() const { return this->n; }
#include "controllers/battle_controller.h"
#include "controllers/dungeon_controller.h"
#include "controllers/menu_controller.h"
#include "controllers/overworld_controller.h"
#include "entities/entity.h"
#include "entities/entity_manager.h"
#include "entities/player.h"
#include "level.h"
#include "lua/entity.h"
#include "lua/helpers.h"
#include "lua/text.h"
#include "text.h"
#include <engine/input/input.h>
#include <engine/limits.h>
#include <engine/platform.h>
#include <engine/render/glyph.h>
#include <engine/render/renderable.h>
#include <engine/state/state.h>
#include <engine/types/numeric.h>
#include <lua.hpp>
#include <memory>
#include <vector>
enum GameStage { GS_MENU, GS_OVERWORLD, GS_DUNGEON, GS_BATTLE, GS_UNKNOWN };
class Game {
private:
EntityManager ent_manager;
Text text[MAX_TEXT_OBJECTS];
std::shared_ptr<Level> level;
GameState *game_state;
InputState *input_state;
lua_State *lua;
OverworldController *overworld_controller;
DungeonController *dungeon_controller;
BattleController *battle_controller;
MenuController *menu_controller;
Entity *background;
GameStage stage;
f32 window_width;
f32 window_height;
f32 window_scale_x;
f32 window_scale_y;
f32 scale;
bool locked;
bool should_clear_text;
public:
Game() {
this->input_state = nullptr;
this->game_state = nullptr;
this->overworld_controller = nullptr;
this->dungeon_controller = nullptr;
this->battle_controller = nullptr;
this->menu_controller = nullptr;
this->scale = RENDER_SCALE;
this->stage = GameStage::GS_UNKNOWN;
this->locked = false;
this->should_clear_text = false;
this->window_width = 1280.0f;
this->window_height = 720.0f;
this->window_scale_x = 1.0f;
this->window_scale_y = 1.0f;
}
GAME_GETTER(InputState *, input_state);
GAME_GETTER(GameStage, stage);
GAME_GETTER(f32, scale);
GAME_GETTER(f32, window_width);
GAME_GETTER(f32, window_height);
GAME_GETTER(f32, window_scale_x);
GAME_GETTER(f32, window_scale_y);
/* Events called from the engine */
void init(GameState *state);
void update(GameState *state, mutex_t *lock);
void update_lazy(GameState *state, mutex_t *lock);
void update_paused(GameState *state, mutex_t *lock);
void update_renderables(
GameState *state,
mutex_t *lock,
RenderState *render_state,
Renderable **renderables,
const u32 renderables_count,
GlyphText *text_objects,
const u32 text_objects_count
);
void create_bindings(GameState *state, mutex_t *lock, InputState *input_state);
void process_input(GameState *state, const f64 update_time);
void set_stage(const GameStage stage);
void init_lua();
void ent_remove(Entity *ent);
void clear_entities();
void changelevel(const std::string level);
Text *add_text(const std::string text, const Vector4 pos, const Vector4 color, const Vector2 scale);
void clear_text();
static bool compare_renderables(const Renderable *r1, const Renderable *r2);
static i32 lua_set_stage(lua_State *state);
static i32 lua_bind(lua_State *state);
static i32 lua_get_stage(lua_State *state);
static i32 lua_player(lua_State *state);
static i32 lua_getscale(lua_State *state);
static i32 lua_ent_create(lua_State *state);
static i32 lua_ent_clear(lua_State *state);
static i32 lua_ent_remove(lua_State *state);
static i32 lua_changelevel(lua_State *state);
static i32 lua_window_getheight(lua_State *state);
static i32 lua_window_getwidth(lua_State *state);
static i32 lua_window_getscale(lua_State *state);
static i32 lua_add_text(lua_State *state);
static i32 lua_clear_text(lua_State *state);
};
#endif