4#include <unordered_map>
8#include <glm/gtc/quaternion.hpp>
10#include "ecs/entity.h"
11#include "net/prediction/sample_track.h"
13namespace Vkm::Engine {
25class NetInterpolation {
55 "the least delay has to fit the samples kept"
59 NetInterpolation() =
default;
60 ~NetInterpolation() =
default;
62 NetInterpolation(
const NetInterpolation& other) =
delete;
63 NetInterpolation& operator=(
const NetInterpolation& other) =
delete;
65 NetInterpolation(NetInterpolation && other) =
delete;
66 NetInterpolation& operator=(NetInterpolation && other) =
delete;
80 void record(
EntityId entity, uint32_t tick,
const glm::vec3& position,
const glm::quat& rotation);
93 void heard(uint32_t tick,
float tickRate);
125 void apply(
Scene& scene,
float deltaTime,
float tickRate,
float snapshotRate);
145 size_t tracked()
const {
return m_tracks.size(); }
167 return m_started ?
static_cast<float>(
static_cast<double>(m_newestTick) - m_renderTick) : 0.0f;
179 bool isPosed(uint32_t slot)
const {
return slot < m_posed.size() && m_posed[slot]; }
182 void heardOf(uint32_t tick);
185 std::unordered_map<uint32_t, Track> m_tracks;
188 std::vector<bool> m_posed;
190 double m_renderTick = 0.0;
191 uint32_t m_newestTick = 0;
192 bool m_started =
false;
194 double m_seconds = 0.0;
195 double m_heardAt = 0.0;
196 uint32_t m_heardTick = 0;
197 float m_jitter = 0.0f;
198 bool m_heardAny =
false;
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.
bool started() const
Whether a snapshot has been heard, so the render clock runs.
Definition interpolation.h:157
static constexpr float SNAPSHOTS_BEHIND
The least that is drawn behind the newest news, in snapshots.
Definition interpolation.h:34
static constexpr float MAX_SNAPSHOTS_BEHIND
The most that is drawn behind the newest news, in snapshots, however badly the link jitters.
Definition interpolation.h:51
static constexpr size_t HISTORY
Samples kept per entity.
Definition interpolation.h:42
void restoreConfirmed(Scene &scene)
Put the confirmed transform back, for the entities that have one.
double renderTick() const
Where the clock that decides what is drawn currently stands, in ticks.
Definition interpolation.h:154
float behindTicks() const
How far behind the newest news it is drawing, in ticks.
Definition interpolation.h:166
void hold(EntityId entity, bool held)
Stop drawing entity late, without forgetting where it was.
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 forget(EntityId entity)
Stop tracking entity, for one that left the world.
void apply(Scene &scene, float deltaTime, float tickRate, float snapshotRate)
Move every tracked entity to where it was, a moment ago.
Central registry managing entities and an open set of component types.
Definition scene.h:29
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23
A short history of where one entity was, kept by tick.
Definition sample_track.h:19