5#include "BigEndian.hpp"
8namespace rtype::protocol {
80 "CreateEntityPayload must not contain padding");
83 "DestroyEntityPayload must not contain padding");
85 "QueryEntityPayload must not contain padding");
103 static_cast<std::uint8_t
>(payload.
reason) <=
127 std::uint32_t networkId,
128 std::uint16_t entityType,
130 float rotation = 0.0f) {
131 return {serverTick, networkId, entityType,
143 std::uint32_t networkId,
145 return {serverTick, networkId, reason};
CreateEntityPayload createEntityPayload(std::uint32_t serverTick, std::uint32_t networkId, std::uint16_t entityType, float x, float y, float rotation=0.0f)
Builds a CreateEntity payload from world values.
Definition EntityPayload.hpp:126
constexpr bool isValid(const DisconnectPayload &payload)
Checks that the reason is a known value.
Definition DisconnectPayload.hpp:41
BigEndian< std::uint16_t > be16
16-bit unsigned integer stored in big-endian order.
Definition BigEndian.hpp:85
be16 encodePosition(float position)
Encodes a position as a 16-bit fixed point value.
Definition Position.hpp:33
BigEndian< std::uint32_t > be32
32-bit unsigned integer stored in big-endian order.
Definition BigEndian.hpp:87
DestroyEntityPayload destroyEntityPayload(std::uint32_t serverTick, std::uint32_t networkId, DestroyReason reason)
Builds a DestroyEntity payload.
Definition EntityPayload.hpp:142
be16 encodeRotation(float radians)
Encodes an angle as a fraction of a full turn on 16 bits.
Definition Position.hpp:59
DestroyReason
Reason carried by a DestroyEntity message.
Definition EntityPayload.hpp:20
std::uint32_t NetworkEntityId
Server assigned identifier of a replicated entity, 0 means no entity.
Definition EntityPayload.hpp:15
@ GameEnded
The game is over.
@ Collision
Removed by gameplay, such as a hit.
@ OutOfBounds
Left the playable area.
@ PlayerDisconnected
Owner of the ship left the game.
@ Unknown
No specific reason.
constexpr T get() const
Returns the value in host byte order.
Definition BigEndian.hpp:76
Payload of a CreateEntity message, 16 bytes, sent by the server to spawn an entity on a client.
Definition EntityPayload.hpp:41
be16 positionY
Vertical position, fixed point encoded.
Definition EntityPayload.hpp:46
be16 entityType
Archetype id of the entity blueprint.
Definition EntityPayload.hpp:44
be32 serverTick
Server tick at sending time.
Definition EntityPayload.hpp:42
be16 positionX
Horizontal position, fixed point encoded.
Definition EntityPayload.hpp:45
be32 networkId
Identifier of the new entity.
Definition EntityPayload.hpp:43
be16 rotation
Rotation, fraction of a full turn.
Definition EntityPayload.hpp:47
Payload of a DestroyEntity message, 9 bytes, sent by the server to remove an entity from a client.
Definition EntityPayload.hpp:60
be32 networkId
Identifier of the removed entity.
Definition EntityPayload.hpp:62
DestroyReason reason
Why the entity is removed.
Definition EntityPayload.hpp:63
be32 serverTick
Server tick at sending time.
Definition EntityPayload.hpp:61
Payload of a QueryEntity message, 4 bytes, sent by a client that received a snapshot for an entity it...
Definition EntityPayload.hpp:74
be32 networkId
Identifier of the unknown entity.
Definition EntityPayload.hpp:75