Avara3D 0.2.0
C++ API reference
a3d::Runner Class Reference

Drives host updates, fixed-step simulation, and rendering for a Scene. More...

#include <a3d/Runner.h>

Classes

struct  UpdateInfo
 Timing information supplied to each host update callback. More...
 

Public Types

enum class  State { Idle , Running , Stopped }
 Runner lifecycle states. More...
 
using UpdateCallback = std::function< void(Runner &runner, const UpdateInfo &info)>
 Callback invoked near the beginning of each host update. More...
 

Public Member Functions

 Runner (Scene &scene, SimulationConfig config={})
 Creates an idle Runner for scene. More...
 
void start ()
 Starts the Runner using the current monotonic time. More...
 
bool update ()
 Performs one host update using the current monotonic time. More...
 
void stop ()
 Permanently stops the Runner and clears pending requested steps. More...
 
bool simulationPaused () const
 Returns true when automatic simulation stepping is paused. More...
 
void simulationPaused (bool paused)
 Pauses or resumes automatic simulation stepping. More...
 
void requestSimulationStep ()
 Queues one fixed-duration simulation step while paused. More...
 
void resetSimulation ()
 Resets simulation progression without changing scheduling settings. More...
 
UpdateCallback updateCallback () const
 Returns the currently installed host update callback. More...
 
void updateCallback (UpdateCallback callback)
 Replaces the host update callback; an empty callback disables it. More...
 
double timeStep () const
 Returns the fixed simulation step duration in seconds. More...
 
void timeStep (double value)
 Changes the fixed simulation step duration. More...
 
std::uint32_t maxCatchUpSteps () const
 Returns the maximum number of automatic catch-up steps permitted per host update. More...
 
void maxCatchUpSteps (std::uint32_t value)
 Changes the maximum number of automatic catch-up steps per host update. More...
 
double timeScale () const
 Returns the scale applied to elapsed host time for automatic simulation stepping. More...
 
void timeScale (double value)
 Changes the scale applied to elapsed host time for automatic simulation stepping. More...
 
double simulationTime () const
 Returns total simulated time in seconds completed by fixed simulation steps. More...
 
std::uint64_t simulationStepCount () const
 Returns the total number of completed fixed simulation steps. More...
 
State state () const
 Returns the current Runner lifecycle state. More...
 
Scenescene ()
 Returns the Scene driven by this Runner. More...
 
const Scenescene () const
 Returns the Scene driven by this Runner. More...
 

Detailed Description

Drives host updates, fixed-step simulation, and rendering for a Scene.

A Runner converts elapsed host time into zero or more constant-duration simulation steps according to SimulationConfig. Catch-up work is bounded by maxCatchUpSteps(); excess accumulated simulation time is discarded while the fractional remainder is retained.

Automatic simulation stepping may be paused while host updates, input processing, host-update and input callbacks, and rendering continue. While paused, fixed-duration simulation steps may be requested explicitly.

A Runner begins in State::Idle. start() may be called once; stop() places the Runner in the terminal State::Stopped state.

See also
SimulationConfig

Definition at line 45 of file Runner.h.

Member Typedef Documentation

◆ UpdateCallback

using a3d::Runner::UpdateCallback = std::function<void(Runner& runner, const UpdateInfo& info)>

Callback invoked near the beginning of each host update.

The callback runs before event polling, input update, simulation scheduling, and rendering. It may change Runner state, including stopping the Runner or pausing automatic simulation stepping.

Definition at line 81 of file Runner.h.

Member Enumeration Documentation

◆ State

enum class a3d::Runner::State
strong

Runner lifecycle states.

Enumerator
Idle 

Constructed but not yet started.

Running 

Accepting host updates and scheduling simulation work.

Stopped 

Permanently stopped; the Runner cannot be restarted.

Definition at line 51 of file Runner.h.

Constructor & Destructor Documentation

◆ Runner()

a3d::Runner::Runner ( Scene scene,
SimulationConfig  config = {} 
)
explicit

Creates an idle Runner for scene.

The Runner retains scene by reference; the Scene must outlive the Runner. The supplied configuration is copied and validated when start() is called.

Parameters
sceneScene whose input, simulation, and rendering are driven.
configinitial simulation scheduling configuration.

Member Function Documentation

◆ maxCatchUpSteps() [1/2]

std::uint32_t a3d::Runner::maxCatchUpSteps ( ) const

Returns the maximum number of automatic catch-up steps permitted per host update.

◆ maxCatchUpSteps() [2/2]

void a3d::Runner::maxCatchUpSteps ( std::uint32_t  value)

Changes the maximum number of automatic catch-up steps per host update.

Exceptions
std::invalid_argumentif value is zero.

◆ requestSimulationStep()

void a3d::Runner::requestSimulationStep ( )

Queues one fixed-duration simulation step while paused.

Requested steps use timeStep() and are not scaled by timeScale(). Multiple calls queue multiple steps for the next eligible host update.

Exceptions
std::logic_errorif the Runner is not running or the simulation is not paused.
std::overflow_errorif the pending-step counter overflows.

◆ resetSimulation()

void a3d::Runner::resetSimulation ( )

Resets simulation progression without changing scheduling settings.

Simulation time, completed step count, accumulated/discarded time, and pending requested steps are reset. The current time step, maximum catch-up count, time scale, and pause state are preserved.

When automatic stepping is active, the next host-time delta is discarded.

Exceptions
std::logic_errorif the Runner is not running.

◆ scene() [1/2]

Scene & a3d::Runner::scene ( )

Returns the Scene driven by this Runner.

◆ scene() [2/2]

const Scene & a3d::Runner::scene ( ) const

Returns the Scene driven by this Runner.

◆ simulationPaused() [1/2]

bool a3d::Runner::simulationPaused ( ) const

Returns true when automatic simulation stepping is paused.

◆ simulationPaused() [2/2]

void a3d::Runner::simulationPaused ( bool  paused)

Pauses or resumes automatic simulation stepping.

Host updates, input processing, host-update and input callbacks, and rendering continue while paused. Scene simulation-step callbacks run only when explicitly requested steps are executed. Pausing clears accumulated automatic simulation time. Resuming clears pending requested steps and discards the next host-time delta so time spent paused does not become catch-up work.

Parameters
pausedtrue to pause automatic simulation stepping; false to resume it.
Exceptions
std::logic_errorif the Runner is not running.

◆ simulationStepCount()

std::uint64_t a3d::Runner::simulationStepCount ( ) const

Returns the total number of completed fixed simulation steps.

◆ simulationTime()

double a3d::Runner::simulationTime ( ) const

Returns total simulated time in seconds completed by fixed simulation steps.

◆ start()

void a3d::Runner::start ( )

Starts the Runner using the current monotonic time.

Starting resets simulation progression and host-update counters to their initial values from the Runner configuration.

Exceptions
std::logic_errorif the Runner is not idle.
std::invalid_argumentif the initial simulation configuration is invalid.

◆ state()

State a3d::Runner::state ( ) const

Returns the current Runner lifecycle state.

◆ stop()

void a3d::Runner::stop ( )

Permanently stops the Runner and clears pending requested steps.

Calling stop() on an already stopped Runner has no effect.

◆ timeScale() [1/2]

double a3d::Runner::timeScale ( ) const

Returns the scale applied to elapsed host time for automatic simulation stepping.

◆ timeScale() [2/2]

void a3d::Runner::timeScale ( double  value)

Changes the scale applied to elapsed host time for automatic simulation stepping.

Requested steps are not affected by this value.

Exceptions
std::invalid_argumentif value is less than or equal to zero.

◆ timeStep() [1/2]

double a3d::Runner::timeStep ( ) const

Returns the fixed simulation step duration in seconds.

◆ timeStep() [2/2]

void a3d::Runner::timeStep ( double  value)

Changes the fixed simulation step duration.

Existing accumulated simulation time is preserved in seconds.

Exceptions
std::invalid_argumentif value is less than or equal to zero.

◆ update()

bool a3d::Runner::update ( )

Performs one host update using the current monotonic time.

A running update invokes the host callback, polls events, updates input, advances or explicitly steps the simulation as appropriate, and renders when the Scene has a VisualWorld.

Returns
true when the Runner remains running after the update; false when it was not running or stopped during the update.

◆ updateCallback() [1/2]

UpdateCallback a3d::Runner::updateCallback ( ) const

Returns the currently installed host update callback.

◆ updateCallback() [2/2]

void a3d::Runner::updateCallback ( UpdateCallback  callback)

Replaces the host update callback; an empty callback disables it.


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