9#ifndef AVARA3D_RUNNER_H
10#define AVARA3D_RUNNER_H
16#include "a3d/SimulationConfig.h"
17#include "a3d/profile/FrameStatsHistory.h"
18#include "a3d/profile/Profiler.h"
20#include "a3d/TestAccessFwd.h"
236 bool simulationClockSuspended()
const;
237 void simulationClockSuspended(
bool suspended);
242 using Clock = std::chrono::steady_clock;
243 using TimePoint = Clock::time_point;
247 void start(TimePoint now);
248 bool update(TimePoint now);
250 void advanceSimulation(
const UpdateInfo& info, FrameStats& stats);
251 void executePendingSimulationSteps(FrameStats& stats);
252 void executeSimulationStep();
254 bool renderFrame(
const UpdateInfo& info, FrameStats& stats);
262 std::uint32_t _maxCatchUpSteps;
264 double _simulationTimeAccumulator;
265 double _simulationTime;
266 std::uint64_t _simulationStepCount;
267 double _totalDiscardedSimulationTime;
268 bool _simulationPaused;
269 std::uint64_t _pendingSimulationSteps;
270 bool _skipNextUpdateDelta;
271 bool _simulationClockSuspended;
272 TimePoint _startTime;
273 TimePoint _prevUpdateTime;
274 std::uint64_t _updateCount;
276 std::uint64_t _renderedFrameCount;
278 FrameStatsHistory _frameStatsHistory;
282 friend class testing::RunnerTestAccess;
Drives host updates, fixed-step simulation, and rendering for a Scene.
Scene & scene()
Returns the Scene driven by this Runner.
State
Runner lifecycle states.
void timeScale(double value)
Changes the scale applied to elapsed host time for automatic simulation stepping.
double timeStep() const
Returns the fixed simulation step duration in seconds.
void updateCallback(UpdateCallback callback)
Replaces the host update callback; an empty callback disables it.
void start()
Starts the Runner using the current monotonic time.
double timeScale() const
Returns the scale applied to elapsed host time for automatic simulation stepping.
void requestSimulationStep()
Queues one fixed-duration simulation step while paused.
void maxCatchUpSteps(std::uint32_t value)
Changes the maximum number of automatic catch-up steps per host update.
std::uint32_t maxCatchUpSteps() const
Returns the maximum number of automatic catch-up steps permitted per host update.
Runner(Scene &scene, SimulationConfig config={})
Creates an idle Runner for scene.
void resetSimulation()
Resets simulation progression without changing scheduling settings.
std::function< void(Runner &runner, const UpdateInfo &info)> UpdateCallback
Callback invoked near the beginning of each host update.
bool update()
Performs one host update using the current monotonic time.
bool simulationPaused() const
Returns true when automatic simulation stepping is paused.
State state() const
Returns the current Runner lifecycle state.
void simulationPaused(bool paused)
Pauses or resumes automatic simulation stepping.
void stop()
Permanently stops the Runner and clears pending requested steps.
const Scene & scene() const
Returns the Scene driven by this Runner.
std::uint64_t simulationStepCount() const
Returns the total number of completed fixed simulation steps.
UpdateCallback updateCallback() const
Returns the currently installed host update callback.
double simulationTime() const
Returns total simulated time in seconds completed by fixed simulation steps.
void timeStep(double value)
Changes the fixed simulation step duration.
Owns a scene graph and the worlds used to simulate and render it.
Timing information supplied to each host update callback.
std::uint64_t updateIndex
Zero-based Runner update index.
double deltaTime
Monotonic seconds since the previous update's start.
double elapsedTime
Monotonic seconds since start(), sampled at this update's start.
Initial simulation scheduling parameters supplied to a Runner.