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
63 double getTime() const;
64
71 inline double getDeltaTime() const noexcept
72 {
73 return _last_delta_time;
74 }
75
79 void setSwapInterval(const int32_t interval);
80
81 void setMaxFps(const int max_fps)
82 {
83 minimum_frame_time = std::chrono::milliseconds(static_cast<int32_t>(1000.f / max_fps));
84 }
85
104 void limitFps();
105
106 const std::vector<Window*> getWindows() const
107 {
108 return _windows;
109 }
110
115 int32_t addWindow(const glm::ivec2& dimensions, const std::string& title, bool is_visible = true);
116
121 Window& getWindow(const int32_t id = 0);
122
127 const Window& getWindow(const int32_t id = 0) const;
128
134 const std::string getKeyName(const key_code_t& key) const noexcept;
135
136 const std::string getScancodeName(const key_code_t& scancode) const noexcept;
137
138 key_code_t getScanCodeFromKey(const key_code_t& key) const noexcept;
139
147 std::chrono::duration<float> minimum_frame_time = std::chrono::milliseconds(4);
148
149 private:
150 double _last_time_for_delta = 0.0;
151 double _last_delta_time = 0.0;
152
153 std::chrono::time_point<std::chrono::steady_clock> _start_frame;
154
155 std::vector<Window*> _windows;
156 };
157}
158
159#endif
The OxygenEngine device that will manage events, windows, scene, etc...
Definition device.h:18
void processEvents()
Process device events.
std::chrono::duration< float > minimum_frame_time
Minimum time allowed for a frame.
Definition device.h:147
int32_t addWindow(const glm::ivec2 &dimensions, const std::string &title, bool is_visible=true)
Add a new window.
double getDeltaTime() const noexcept
Get delta time between this frame and the last one.
Definition device.h:71
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 & getWindow(const int32_t id=0) const
Get a device's registered window.
~Device()
Destroy the device.
Device()
Create a device without windows.
double getTime() const
Get time since device started.
Window & getWindow(const int32_t id=0)
Get a device's registered window.
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.
void setSwapInterval(const int32_t interval)
Set the device's swap interval.
Definition window.h:24
Core functionality (windows, event handler, logger, ...)
Definition cursor.h:8