vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::NetInterpolation Class Reference

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.

Detailed Description

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.

Member Function Documentation

◆ record()

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.

Parameters
entityThe entity described; a new occupant of a tracked slot starts a fresh track.
tickThe server tick the snapshot names.
positionWhere the snapshot put it.
rotationHow the snapshot turned it.

◆ heard()

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.

Parameters
tickThe server tick the snapshot's header names.
tickRateTicks a second, to turn ticks into time.

◆ delayTicks()

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.

Parameters
tickRateSimulation ticks a second.
snapshotRateSnapshots a second.
Returns
The delay, in ticks.

◆ restoreConfirmed()

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.

Parameters
sceneWorld the snapshot is about to be read into.

◆ apply()

void Vkm::Engine::NetInterpolation::apply ( Scene & scene,
float deltaTime,
float tickRate,
float snapshotRate )

Move every tracked entity to where it was, a moment ago.

Parameters
sceneWorld to write into.
deltaTimeReal seconds since the last frame.
tickRateTicks a second.
snapshotRateSnapshots a second, the delay's unit.

◆ hold()

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.

Parameters
entityThe body this end has taken over or given back.
heldTrue to stop drawing it late, false to resume.

◆ renderTick()

double Vkm::Engine::NetInterpolation::renderTick ( ) const
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.

Returns
The render clock, in server ticks.

◆ behindTicks()

float Vkm::Engine::NetInterpolation::behindTicks ( ) const
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.

Returns
Ticks behind, or zero before anything has arrived.

Member Data Documentation

◆ SNAPSHOTS_BEHIND

float Vkm::Engine::NetInterpolation::SNAPSHOTS_BEHIND = 2.0f
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.

◆ HISTORY

size_t Vkm::Engine::NetInterpolation::HISTORY = 8
staticconstexpr

Samples kept per entity.

Enough to cross a lost packet or two; past that a body is better snapped than guessed at.

◆ MAX_SNAPSHOTS_BEHIND

float Vkm::Engine::NetInterpolation::MAX_SNAPSHOTS_BEHIND = static_cast<float>(HISTORY) / 2.0f
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.


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