Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
oe::core::Device Class Reference

The OxygenEngine device that will manage events, windows, scene, etc... More...

#include <OxygenEngine/core/device.h>

Public Member Functions

 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.
 
double 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 int max_fps)
 
void limitFps ()
 Clamp FPS to avoid rendering at too high framerates.
 
const std::vector< Window * > getWindows () const
 
int32_t addWindow (const glm::ivec2 &dimensions, const std::string &title, bool is_visible=true)
 Add a new window.
 
WindowgetWindow (const int32_t id=0)
 Get a device's registered window.
 
const WindowgetWindow (const int32_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
 

Public Attributes

std::chrono::duration< float > minimum_frame_time = std::chrono::milliseconds(4)
 Minimum time allowed for a frame.
 

Detailed Description

The OxygenEngine device that will manage events, windows, scene, etc...

Constructor & Destructor Documentation

◆ Device() [1/2]

oe::core::Device::Device ( const std::string &  title)

Create the device with a fullscreen window.

Parameters
titlemain window title

◆ 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
dimensionsmain window dimensions
titlemain window title

Member Function Documentation

◆ addWindow()

int32_t oe::core::Device::addWindow ( const glm::ivec2 &  dimensions,
const std::string &  title,
bool  is_visible = true 
)

Add a new window.

Returns
window identifier to use in getWindow()

◆ canRun()

bool oe::core::Device::canRun ( ) const

Check if nothing prevented the device to close.

Example: A click on window close button

◆ getDeltaTime()

double 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
keyKey to use, for example, KeyboardKey::KEY_A will return "Q" on an Azerty keyboard

◆ getWindow() [1/2]

Window & oe::core::Device::getWindow ( const int32_t  id = 0)

Get a device's registered window.

Parameters
idid of the window returned from addWindow() or 0 to get the main window

◆ getWindow() [2/2]

const Window & oe::core::Device::getWindow ( const int32_t  id = 0) const

Get a device's registered window.

Parameters
idid of the window returned from addWindow() or 0 to get the main window

◆ 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();
// ... Update, renders, etc ...
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

Member Data Documentation

◆ 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: