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 "datatypes.h"
5#include <string>
6#include <chrono>
7#include <glm/vec2.hpp>
8
9namespace oe::core
10{
11 class Window;
12
16 class Device
17 {
18 public:
23
29 Device(const std::string& title);
30
37 Device(const glm::ivec2& dimensions, const std::string& title, bool is_visible = true);
38
43
49 bool canRun() const;
50
58
64 double getTime() const;
65
72 inline std::chrono::nanoseconds getDeltaTime() const noexcept
73 {
74 return _last_delta_time;
75 }
76
80 void setSwapInterval(const int32_t interval);
81
82 void setMaxFps(const uint32_t max_fps)
83 {
84 minimum_frame_time = std::chrono::milliseconds(static_cast<int32_t>(1000.f / max_fps));
85 }
86
105 void limitFps();
106
107 const auto& getWindows() const
108 {
109 return _windows;
110 }
111
116 size_t addWindow(const glm::ivec2& dimensions, const std::string& title, bool is_visible = true);
117
122 void removeWindow(const size_t id);
123
130 Window* getWindowById(const size_t id);
131
138 const Window* getWindowById(const size_t id) const;
139
144 Window& getWindow(const size_t id = 0)
145 {
146 return *getWindowById(id);
147 }
148
153 const Window& getWindow(const size_t id = 0) const
154 {
155 return *getWindowById(id);
156 }
157
163 const std::string getKeyName(const key_code_t& key) const noexcept;
164
165 const std::string getScancodeName(const key_code_t& scancode) const noexcept;
166
167 key_code_t getScanCodeFromKey(const key_code_t& key) const noexcept;
168
176 std::chrono::duration<float> minimum_frame_time = std::chrono::milliseconds(4);
177
178 private:
179 void _init();
180
181 std::chrono::nanoseconds _last_delta_time = {};
182
183 std::chrono::time_point<std::chrono::steady_clock> _start_frame;
184
185 std::vector<std::pair<size_t, Window*>> _windows;
186
187 size_t _next_window_id = 0;
188 };
189}
190
191#endif
The OxygenEngine device that will manage events, windows, scene, etc...
Definition device.h:17
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:176
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:144
std::chrono::nanoseconds getDeltaTime() const noexcept
Get delta time between this frame and the last one.
Definition device.h:72
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:153
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 args.h:10