5#include <unordered_set>
9#include "BigEndian.hpp"
10#include "EntityPayload.hpp"
11#include "PayloadCodec.hpp"
12#include "Position.hpp"
14#include "config/NetworkConfig.hpp"
15#include "protocol/MessageHeader.hpp"
17namespace rtype::protocol {
57 "SnapshotHeader must not contain padding");
59 sizeof(
be32) +
sizeof(std::uint8_t) +
sizeof(
be16) * 3,
60 "SnapshotEntityState must not contain padding");
93 for (
const auto &state : payload.
entities) {
118 std::vector<SnapshotEntityState> states(count);
119 std::unordered_set<std::uint32_t> ids;
122 for (
auto &state : states) {
126 if (state.networkId.get() == 0 || !ids.insert(state.networkId.get()).second)
131 payload.
entities = std::move(states);
Bounds checked reader of big-endian values over a byte buffer.
Definition PacketReader.hpp:15
std::size_t getRemaining() const
Returns the number of bytes left to read.
Definition PacketReader.cpp:67
Growable buffer of big-endian values, capped at MAX_PAYLOAD_SIZE.
Definition PacketWriter.hpp:16
constexpr std::size_t MAX_MESSAGE_SIZE
Room left for messages after the packet header, in bytes.
Definition NetworkConfig.hpp:22
bool readPayload(PacketReader &reader, T &payload)
Reads the raw bytes of a padding free payload struct.
Definition PayloadCodec.hpp:38
bool writePayload(PacketWriter &writer, const T &payload)
Appends the raw bytes of a padding free payload struct.
Definition PayloadCodec.hpp:24
BigEndian< std::uint16_t > be16
16-bit unsigned integer stored in big-endian order.
Definition BigEndian.hpp:85
bool readSnapshot(PacketReader &reader, SnapshotPayload &payload)
Decodes and validates a snapshot.
Definition SnapshotPayload.hpp:106
BigEndian< std::uint32_t > be32
32-bit unsigned integer stored in big-endian order.
Definition BigEndian.hpp:87
constexpr std::size_t SNAPSHOT_MAX_ENTITIES
Largest number of entity states that fit in one Snapshot message.
Definition SnapshotPayload.hpp:63
bool writeSnapshot(PacketWriter &writer, const SnapshotPayload &payload)
Encodes a snapshot.
Definition SnapshotPayload.hpp:82
constexpr T get() const
Returns the value in host byte order.
Definition BigEndian.hpp:76
State of one entity inside a Snapshot message, 11 bytes.
Definition SnapshotPayload.hpp:48
be16 rotation
Rotation, fraction of a full turn.
Definition SnapshotPayload.hpp:53
be16 positionX
Horizontal position, fixed point encoded.
Definition SnapshotPayload.hpp:51
std::uint8_t entityType
Low 8 bits of the archetype id.
Definition SnapshotPayload.hpp:50
be16 positionY
Vertical position, fixed point encoded.
Definition SnapshotPayload.hpp:52
be32 networkId
Identifier of the entity.
Definition SnapshotPayload.hpp:49
Decoded Snapshot message: a SnapshotHeader followed by entityCount SnapshotEntityState records.
Definition SnapshotPayload.hpp:71
be32 serverTick
Server tick the states belong to.
Definition SnapshotPayload.hpp:72
std::vector< SnapshotEntityState > entities
Entity states.
Definition SnapshotPayload.hpp:73