#5 - fixed interpolation & rollback

This commit is contained in:
Martin Slachta
2026-08-05 15:20:56 +02:00
parent 2e95c941ba
commit 0e639abcd2
14 changed files with 243 additions and 40 deletions
@@ -23,7 +23,7 @@ class WorldStateWriter {
public:
explicit WorldStateWriter(BinaryBuffer& buf) noexcept : m_w(buf) {}
void begin(uint32_t frame_idx, uint32_t message_type) noexcept {
void begin(uint32_t frame_idx, uint32_t tick_idx, uint32_t message_type) noexcept {
m_entity_count = 0;
// message_type — lets the receiver dispatch without peeking further
@@ -35,6 +35,10 @@ public:
// frame_idx
m_w.encode<uint32_t>(frame_idx);
// tick_idx — counts the states that went out, so the receiver can tell
// a late one from a new one. Says nothing about the frame answered.
m_w.encode<uint32_t>(tick_idx);
// entity_count placeholder — patched when end() is called
m_entity_count_offset = m_w.reserve_u32();
}
@@ -85,6 +89,7 @@ public:
struct WorldStateHeader {
uint32_t packet_type;
uint32_t frame_idx;
uint32_t tick_idx;
uint32_t entity_count;
};
@@ -109,10 +114,11 @@ public:
explicit WorldStateReader(std::span<const std::byte> data) noexcept
: m_r(data) {}
/** Read the 12-byte header. Must be called first. */
/** Read the header. Must be called first. */
WorldStateHeader read_header() noexcept {
// m_header.packet_type = m_r.decode<uint32_t>();
m_header.frame_idx = m_r.decode<uint32_t>();
m_header.tick_idx = m_r.decode<uint32_t>();
m_header.entity_count = m_r.decode<uint32_t>();
// spawn count follows immediately