group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
RegistrySerialization.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
7#include "entt/entity/fwd.hpp"
8
9#include <entt/entt.hpp>
10#include <optional>
11#include <vector>
12
15{
16
19{
20 entt::entity entity{entt::null};
22};
23
27std::vector<uint8_t> serialize(const entt::registry& registry);
28
29// ── PR-10 (server-perf): snapshot delta encoding ────────────────────────
30//
31// Two helpers pair to give a simple bytewise diff against a prior
32// snapshot. Format:
33// [skip:u32] [copy:u32] [copy_bytes : u8 × copy] (repeated until output
34// covers `current.size()`)
35// The decoder walks the same triples, copying `skip` bytes from the
36// baseline and `copy` bytes from the patch into the output buffer.
37//
38// Caller contract: only emit a delta when `baseline.size() ==
39// current.size()`. Different sizes mean the entt entity-list section
40// shifted; the sequential skip/copy form would mis-align. Server
41// falls back to a full snapshot in that case.
42//
43// `encodeDelta` returns the patch bytes only — callers prepend the
44// `[currentTick:u32] [fromTick:u32] [size:u32]` wire header outside.
45
56std::vector<uint8_t> encodeDelta(const std::vector<uint8_t>& baseline, const std::vector<uint8_t>& current);
57
67std::vector<uint8_t>
68applyDelta(const std::vector<uint8_t>& baseline, const uint8_t* patch, std::size_t patchSize, std::size_t outputSize);
69
71class Loader
72{
73public:
76 explicit Loader(entt ::registry& registry) : registry(registry), loader(registry) {}
77
90 void apply(const uint8_t* data,
91 size_t size,
92 std::optional<entt::entity> localPlayerServerEntity = std::nullopt,
93 uint32_t* outServerAckedClientTick = nullptr);
94
98 [[nodiscard]] entt::entity map(entt::entity e) const;
99
100private:
101 entt::registry& registry;
102 entt::continuous_loader loader;
103};
104
105} // namespace registry_serialization
Per-tick player input snapshot for networking and prediction.
entt::entity map(entt::entity e) const
Map a server-side entity ID to its local equivalent.
Definition RegistrySerialization.cpp:354
void apply(const uint8_t *data, size_t size, std::optional< entt::entity > localPlayerServerEntity=std::nullopt, uint32_t *outServerAckedClientTick=nullptr)
Apply a serialized registry snapshot to the local registry.
Definition RegistrySerialization.cpp:298
Loader(entt ::registry &registry)
Construct a Loader bound to the given registry.
Definition RegistrySerialization.hpp:76
entt::registry & registry
Definition RegistrySerialization.hpp:101
entt::continuous_loader loader
Definition RegistrySerialization.hpp:102
Utilities for serializing and deserializing the ECS registry over the network.
Definition RegistrySerialization.cpp:127
std::vector< uint8_t > serialize(const entt::registry &registry)
Serialize the full registry state into a byte buffer for transmission.
Definition RegistrySerialization.cpp:261
std::vector< uint8_t > encodeDelta(const std::vector< uint8_t > &baseline, const std::vector< uint8_t > &current)
Compute an RLE byte-diff patch from baseline to current.
Definition RegistrySerialization.cpp:177
std::vector< uint8_t > applyDelta(const std::vector< uint8_t > &baseline, const uint8_t *patch, std::size_t patchSize, std::size_t outputSize)
Reconstruct current from baseline + patch.
Definition RegistrySerialization.cpp:224
One tick of player input, stamped with the tick it was sampled on.
Definition InputSnapshot.hpp:19
A paired entity ID and input snapshot received from a remote client.
Definition RegistrySerialization.hpp:19
InputSnapshot input
Definition RegistrySerialization.hpp:21
entt::entity entity
Definition RegistrySerialization.hpp:20