Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
device.h
1#ifndef OE_CORE_DEVICE_H
2#define OE_CORE_DEVICE_H
3
4#include "../common.h"
5#include <string>
6#include <chrono>
7#include <glm/vec2.hpp>
8#include "event_handler.h"
9
10namespace oe::core
11{
12 class Window;
13
17 class Device
18 {
19 public:
24
30 Device(const std::string& title);
31
38 Device(const glm::ivec2& dimensions, const std::string& title, bool is_visible = true);
39
44
50 bool canRun() const;
51
59
65 double getTime() const;
66
73 inline std::chrono::nanoseconds getDeltaTime() const noexcept
74 {
75 return _last_delta_time;
76 }
77
81 void setSwapInterval(const int32_t interval);
82
83 void setMaxFps(const uint32_t max_fps)
84 {
85 minimum_frame_time = std::chrono::milliseconds(static_cast<int32_t>(1000.f / max_fps));
86 }
87
106 void limitFps();
107
108 const auto& getWindows() const
109 {
110 return _windows;
111 }
112
117 size_t addWindow(const glm::ivec2& dimensions, const std::string& title, bool is_visible = true);
118
123 void removeWindow(const size_t id);
124
131 Window* getWindowById(const size_t id);
132
139 const Window* getWindowById(const size_t id) const;
140
145 Window& getWindow(const size_t id = 0)
146 {
147 return *getWindowById(id);
148 }
149
154 const Window& getWindow(const size_t id = 0) const
155 {
156 return *getWindowById(id);
157 }
158
164 const std::string getKeyName(const key_code_t& key) const noexcept;
165
166 const std::string getScancodeName(const key_code_t& scancode) const noexcept;
167
168 key_code_t getScanCodeFromKey(const key_code_t& key) const noexcept;
169
177 std::chrono::duration<float> minimum_frame_time = std::chrono::milliseconds(4);
178
179 private:
180 void _init();
181
182 std::chrono::nanoseconds _last_delta_time = {};
183
184 std::chrono::time_point<std::chrono::steady_clock> _start_frame;
185
186 std::vector<std::pair<size_t, Window*>> _windows;
187
188 size_t _next_window_id = 0;
189 };
190}
191
192#endif
The OxygenEngine device that will manage events, windows, scene, etc...
Definition device.h:18
void processEvents()
Process device events.
Window * getWindowById(const size_t id)
Get a device's registered window.
std::chrono::duration< float > minimum_frame_time
Minimum time allowed for a frame.
Definition device.h:177
Device(const std::string &title)
Create the device with a fullscreen window.
const std::string getKeyName(const key_code_t &key) const noexcept
bool canRun() const
Check if nothing prevented the device to close.
const Window * getWindowById(const size_t id) const
Get a device's registered window.
~Device()
Destroy the device.
size_t addWindow(const glm::ivec2 &dimensions, const std::string &title, bool is_visible=true)
Add a new window.
Window & getWindow(const size_t id=0)
Get a device's registered window.
Definition device.h:145
std::chrono::nanoseconds getDeltaTime() const noexcept
Get delta time between this frame and the last one.
Definition device.h:73
Device()
Create a device without windows.
double getTime() const
Get time since device started.
void limitFps()
Clamp FPS to avoid rendering at too high framerates.
Device(const glm::ivec2 &dimensions, const std::string &title, bool is_visible=true)
Create the device with a window.
const Window & getWindow(const size_t id=0) const
Get a device's registered window.
Definition device.h:154
void setSwapInterval(const int32_t interval)
Set the device's swap interval.
void removeWindow(const size_t id)
Remove a window.
Definition window.h:24
Core functionality (windows, event handler, logger, ...)
Definition cursor.h:8