![]() |
vkmEngine 1.0.0
A C++ game engine · vkmengine.com
|
Draws entities this end is only told about, between what it was told. More...
#include <interpolation.h>
Public Member Functions | |
| void | record (EntityId entity, uint32_t tick, const glm::vec3 &position, const glm::quat &rotation) |
Record where the authority says entity is, as of tick. | |
| void | heard (uint32_t tick, float tickRate) |
Note that a snapshot of tick has arrived, now. | |
| float | delayTicks (float tickRate, float snapshotRate) const |
| How far behind the newest news to draw, in ticks. | |
| void | restoreConfirmed (Scene &scene) |
| Put the confirmed transform back, for the entities that have one. | |
| void | apply (Scene &scene, float deltaTime, float tickRate, float snapshotRate) |
| Move every tracked entity to where it was, a moment ago. | |
| void | hold (EntityId entity, bool held) |
Stop drawing entity late, without forgetting where it was. | |
| void | forget (EntityId entity) |
Stop tracking entity, for one that left the world. | |
| double | renderTick () const |
| Where the clock that decides what is drawn currently stands, in ticks. | |
| float | behindTicks () const |
| How far behind the newest news it is drawing, in ticks. | |
Static Public Attributes | |
| static constexpr float | SNAPSHOTS_BEHIND = 2.0f |
| The least that is drawn behind the newest news, in snapshots. | |
| static constexpr size_t | HISTORY = 8 |
| Samples kept per entity. | |
| static constexpr float | MAX_SNAPSHOTS_BEHIND = static_cast<float>(HISTORY) / 2.0f |
| The most that is drawn behind the newest news, in snapshots, however badly the link jitters. | |
Draws entities this end is only told about, between what it was told.
Most frames bring no snapshot, so drawing the newest would move in steps. Instead a client draws a moment slightly behind the newest, with data on both sides of it, at the cost of showing the world a little late. The entity a client owns is predicted, never interpolated.
| void Vkm::Engine::NetInterpolation::record | ( | EntityId | entity, |
| uint32_t | tick, | ||
| const glm::vec3 & | position, | ||
| const glm::quat & | rotation ) |
Record where the authority says entity is, as of tick.
With the transform as the snapshot left it, before any smoothing.
| entity | The entity described; a new occupant of a tracked slot starts a fresh track. |
| tick | The server tick the snapshot names. |
| position | Where the snapshot put it. |
| rotation | How the snapshot turned it. |
| void Vkm::Engine::NetInterpolation::heard | ( | uint32_t | tick, |
| float | tickRate ) |
Note that a snapshot of tick has arrived, now.
Once per snapshot. How far each arrival is off its due time is the jitter the delay grows to ride out; a fixed delay would run the clock into the newest sample and the world would pause.
| tick | The server tick the snapshot's header names. |
| tickRate | Ticks a second, to turn ticks into time. |
| float Vkm::Engine::NetInterpolation::delayTicks | ( | float | tickRate, |
| float | snapshotRate ) const |
How far behind the newest news to draw, in ticks.
One snapshot interval plus twice the measured jitter, clamped to SNAPSHOTS_BEHIND..MAX_SNAPSHOTS_BEHIND.
| tickRate | Simulation ticks a second. |
| snapshotRate | Snapshots a second. |
| void Vkm::Engine::NetInterpolation::restoreConfirmed | ( | Scene & | scene | ) |
Put the confirmed transform back, for the entities that have one.
Before a snapshot is applied: an absent component means "as last time", and left smoothed, the error would compound every snapshot.
| scene | World the snapshot is about to be read into. |
| void Vkm::Engine::NetInterpolation::apply | ( | Scene & | scene, |
| float | deltaTime, | ||
| float | tickRate, | ||
| float | snapshotRate ) |
Move every tracked entity to where it was, a moment ago.
| scene | World to write into. |
| deltaTime | Real seconds since the last frame. |
| tickRate | Ticks a second. |
| snapshotRate | Snapshots a second, the delay's unit. |
| void Vkm::Engine::NetInterpolation::hold | ( | EntityId | entity, |
| bool | held ) |
Stop drawing entity late, without forgetting where it was.
For a body this end now predicts; drawing it late too would fight the prediction. The track is kept as the only record of the server's last word, which may never be sent again: when the hold lifts, the body slides back to it.
| entity | The body this end has taken over or given back. |
| held | True to stop drawing it late, false to resume. |
|
inline |
Where the clock that decides what is drawn currently stands, in ticks.
A double: a float's spacing reaches half a tick at 2^22 ticks.
|
inline |
How far behind the newest news it is drawing, in ticks.
Where the clock actually stands; it is eased toward the delay, not set.
|
staticconstexpr |
The least that is drawn behind the newest news, in snapshots.
With one, a single lost packet leaves nothing to interpolate toward and the world stalls. Jitter grows the delay past this (delayTicks()). The snapshot rate sets what it costs in milliseconds.
|
staticconstexpr |
Samples kept per entity.
Enough to cross a lost packet or two; past that a body is better snapped than guessed at.
|
staticconstexpr |
The most that is drawn behind the newest news, in snapshots, however badly the link jitters.
Half of HISTORY, so samples either side of the moment drawn survive a further loss or two.