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);
92 void heard(uint32_t tick,
float tickRate);
124 void apply(
Scene& scene,
float deltaTime,
float tickRate,
float snapshotRate);
144 size_t tracked()
const {
return m_tracks.size(); }
163 return m_started ?
static_cast<float>(
static_cast<double>(m_newestTick) - m_renderTick) : 0.0f;
175 bool isPosed(uint32_t slot)
const {
return slot < m_posed.size() && m_posed[slot]; }
178 std::unordered_map<uint32_t, Track> m_tracks;
181 std::vector<bool> m_posed;
183 double m_renderTick = 0.0;
184 uint32_t m_newestTick = 0;
185 bool m_started =
false;
187 double m_seconds = 0.0;
188 double m_heardAt = 0.0;
189 uint32_t m_heardTick = 0;
190 float m_jitter = 0.0f;
191 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.
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:153
float behindTicks() const
How far behind the newest news it is drawing, in ticks.
Definition interpolation.h:162
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