ST_engine  0.3-ALPHA
game_manager.hpp
1 /* This file is part of the "ST" project.
2  * You may use, distribute or modify this code under the terms
3  * of the GNU General Public License version 2.
4  * See LICENCE.txt in the root directory of the project.
5  *
6  * Author: Maxim Atanasov
7  * E-mail: maxim.atanasov@protonmail.com
8  */
9 
10 #ifndef ST_GAME_MANAGER_DEF
11 #define ST_GAME_MANAGER_DEF
12 
13 #include <game_manager/level/level.hpp>
14 #include <message_bus.hpp>
15 #include <game_manager/lua_backend/lua_backend.hpp>
16 #include <task_manager.hpp>
17 #include <bitset>
18 
20 class game_manager {
21 private:
22 
23  std::vector<ST::level> levels{};
24  std::string active_level{};
25  ST::level *current_level_pointer{};
26  subscriber msg_sub{};
27  std::atomic_bool game_is_running_{};
28  lua_backend gScript_backend{};
29  message_bus &gMessage_bus;
30  task_manager *gTask_manager{};
31  std::bitset<256> keys_pressed_data{};
32  std::bitset<256> keys_held_data{};
33  std::bitset<256> keys_released_data{};
34  int32_t mouse_x = 0;
35  int32_t mouse_y = 0;
36  int16_t left_trigger{};
37  int16_t right_trigger{};
38  int16_t left_stick_horizontal{};
39  int16_t left_stick_vertical{};
40  int16_t right_stick_vertical{};
41  int16_t right_stick_horizontal{};
42 
43  //Virtual screen size
44  uint16_t v_width = 1920;
45  uint16_t v_height = 1080;
46 
47  //Window screen size
48  uint16_t w_width = 1920;
49  uint16_t w_height = 1080;
50 
51  //methods
52  void handle_messages();
53 
54  int8_t load_level(const std::string &);
55 
56  void unload_level(const std::string &);
57 
58  void reload_level(const std::string &);
59 
60  void start_level(const std::string &);
61 
62  void reset_keys();
63 
64  void run_level_loop();
65 
66 public:
67  bool vsync_flag = true;
68  bool fullscreen_status = false;
69  uint8_t music_volume_level = 100;
70  uint8_t sounds_volume_level = 100;
71  bool audio_enabled = true;
72  int8_t gravity = 0;
73 
74  explicit game_manager(message_bus &msg_bus);
75 
76  ~game_manager();
77 
78  [[nodiscard]] std::string get_active_level() const;
79 
80  [[nodiscard]] bool key_pressed(uint16_t arg) const;
81 
82  [[nodiscard]] bool key_held(uint16_t arg) const;
83 
84  [[nodiscard]] bool key_released(uint16_t arg) const;
85 
86  [[nodiscard]] int32_t get_mouse_x() const;
87 
88  [[nodiscard]] int32_t get_mouse_y() const;
89 
90  [[nodiscard]] int16_t get_left_trigger() const;
91 
92  [[nodiscard]] int16_t get_right_trigger() const;
93 
94  [[nodiscard]] int16_t get_left_stick_horizontal() const;
95 
96  [[nodiscard]] int16_t get_left_stick_vertical() const;
97 
98  [[nodiscard]] int16_t get_right_stick_vertical() const;
99 
100  [[nodiscard]] int16_t get_right_stick_horizontal() const;
101 
102  void update();
103 
104  [[nodiscard]] bool game_is_running() const;
105 
106  [[nodiscard]] ST::level *get_level() const;
107 
108  void center_camera_on_entity(uint64_t id);
109 
110  uint16_t get_window_width() const;
111 
112  uint16_t get_window_height() const;
113 
114  uint16_t get_internal_width() const;
115 
116  uint16_t get_internal_height() const;
117 
118  void save_state(const std::string &filepath);
119 };
120 
121 #endif /*ST_GAME_MANAGER_DEF*/
This object contains all the data for a level and provides functions for loading and unloading a leve...
Definition: level.hpp:29
This class is responsible for managing all levels and the lua backend, it is the heart of the engine.
bool key_released(uint16_t arg) const
uint16_t get_internal_width() const
void center_camera_on_entity(uint64_t id)
uint16_t get_window_height() const
int16_t get_left_stick_vertical() const
bool key_held(uint16_t arg) const
int16_t get_left_trigger() const
int32_t get_mouse_x() const
int16_t get_right_stick_vertical() const
int16_t get_left_stick_horizontal() const
ST::level * get_level() const
uint16_t get_window_width() const
bool game_is_running() const
uint16_t get_internal_height() const
int32_t get_mouse_y() const
bool key_pressed(uint16_t arg) const
int16_t get_right_trigger() const
game_manager(message_bus &msg_bus)
int16_t get_right_stick_horizontal() const
std::string get_active_level() const
This class handles all interaction with lua.
Definition: lua_backend.hpp:31
The central messaging system of the engine. All subsystem make extensive use of it.
Definition: message_bus.hpp:29
This class handles a small queue for messages.
Definition: subscriber.hpp:20
The Task Manager handles all things multi-threaded in the engine.