The OxygenEngine device that will manage events, windows, scene, etc...
More...
#include <OxygenEngine/core/device.h>
|
| Device () |
| Create a device without windows.
|
|
| Device (const std::string &title) |
| Create the device with a fullscreen window.
|
|
| Device (const glm::ivec2 &dimensions, const std::string &title, bool is_visible=true) |
| Create the device with a window.
|
|
| ~Device () |
| Destroy the device.
|
|
bool | canRun () const |
| Check if nothing prevented the device to close.
|
|
void | processEvents () |
| Process device events.
|
|
double | getTime () const |
| Get time since device started.
|
|
std::chrono::nanoseconds | getDeltaTime () const noexcept |
| Get delta time between this frame and the last one.
|
|
void | setSwapInterval (const int32_t interval) |
| Set the device's swap interval.
|
|
void | setMaxFps (const uint32_t max_fps) |
|
void | limitFps () |
| Clamp FPS to avoid rendering at too high framerates.
|
|
const auto & | getWindows () const |
|
size_t | addWindow (const glm::ivec2 &dimensions, const std::string &title, bool is_visible=true) |
| Add a new window.
|
|
void | removeWindow (const size_t id) |
| Remove a window.
|
|
Window * | getWindowById (const size_t id) |
| Get a device's registered window.
|
|
const Window * | getWindowById (const size_t id) const |
| Get a device's registered window.
|
|
Window & | getWindow (const size_t id=0) |
| Get a device's registered window.
|
|
const Window & | getWindow (const size_t id=0) const |
| Get a device's registered window.
|
|
const std::string | getKeyName (const key_code_t &key) const noexcept |
|
const std::string | getScancodeName (const key_code_t &scancode) const noexcept |
|
key_code_t | getScanCodeFromKey (const key_code_t &key) const noexcept |
|
|
std::chrono::duration< float > | minimum_frame_time = std::chrono::milliseconds(4) |
| Minimum time allowed for a frame.
|
|
The OxygenEngine device that will manage events, windows, scene, etc...
◆ Device() [1/2]
oe::core::Device::Device |
( |
const std::string & |
title | ) |
|
Create the device with a fullscreen window.
- Parameters
-
◆ Device() [2/2]
oe::core::Device::Device |
( |
const glm::ivec2 & |
dimensions, |
|
|
const std::string & |
title, |
|
|
bool |
is_visible = true |
|
) |
| |
Create the device with a window.
- Parameters
-
dimensions | main window dimensions |
title | main window title |
◆ addWindow()
size_t oe::core::Device::addWindow |
( |
const glm::ivec2 & |
dimensions, |
|
|
const std::string & |
title, |
|
|
bool |
is_visible = true |
|
) |
| |
◆ canRun()
bool oe::core::Device::canRun |
( |
| ) |
const |
Check if nothing prevented the device to close.
Example: A click on window close button
◆ getDeltaTime()
std::chrono::nanoseconds oe::core::Device::getDeltaTime |
( |
| ) |
const |
|
inlinenoexcept |
Get delta time between this frame and the last one.
- Note
- Can be used to fill
update()
delta
-
Value is updated after each processEvents()
◆ getKeyName()
const std::string oe::core::Device::getKeyName |
( |
const key_code_t & |
key | ) |
const |
|
noexcept |
Get a layout dependant key name from key
- Parameters
-
key | Key to use, for example, KeyboardKey::KEY_A will return "Q" on an Azerty keyboard |
◆ getTime()
double oe::core::Device::getTime |
( |
| ) |
const |
Get time since device started.
- Note
- Wrapper of glfwGetTime
◆ getWindow() [1/2]
Window & oe::core::Device::getWindow |
( |
const size_t |
id = 0 | ) |
|
|
inline |
Get a device's registered window.
- Parameters
-
id | id of the window returned from addWindow() or 0 to get the main window |
◆ getWindow() [2/2]
const Window & oe::core::Device::getWindow |
( |
const size_t |
id = 0 | ) |
const |
|
inline |
Get a device's registered window.
- Parameters
-
id | id of the window returned from addWindow() or 0 to get the main window |
◆ getWindowById() [1/2]
Window * oe::core::Device::getWindowById |
( |
const size_t |
id | ) |
|
Get a device's registered window.
- Parameters
-
- Returns
- nullptr if the window does not exists
◆ getWindowById() [2/2]
const Window * oe::core::Device::getWindowById |
( |
const size_t |
id | ) |
const |
Get a device's registered window.
- Parameters
-
- Returns
- nullptr if the window does not exists
◆ limitFps()
void oe::core::Device::limitFps |
( |
| ) |
|
Clamp FPS to avoid rendering at too high framerates.
The thread will be paused until cooldown is elapsed
while (device.canRun())
{
device.processEvents();
device.limitFps();
}
- Note
- Actual FPS are expected to sometimes not be exactly the same as requested (because
sleep
is not perfect)
◆ processEvents()
void oe::core::Device::processEvents |
( |
| ) |
|
Process device events.
- Fill all windows EventHandler from events that happened during the frame
- Update the delta time
◆ removeWindow()
void oe::core::Device::removeWindow |
( |
const size_t |
id | ) |
|
Remove a window.
- Parameters
-
◆ minimum_frame_time
std::chrono::duration<float> oe::core::Device::minimum_frame_time = std::chrono::milliseconds(4) |
Minimum time allowed for a frame.
If the render is faster than this value and limitFps() is used, a sleep will be added to prevent huge framerates (and coilwhine)
By default this value prevent renders faster than 250 FPS (1000/4)
The documentation for this class was generated from the following file: