vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
rewind.h
1#pragma once
2
3#include <cstdint>
4#include <unordered_map>
5
6#include <glm/glm.hpp>
7#include <glm/gtc/quaternion.hpp>
8
9#include "ecs/entity.h"
10#include "net/prediction/sample_track.h"
11
12namespace Vkm::Engine {
13
21class NetRewind {
22 public:
29 static constexpr size_t HISTORY_TICKS = 64;
30
31 public:
32 NetRewind() = default;
33 ~NetRewind() = default;
34
35 NetRewind(const NetRewind& other) = delete;
36 NetRewind& operator=(const NetRewind& other) = delete;
37
38 NetRewind(NetRewind && other) = delete;
39 NetRewind& operator=(NetRewind && other) = delete;
40
41 public:
43 void record(EntityId entity, uint32_t tick, const glm::vec3& position, const glm::quat& rotation);
44
57 bool poseAt(EntityId entity, double tick, glm::vec3& position, glm::quat& rotation) const;
58
66 void forget(EntityId entity);
67
68 void clear() { m_tracks.clear(); }
69
70 size_t tracked() const { return m_tracks.size(); }
71
72 private:
73 std::unordered_map<uint32_t, SampleTrack<HISTORY_TICKS>> m_tracks;
74};
75
76} // namespace Vkm::Engine
void record(EntityId entity, uint32_t tick, const glm::vec3 &position, const glm::quat &rotation)
Remember where entity was on tick, in the server's own clock.
bool poseAt(EntityId entity, double tick, glm::vec3 &position, glm::quat &rotation) const
Where entity was at tick, which may fall between two.
void forget(EntityId entity)
Forget entity, for a seat changing hands.
static constexpr size_t HISTORY_TICKS
Ticks of history kept per player.
Definition rewind.h:29
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23