|
7 | 7 | #include "ui/button.hpp"
|
8 | 8 | #include <future>
|
9 | 9 | #include <mutex>
|
| 10 | +#include <unordered_map> |
10 | 11 | #ifndef VK_EXT_DEBUG_REPORT_EXTENSION_NAME
|
11 | 12 | #define VK_EXT_DEBUG_REPORT_EXTENSION_NAME "VK_EXT_debug_report"
|
12 | 13 | #endif
|
@@ -61,7 +62,7 @@ const std::vector<const char *> requiredInstanceExtensions = {
|
61 | 62 |
|
62 | 63 | const std::vector<const char *> requiredLayerExtensions {
|
63 | 64 | #if DEBUG
|
64 |
| -// "VK_LAYER_KHRONOS_validation", |
| 65 | +// "VK_LAYER_KHRONOS_validation", |
65 | 66 | #endif
|
66 | 67 | };
|
67 | 68 |
|
@@ -90,14 +91,15 @@ struct UIArrowsUBO {
|
90 | 91 | glm::vec3 Color;
|
91 | 92 | };
|
92 | 93 |
|
| 94 | +/* Got a weird bug with floats and found out it was because I didn't put alignas(16), I am now extremely paranoid and will put this in every single UBO with a vec2/float. */ |
93 | 95 | struct UIPanelUBO {
|
94 |
| - glm::vec4 Dimensions; |
95 |
| - float Depth; |
| 96 | +alignas(16) glm::vec4 Dimensions; |
| 97 | +alignas(16) float Depth; |
96 | 98 | };
|
97 | 99 |
|
98 | 100 | struct UILabelPositionUBO {
|
99 |
| - glm::vec2 PositionOffset; |
100 |
| - float Depth; |
| 101 | +alignas(16) glm::vec2 PositionOffset; |
| 102 | +alignas(16) float Depth; |
101 | 103 | };
|
102 | 104 |
|
103 | 105 | struct RenderModel {
|
@@ -172,10 +174,10 @@ struct RenderPass {
|
172 | 174 | PipelineAndLayout graphicsPipeline;
|
173 | 175 | };
|
174 | 176 |
|
175 |
| -class Engine { |
| 177 | +class Renderer { |
176 | 178 | public:
|
177 |
| - Engine(Settings &settings, Camera *primaryCam) : m_PrimaryCamera(primaryCam), m_Settings(settings) {}; |
178 |
| - ~Engine(); |
| 179 | + Renderer(Settings &settings, const Camera *primaryCam) : m_PrimaryCamera(primaryCam), m_Settings(settings) {}; |
| 180 | + ~Renderer(); |
179 | 181 |
|
180 | 182 | void SetMouseCaptureState(bool capturing);
|
181 | 183 |
|
@@ -208,6 +210,9 @@ class Engine {
|
208 | 210 | // Fixed Updates are called 60 times a second.
|
209 | 211 | void RegisterFixedUpdateFunction(const std::function<void(std::array<bool, 322>)> &func);
|
210 | 212 |
|
| 213 | + /* DO NOT 'OR' MULTIPLE EVENT TYPES, REGISTER THE SAME FUNCTION WITH A DIFFERENT TYPE IF YOU WANT THAT. */ |
| 214 | + void RegisterSDLEventListener(const std::function<void(SDL_Event *)> &func, SDL_EventType types); |
| 215 | + |
211 | 216 | void SetPrimaryCamera(Camera &cam);
|
212 | 217 |
|
213 | 218 | Glyph GenerateGlyph(EngineSharedContext &sharedContext, FT_Face ftFace, char c, float &x, float &y, float depth);
|
@@ -256,9 +261,11 @@ class Engine {
|
256 | 261 | inline bool HasStencilAttachment(VkFormat format) {return format == VK_FORMAT_D32_SFLOAT_S8_UINT || format == VK_FORMAT_D24_UNORM_S8_UINT;};
|
257 | 262 |
|
258 | 263 | /* Cameras, high-level stuff. */
|
259 |
| - Camera *m_PrimaryCamera; |
| 264 | + const Camera *m_PrimaryCamera; |
260 | 265 | Settings &m_Settings;
|
261 | 266 |
|
| 267 | + std::unordered_map<SDL_EventType, std::vector<std::function<void(SDL_Event *)>>> m_SDLEventListeners; |
| 268 | + |
262 | 269 | std::vector<Glyph> m_GlyphCache;
|
263 | 270 |
|
264 | 271 | std::vector<RenderUIWaypoint> m_RenderUIWaypoints;
|
@@ -352,7 +359,36 @@ class Engine {
|
352 | 359 | std::vector<VkDeviceMemory> m_AllocatedMemory;
|
353 | 360 | std::vector<VkImageView> m_CreatedImageViews;
|
354 | 361 | std::vector<VkSampler> m_CreatedSamplers;
|
| 362 | +}; |
| 363 | + |
| 364 | +class Engine { |
| 365 | +public: |
| 366 | + Engine() = default; |
| 367 | + |
| 368 | + void InitRenderer(Settings &settings, const Camera *primaryCamera); |
| 369 | + |
| 370 | + /* UI::Button listeners will receive events when any button is pressed, along with its ID. */ |
| 371 | + /* Due to how it works, this function can be called before the renderer is initialized. */ |
| 372 | + void RegisterUIButtonListener(const std::function<void(std::string)> listener); |
| 373 | + |
| 374 | + Renderer *GetRenderer(); |
| 375 | + |
| 376 | + void StartRenderer(); |
| 377 | + |
| 378 | + void LoadUIFile(const std::string &name); |
| 379 | + |
| 380 | + /* Register a button to the Engine, so that it can forward any clicks inside of it to the UIButton Listeners */ |
| 381 | + void RegisterUIButton(UI::Button *button); |
| 382 | + void UnregisterUIButton(UI::Button *button); |
| 383 | +private: |
| 384 | +/* Systems */ |
| 385 | + Renderer *m_Renderer = nullptr; |
| 386 | + Settings *m_Settings; |
| 387 | + |
| 388 | + void CheckButtonClicks(SDL_Event *event); |
355 | 389 |
|
| 390 | + std::vector<std::function<void(std::string)>> m_UIButtonListeners; |
| 391 | + std::vector<UI::Button *> m_UIButtons; |
356 | 392 | };
|
357 | 393 |
|
358 | 394 | #endif
|
0 commit comments