Loading...
Searching...
No Matches
Application.h
Go to the documentation of this file.
1// Application.h
2#pragma once
3#include "../platform/IWindow.h"
4#include "../scene/SceneManager.h"
5#include "../graphics/renderer/Renderer.h"
6#include "../graphics/managers/ShaderManager.h"
7#include "hellfire/Interfaces/IApplicationPlugin.h"
8#include "InputManager.h"
9
10namespace hellfire {
11 class Renderer;
12 class Camera;
13
14 struct MousePos {
15 float x;
16 float y;
17 };
18
19 struct AppInfo {
20 // Dimensions
21 int width;
22 int height;
24
25 // state
28
29 // Input
32
34 int fps;
35 bool first_mouse = true;
36
38 bool should_warp_cursor = false;
39 bool minimized = false;
40 std::string title = "Hellfire Engine";
41 };
42
44 public:
45 explicit Application(int width = 800, int height = 600, std::string title = "hellfire Application");
46
47 ~Application() override;
48
50
52
53 // Clean initialization
54 void initialize();
55
56 void run();
57
58 // Accessors
60 /// Method for registering plugins
61 void register_plugin(std::unique_ptr<IApplicationPlugin> plugin) {
62 plugins_.push_back(std::move(plugin));
63 }
64
65 void set_exit_condition(std::function<bool()> condition);
66
67 void request_exit();
68
69 bool should_exit() const;
70 protected:
71 // IWindowEventHandler implementation
72 void on_render() override;
73
74 void on_key_down(int key) override;
75
76 void on_key_up(int key) override;
77
78 void on_mouse_button(int button, bool pressed) override;
79
80 bool handle_first_mouse_movement(float x, float y);
81
82 void handle_cursor_warping(float x, float y) const;
83
84 void on_mouse_move(float x, float y) override;
85
86 void on_window_resize(int width, int height) override;
87
88 void on_window_minimize(bool minimized) override;
89
90
91
92 private:
93 std::function<bool()> exit_condition_;
94 bool should_exit_ = false;
95
96 // Managers
100
103
104 // Window info tracking
106
107 template<typename Func>
108 void call_plugins(Func &&func) {
109 for (auto &plugin: plugins_) {
110 func(*plugin);
111 }
112 }
113
114 template<typename Func>
115 bool call_plugins_until_consumed(Func &&func) {
116 for (auto &plugin: plugins_) {
117 if (func(*plugin)) return true;
118 }
119 return false;
120 }
121 };
122}
bool is_valid() const
Definition Shader.h:46
std::vector< std::unique_ptr< IApplicationPlugin > > plugins_
Definition Application.h:97
std::function< bool()> exit_condition_
Definition Application.h:93
AppInfo & get_window_info()
Definition Application.h:59
void on_mouse_move(float x, float y) override
void set_exit_condition(std::function< bool()> condition)
ShaderManager shader_manager_
std::unique_ptr< IWindow > window_
Definition Application.h:98
ShaderRegistry shader_registry_
bool call_plugins_until_consumed(Func &&func)
void on_render() override
std::unique_ptr< InputManager > input_manager_
Definition Application.h:99
Application(int width=800, int height=600, std::string title="hellfire Application")
void handle_cursor_warping(float x, float y) const
bool handle_first_mouse_movement(float x, float y)
void on_key_up(int key) override
void on_key_down(int key) override
void on_window_minimize(bool minimized) override
void register_plugin(std::unique_ptr< IApplicationPlugin > plugin)
Method for registering plugins.
Definition Application.h:61
Shader * ensure_fallback_shader()
void on_mouse_button(int button, bool pressed) override
void call_plugins(Func &&func)
uint32_t create_minimal_fallback_shader()
void on_window_resize(int width, int height) override
virtual bool on_mouse_move(float x, float y, float x_offset, float y_offset)
virtual bool on_mouse_button(int button, bool pressed)
virtual bool on_key_down(int key)
virtual Entity * get_render_camera_override()
virtual void on_initialize(Application &app)
virtual void on_window_resize(int width, int height)
virtual void on_mouse_button(int button, bool pressed)
Definition IWindow.h:34
Manages a collection of entities and their hierarchical relationships.
Definition Scene.h:24
std::string title
Definition Application.h:40
static float delta_time
Definition Time.h:9
static void update()
Definition Time.h:20
static void init()
Definition Time.h:16