AcresCommandTiming.h#
Acres/Source/Acres/AcresCommandTiming.h Generated
When a controller's commands reach the physics: each message applies at the physics step that matches the time it arrived (pure C++, no Unreal objects).
The game reads the controller's sockets once per rendered frame, and one frame advances the physics by the frame's time up to MaxPhysicsDeltaTime (0.1 s, 12 steps of 1/120 s). Applied as they are read, all the messages of a long frame reach its first step and the other steps see none, so a controller sending at 50 Hz looks silent for most of the frame, and the drive-by-wire command timeout (0.1 s, AcresUtvModel.h) trips although the controller never stopped; on the vehicle it trips only when the controller goes silent. Here a receiver thread stamps every message with its arrival time on the wall clock; at each read the wall-clock interval since the previous read is mapped linearly onto the solver-time interval the frame advances, and the message is queued at its point in it. The first physics step that starts at or after that time takes it, so a long frame's steps see the commands in the order and at the spacing they arrived. A frame the physics keeps up with maps one to one; a frame the MaxPhysicsDeltaTime clamp shortens compresses its messages by the same factor as it compresses the vehicle's motion. In lockstep (AcresSimControl.h) every command applies at the next step, as the step request expects, so stepping stays deterministic.
The queue keeps whole-state snapshots (the drive-by-wire inbox with its per-subsystem sequence numbers, the bridge driver's controls): a step that takes several keeps the latest, and a snapshot queued for the same step as the one before it replaces it, which is what that step would take anyway.
| Name | Type | Unit | Default | Description |
|---|---|---|---|---|
ApplyAtNextStep |
inline constexpr double |
Queue time of a command that applies at the next physics step, whatever its time. | ||
CommandDueToleranceS |
inline constexpr double |
s | .002 |
How much earlier than a step's start a command may be due and still apply at that step, s: the physics step's solver time arrives as a float (Unreal's AsyncPhysicsTickActor), which rounds by up to 0.5 ms after 2 hours; a quarter of a 1/120 s step. |
FCommandClock#
Maps the wall-clock arrival time of a controller message to the solver time of the physics step that first sees it.
One BeginRead per read of the transports (once per game frame, before the messages read are handled), then ApplyAt for each message. Game thread.
FCommandClock::BeginRead#
Starts one read.
| Argument | Description |
|---|---|
WallS |
Wall clock now, s (the clock of the arrival stamps). |
SimS |
Solver time the physics has been given so far, s: this frame's steps start there. |
FrameSimS |
Solver time this frame advances, s: the frame's time clamped to MaxPhysicsDeltaTime (0 while the world is paused). |
bNextStep |
Every message of this read applies at the next step (lockstep, or no fixed-step solver clock). |
FCommandClock::ApplyAt#
Solver time at which a message that arrived at ArrivalWallS applies, s: its place in the wall-clock interval since the previous read, scaled onto this frame's solver interval. ApplyAtNextStep in bNextStep mode and at the first read (no interval yet).
TTimedCommands#
Snapshots of a command state, each with the solver time it applies at.
Push on the producer side and Take on the physics step, both under the caller's lock.
TTimedCommands::Push#
Queues a snapshot.
| Argument | Description |
|---|---|
AtS |
Solver time it applies at, s (ApplyAtNextStep: the next step). A snapshot never applies before the one queued ahead of it: an earlier time is raised to that one's, and then it replaces it. |
Value |
The state from then on. |
TTimedCommands::Take#
Takes the snapshots due at a physics step.
| Argument | Description |
|---|---|
StepStartS |
Solver time at the step's start, s. |
Out |
Set to the latest snapshot due, when there is one. |
Returns: True if a snapshot was due (Out changed).
TTimedCommands::Clear#
Drops every queued snapshot.
TTimedCommands::Num#
Snapshots waiting.