matf-rg-engine  1.0.0
Base for project for the Computer Graphics course at Faculty of Mathematics, University of Belgrade
Public Member Functions | Private Member Functions | Private Attributes | List of all members
engine::platform::PlatformController Class Referencefinal

Registers Platform events such as mouse movement, key press, window events... More...

#include <PlatformController.hpp>

Inheritance diagram for engine::platform::PlatformController:
Inheritance graph
[legend]
Collaboration diagram for engine::platform::PlatformController:
Collaboration graph
[legend]

Public Member Functions

const Key & key (KeyId key) const
 Get the state of the Key in the current frame. More...
 
const MousePosition & mouse () const
 Get the state of the MousePosition in the current frame. More...
 
std::string_view name () const override
 Get the name of the Controller. More...
 
const Window * window () const
 Get the window. More...
 
void register_platform_event_observer (std::unique_ptr< PlatformEventObserver > observer)
 Register a PlatformEventObserver callback for platform events. By default, the PlatformController registers a PlatformEventObserver that does nothing. More...
 
const FrameTime & frame_time () const
 Get FrameTime for the previous frame. Updated in during core::App::loop. More...
 
float dt () const
 Get elapsed time for the previous frame. More...
 
void set_enable_cursor (bool enabled)
 Enables/disabled the visibility of the cursor on screen. More...
 
void swap_buffers ()
 Swaps the current draw buffer for the main window. Should be called at the end of the frame. More...
 
void _platform_on_mouse (double x, double y)
 Called from the platform-specific callback. You shouldn't call this function directly. More...
 
void _platform_on_keyboard (int key, int action)
 Called from the platform-specific callback. You shouldn't call this function directly. More...
 
void _platform_on_scroll (double x, double y)
 Called from the platform-specific callback. You shouldn't call this function directly. More...
 
void _platform_on_framebuffer_resize (int width, int height)
 Called from the platform-specific callback. You shouldn't call this function directly. More...
 
void _platform_on_window_close (GLFWwindow *window)
 Called from the platform-specific callback. You shouldn't call this function directly. More...
 
void _platform_on_mouse_button (int button, int action)
 
- Public Member Functions inherited from engine::core::Controller
virtual ~Controller ()=default
 
void before (Controller *next)
 
void after (Controller *prev)
 
const std::vector< Controller * > & next () const
 
bool is_enabled () const
 Controller will execute as long this function returns true. More...
 
void set_enable (bool value)
 Enables or disables the controller based on value. The engine::core::App executes only the enabled controllers, except for the Controller::poll_events function, that's executed always. By default, controllers are enabled when registered. More...
 

Private Member Functions

Key & key_ref (KeyId key)
 
void initialize () override
 Initializes the platform layer and registers platform-specific event callbacks. More...
 
void terminate () override
 Terminate the platform layer. More...
 
bool loop () override
 Checks whether the main loop should continue. Executes in the core::App::loop. More...
 
void poll_events () override
 Process internal and external events. Executes in the core::App::poll_events. More...
 
void update_mouse ()
 
void update_key (Key &key_data) const
 Updates the state of a key. Key states are repesented as a state machine with the following states: Released, JustPressed, Pressed, JustReleased. The state machine transitions are as follows: More...
 

Private Attributes

FrameTime m_frame_time
 
Window m_window
 
std::vector< Key > m_keys
 
std::vector< std::unique_ptr< PlatformEventObserver > > m_platform_event_observers
 

Additional Inherited Members

- Static Public Member Functions inherited from engine::core::Controller
template<typename TController >
static TController * get (std::source_location location=std::source_location::current())
 Serves as a single access point for all the Controller types throughout the code base. Make sure to register the controller via App::register_controller before calling this function. More...
 

Detailed Description

Registers Platform events such as mouse movement, key press, window events...

Member Function Documentation

◆ key()

const Key & engine::platform::PlatformController::key ( KeyId  key) const

Get the state of the Key in the current frame.

Parameters
keyAn KeyId for the key
Returns
The state of the key in the current frame

◆ mouse()

const MousePosition & engine::platform::PlatformController::mouse ( ) const

Get the state of the MousePosition in the current frame.

Returns
MousePosition for the current frame.

◆ name()

std::string_view engine::platform::PlatformController::name ( ) const
overridevirtual

Get the name of the Controller.

Returns
"PlatformController"

Reimplemented from engine::core::Controller.

◆ window()

const Window* engine::platform::PlatformController::window ( ) const
inline

Get the window.

Returns
Window

◆ register_platform_event_observer()

void engine::platform::PlatformController::register_platform_event_observer ( std::unique_ptr< PlatformEventObserver >  observer)

Register a PlatformEventObserver callback for platform events. By default, the PlatformController registers a PlatformEventObserver that does nothing.

◆ frame_time()

const FrameTime& engine::platform::PlatformController::frame_time ( ) const
inline

Get FrameTime for the previous frame. Updated in during core::App::loop.

Returns
FrameTime

◆ dt()

float engine::platform::PlatformController::dt ( ) const
inline

Get elapsed time for the previous frame.

◆ set_enable_cursor()

void engine::platform::PlatformController::set_enable_cursor ( bool  enabled)

Enables/disabled the visibility of the cursor on screen.

◆ swap_buffers()

void engine::platform::PlatformController::swap_buffers ( )

Swaps the current draw buffer for the main window. Should be called at the end of the frame.

◆ _platform_on_mouse()

void engine::platform::PlatformController::_platform_on_mouse ( double  x,
double  y 
)

Called from the platform-specific callback. You shouldn't call this function directly.

◆ _platform_on_keyboard()

void engine::platform::PlatformController::_platform_on_keyboard ( int  key,
int  action 
)

Called from the platform-specific callback. You shouldn't call this function directly.

◆ _platform_on_scroll()

void engine::platform::PlatformController::_platform_on_scroll ( double  x,
double  y 
)

Called from the platform-specific callback. You shouldn't call this function directly.

◆ _platform_on_framebuffer_resize()

void engine::platform::PlatformController::_platform_on_framebuffer_resize ( int  width,
int  height 
)

Called from the platform-specific callback. You shouldn't call this function directly.

◆ _platform_on_window_close()

void engine::platform::PlatformController::_platform_on_window_close ( GLFWwindow *  window)

Called from the platform-specific callback. You shouldn't call this function directly.

◆ _platform_on_mouse_button()

void engine::platform::PlatformController::_platform_on_mouse_button ( int  button,
int  action 
)

◆ key_ref()

Key & engine::platform::PlatformController::key_ref ( KeyId  key)
private

◆ initialize()

void engine::platform::PlatformController::initialize ( )
overrideprivatevirtual

Initializes the platform layer and registers platform-specific event callbacks.

Reimplemented from engine::core::Controller.

◆ terminate()

void engine::platform::PlatformController::terminate ( )
overrideprivatevirtual

Terminate the platform layer.

Reimplemented from engine::core::Controller.

◆ loop()

bool engine::platform::PlatformController::loop ( )
overrideprivatevirtual

Checks whether the main loop should continue. Executes in the core::App::loop.

Returns
true if the render loop should continue.

Reimplemented from engine::core::Controller.

◆ poll_events()

void engine::platform::PlatformController::poll_events ( )
overrideprivatevirtual

Process internal and external events. Executes in the core::App::poll_events.

Reimplemented from engine::core::Controller.

◆ update_mouse()

void engine::platform::PlatformController::update_mouse ( )
private

◆ update_key()

void engine::platform::PlatformController::update_key ( Key &  key_data) const
private

Updates the state of a key. Key states are repesented as a state machine with the following states: Released, JustPressed, Pressed, JustReleased. The state machine transitions are as follows:

  • Released -> JustPressed if the key is pressed.
  • JustPressed -> Pressed if the key is still pressed.
  • Pressed -> JustReleased if the key is released.
  • JustReleased -> Released if the key is released.
    Parameters
    key_dataThe key to update.

Member Data Documentation

◆ m_frame_time

FrameTime engine::platform::PlatformController::m_frame_time
private

◆ m_window

Window engine::platform::PlatformController::m_window
private

◆ m_keys

std::vector<Key> engine::platform::PlatformController::m_keys
private

◆ m_platform_event_observers

std::vector<std::unique_ptr<PlatformEventObserver> > engine::platform::PlatformController::m_platform_event_observers
private

The documentation for this class was generated from the following files: