utility 2026.2.0
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
utility::Engine Class Referenceabstract

Engine interface combining rendering and event handling. More...

#include <headers/utility/engine.hpp>

Inheritance diagram for utility::Engine:
Collaboration diagram for utility::Engine:

Public Types

using ViewportSize = utility::math::Vector2F
 2D vector representing viewport width and height in pixels.
 
using Handler = std::function< void(std::shared_ptr< utility::event::Event > &)>
 Type alias for an event handler callback function.
 

Public Member Functions

bool shouldCaptureViewportInput (void) const
 Check if viewport input capture is enabled.
 
void setShouldCaptureViewportInput (bool capture)
 Set the viewport input capture state.
 
 Engine (void)
 Default constructor.
 
virtual ~Engine (void)=default
 Default destructor.
 
virtual void clear (void)=0
 Clear the current rendering target with the drawing color.
 
virtual void present (void)=0
 Present the composed back buffer to the screen.
 
virtual utility::graphic::SizeF measureText (const utility::graphic::Text &text) const =0
 Measures the pixel dimensions of a given text string when rendered with a specific font.
 
virtual size_t createObject (std::shared_ptr< utility::graphic::Renderable > object)=0
 Create a new render object.
 
virtual bool updateObject (std::shared_ptr< utility::graphic::Renderable > object, size_t objectID)=0
 Update a previously added render object.
 
virtual bool removeObject (std::shared_ptr< utility::graphic::Renderable > object, size_t objectID)=0
 Remove a previously added render object.
 
virtual utility::graphic::ViewF getView (void) const =0
 Get the full view model.
 
virtual float getDeltaTime (void) const
 Get the time elapsed since the previous frame.
 
virtual void setScissor (const utility::graphic::ScissorRect &rect)
 Set the active scissor (clip) rectangle.
 
virtual void clearScissor (void)
 Clear the active scissor (clip) rectangle.
 
std::optional< utility::graphic::ScissorRect > getScissor (void) const
 Get the active scissor (clip) rectangle.
 
void setEventCallback (const Handler &callback)
 Set the event callback function.
 
virtual void pollEvents (void)=0
 Poll for events and dispatch them.
 
virtual void update (void)=0
 Update the engine state.
 

Protected Member Functions

Handler & getEventCallback (void)
 Get the current event callback function.
 
- Protected Member Functions inherited from utility::logging::Loggable< Engine, utility::logging::DefaultLogger >
 Loggable (void)
 Construct a Loggable with the specified LoggerType.
 
 Loggable (Loggable &&other) noexcept
 Move constructor for Loggable.
 
Loggable & operator= (Loggable &&other) noexcept
 Move assignment operator for Loggable.
 
LoggerType & getLogger (void)
 Get the internal logger.
 
LoggerType & getLogger (void) const
 Get the internal logger.
 
virtual ~Loggable (void)=default
 Virtual destructor for proper cleanup.
 

Detailed Description

Engine interface combining rendering and event handling.

This class provides an abstract interface for the core engine loop. Implementations should provide platform-specific rendering and event polling capabilities.

class MyEngine : public Engine { ... };
Engine interface combining rendering and event handling.
Definition engine.hpp:62

Definition at line 59 of file engine.hpp.

Member Typedef Documentation

◆ Handler

using utility::Engine::Handler = std::function<void(std::shared_ptr<utility::event::Event> &)>

Type alias for an event handler callback function.

Takes a shared pointer to an Event and performs an action.

Definition at line 74 of file engine.hpp.

◆ ViewportSize

2D vector representing viewport width and height in pixels.

Definition at line 67 of file engine.hpp.

Member Function Documentation

◆ createObject()

virtual size_t utility::Engine::createObject ( std::shared_ptr< utility::graphic::Renderable >  object)
pure virtual

Create a new render object.

Parameters
objectA shared pointer to the renderable object to create.
Returns
A unique identifier for the created object.

◆ getDeltaTime()

virtual float utility::Engine::getDeltaTime ( void  ) const
virtual

Get the time elapsed since the previous frame.

Implementations backed by a real clock should override this so that time-based systems (animations, transitions) advance with the platform frame rate. The default returns 0, in which case callers fall back to their own monotonic clock.

Returns
Delta time in seconds.

◆ getEventCallback()

Handler & utility::Engine::getEventCallback ( void  )
protected

Get the current event callback function.

Returns
Reference to the event callback function.

◆ getScissor()

std::optional< utility::graphic::ScissorRect > utility::Engine::getScissor ( void  ) const

Get the active scissor (clip) rectangle.

Returns
The active rectangle, or std::nullopt when none is set.

◆ getView()

virtual utility::graphic::ViewF utility::Engine::getView ( void  ) const
pure virtual

Get the full view model.

Returns
The view instance.

◆ measureText()

virtual utility::graphic::SizeF utility::Engine::measureText ( const utility::graphic::Text &  text) const
pure virtual

Measures the pixel dimensions of a given text string when rendered with a specific font.

Parameters
textThe text to measure.
Returns
A 2D vector containing the width and height of the rendered text in pixels in the form of utility::math::Vector2F.

◆ pollEvents()

virtual void utility::Engine::pollEvents ( void  )
pure virtual

Poll for events and dispatch them.

This method should check for pending events from the underlying platform, convert them to Event objects, and call the registered callback for each event.

◆ removeObject()

virtual bool utility::Engine::removeObject ( std::shared_ptr< utility::graphic::Renderable >  object,
size_t  objectID 
)
pure virtual

Remove a previously added render object.

Parameters
objectThe renderable object to remove.
objectIDThe identifier returned by createObject.
Returns
True when the object was removed.

◆ setEventCallback()

void utility::Engine::setEventCallback ( const Handler &  callback)

Set the event callback function.

The callback will be invoked for each event when pollEvents() is called.

Parameters
callbackFunction to call when an event is received.

◆ setScissor()

virtual void utility::Engine::setScissor ( const utility::graphic::ScissorRect &  rect)
virtual

Set the active scissor (clip) rectangle.

The rectangle is expressed in framebuffer pixels. Implementations backed by a renderer should clip subsequent draws to it; the base implementation only stores the rectangle so it can be queried with getScissor().

Parameters
rectThe scissor rectangle to apply.

◆ setShouldCaptureViewportInput()

void utility::Engine::setShouldCaptureViewportInput ( bool  capture)

Set the viewport input capture state.

Parameters
captureTrue to enable viewport input capture, false to disable. When disabled, input is routed to UI instead of camera controls.

◆ shouldCaptureViewportInput()

bool utility::Engine::shouldCaptureViewportInput ( void  ) const

Check if viewport input capture is enabled.

Returns
True when viewport input is captured for camera movement.

◆ update()

virtual void utility::Engine::update ( void  )
pure virtual

Update the engine state.

This method should handle logic updates, input processing, and other non-rendering related tasks. It is typically called once per frame, allowing the engine to respond to user input and update the state of objects in the renderer.

◆ updateObject()

virtual bool utility::Engine::updateObject ( std::shared_ptr< utility::graphic::Renderable >  object,
size_t  objectID 
)
pure virtual

Update a previously added render object.

Parameters
objectThe updated renderable object.
objectIDThe identifier returned by createObject.
Returns
True when the object was updated.

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