Enigma  3.2.0
A Simple, Reliable and Efficient Encryption Tool
Application.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef ENIGMA_APPLICATION_H
3 #define ENIGMA_APPLICATION_H
4 
5 #include <Core/Core.hpp>
6 #include <Logger/Logger.hpp>
7 
8 #include <Window/Window.hpp>
9 
11 #include <Events/KeyEvent.hpp>
12 #include <Events/MouseEvent.hpp>
13 
15 
16 #include <cpr/threadpool.h>
17 
19 
23 class ImGuiRenderer;
24 class Scene;
25 class RAMInfo;
26 class CPUInfo;
27 
28 class Application final : public SingleProcessInstance {
29  public:
33  explicit Application(const WindowSettings& window_settings = WindowSettings());
34  ~Application() override;
35 
37  void Run();
38 
43  void Exit(const std::string& message, const std::int32_t exit_code) noexcept;
44 
50  void LaunchWorkerThread(Scene *scene, const std::string& loading_text, const std::function<void()>& work_func);
51 
52 
53  public: //https://www.doxygen.nl/manual/grouping.html#memgroup
60  void OnEvent(Event& event);
67  public: // Accessors
69  static Application *getInstance() noexcept { return m_instance; }
70 
72  const std::unique_ptr<Window>& GetWindow() const noexcept { return m_window; }
73 
75  void EndApplication() noexcept;
76 
80  void PushScene(std::unique_ptr<Scene> scene);
81 
83  std::uint32_t GetFPS() const noexcept { return m_FPS ? *m_FPS : 0u; }
84 
86  float GetDeltaTime() const noexcept { return m_delta_time; }
87 
89  constexpr const std::unique_ptr<RAMInfo>& GetRAMInfo() const noexcept { return m_ram_info; }
90 
92  constexpr const std::unique_ptr<CPUInfo>& GetCPUInfo() const noexcept { return m_cpu_info; }
93 
94  private: // Updates
96  void UpdateDeltaTime() noexcept;
98  void UpdateHardwareInfo() noexcept;
99 
100 
101  private: // Initializer Functions
103  void InitWindow(const WindowSettings& window_settings);
105  void InitImGuiRenderer();
107  void InitHardwareInfo(const WindowSettings& window_settings);
109  void InitImGuiFonts();
110 
111  private:
112  std::unique_ptr<Window> m_window;
114  private:
115  std::vector<std::unique_ptr<Scene>> m_scenes;
116  std::unique_ptr<Scene> m_loading_scene;
120  private:
121  float m_last_frame_time;
122  float m_current_frame_time;
123  float m_delta_time;
125  private:
126  static constexpr float HARWARE_INFO_UPDATE_TIME = 1.0f;
127  float m_hardware_info_timer;
128  std::unique_ptr<std::uint32_t> m_FPS;
129  std::unique_ptr<RAMInfo> m_ram_info;
130  std::unique_ptr<CPUInfo> m_cpu_info;
132  private:
133  std::unique_ptr<ImGuiRenderer> m_imgui_renderer;
135  private:
136  inline static Application *m_instance{nullptr};
138  private:
139  std::unique_ptr<cpr::ThreadPool> m_threadPool{};
140 };
141 
143 
144 #endif // !ENIGMA_APPLICATION_H
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
Definition: Macros.hpp:13
#define NS_ENIGMA_END
Definition: Macros.hpp:14
void OnEvent(Event &event)
Event callbacks.
const std::unique_ptr< Window > & GetWindow() const noexcept
Definition: Application.hpp:72
Application(const WindowSettings &window_settings=WindowSettings())
std::uint32_t GetFPS() const noexcept
Definition: Application.hpp:83
bool OnWindowResize(WindowResizeEvent &event)
void LaunchWorkerThread(Scene *scene, const std::string &loading_text, const std::function< void()> &work_func)
Launches detached thread seperated from main UI thread.
static Application * getInstance() noexcept
Definition: Application.hpp:69
~Application() override
constexpr const std::unique_ptr< CPUInfo > & GetCPUInfo() const noexcept
Definition: Application.hpp:92
bool OnWindowClose(WindowCloseEvent &event)
void Exit(const std::string &message, const std::int32_t exit_code) noexcept
void PushScene(std::unique_ptr< Scene > scene)
float GetDeltaTime() const noexcept
Definition: Application.hpp:86
void EndApplication() noexcept
constexpr const std::unique_ptr< RAMInfo > & GetRAMInfo() const noexcept
Definition: Application.hpp:89
bool OnFrameBufferResize(FrameBufferResizeEvent &event)
Definition: Event.hpp:66
Definition: Scene.hpp:20
Single process instance class.