ST_engine  0.3-ALPHA
drawing_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 DRAWING_DEF
11 #define DRAWING_DEF
12 
13 #include <game_manager/level/light.hpp>
14 #include <message_bus.hpp>
15 #include <game_manager/level/camera.hpp>
16 #include <renderer_sdl.hpp>
17 #include <game_manager/level/level.hpp>
18 #include <console.hpp>
19 #include "main/metrics.hpp"
20 
21 
22 #define DEFAULT_FONT_NORMAL "OpenSans-Regular.ttf 40"
23 #define DEFAULT_FONT_SMALL "OpenSans-Regular.ttf 25"
24 
27 private:
28  //external dependency - delivered in the constructor
29  message_bus &gMessage_bus;
30 
31  //a subscriber object - so we can subscribe to and recieve messages
32  subscriber msg_sub{};
33 
34  //CPU ticks since start - used for animating sprites
35  uint32_t ticks = 0;
36 
37  //Basically the viewport
38  ST::camera camera{};
39 
40  //Internal rendering resolution
41  uint16_t w_width = 1920;
42  uint16_t w_height = 1080;
43 
44  //variables for drawing light
45  uint8_t lightmap[1920][1080]{};
46  uint8_t darkness_level = 0;
47  uint8_t lights_quality = 0;
48 
49  uint16_t default_font_normal = 0;
50  uint16_t default_font_small = 0;
51 
52  //debug
53  bool collisions_shown = false;
54  bool show_fps = true;
55  bool lighting_enabled = false;
56  bool metrics_shown = false;
57 
58  //Drawing functions
59  void draw_entities(const std::vector<ST::entity> &) const;
60 
61  void draw_collisions(const std::vector<ST::entity> &) const;
62 
63  void draw_coordinates(const std::vector<ST::entity> &) const;
64 
65  void draw_lights() const;
66 
67  void draw_fps(float fps) const;
68 
69  void draw_console(console &console) const;
70 
71  void draw_text_objects(const std::vector<ST::text> &) const;
72 
73  void draw_background(const uint16_t background[PARALLAX_BG_LAYERS],
74  const uint8_t parallax_speed[PARALLAX_BG_LAYERS]) const;
75 
76  void draw_metrics(ST::metrics metrics, const ST::level &level, const std::vector<ST::entity> &entities) const;
77 
78  //Pre-processing
79  void process_lights(const std::vector<ST::light> &arg);
80 
81  [[nodiscard]] bool is_onscreen(const ST::entity &i) const;
82 
83  [[nodiscard]] bool is_onscreen(const ST::text &i) const;
84 
85  //Other functions
86  void handle_messages();
87 
88  void set_darkness(uint8_t arg);
89 
90 
91 public:
92  drawing_manager(SDL_Window *window, message_bus &gMessageBus);
93 
95 
96  void update(const ST::level &temp, float fps, console &gConsole, ST::metrics metrics);
97 
98 
99 };
100 
101 #endif
This class represents all static or dynamic objects in the game (excluding text, see ST::text)
Definition: entity.hpp:24
This object contains all the data for a level and provides functions for loading and unloading a leve...
Definition: level.hpp:29
This object represents the console window.
Definition: console.hpp:17
This object is responsible for issuing drawing commands and drawing the current level.
drawing_manager(SDL_Window *window, message_bus &gMessageBus)
void update(const ST::level &temp, float fps, console &gConsole, ST::metrics metrics)
An fps counter.
Definition: fps.hpp:21
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 camera object - represents the viewport for the game.
Definition: camera.hpp:16
This struct represents text objects in the game.
Definition: text.hpp:23