160 std::variant<SpawnEvent, DestroyEvent, DeathEvent, PlayerJoinedEvent, PlayerLeftEvent>;
171[[nodiscard]] std::vector<std::vector<std::byte>>
write_events(std::span<const GameEvent> events);
180[[nodiscard]] std::optional<GameEvent>
read_event(std::span<const std::byte> bytes);
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
LeaveReason
Why a player left the game, in PlayerLeft.
Definition events.hpp:49
@ Left
It quit: Logout, Disconnect, or its TCP connection closed.
@ TimedOut
No valid datagram for too long, or no event acknowledged (RFC section 5.5).
@ Kicked
A protocol error ended its session (RFC section 3.2).
std::vector< std::vector< std::byte > > write_events(std::span< const GameEvent > events)
Encodes events with write_event(), for ServerNetwork::send_events().
std::variant< SpawnEvent, DestroyEvent, DeathEvent, PlayerJoinedEvent, PlayerLeftEvent > GameEvent
One of the gameplay events the server sends.
Definition events.hpp:160
DestroyReason
Why an entity was destroyed, which tells the client what to show.
Definition events.hpp:36
@ Consumed
A missile that hit its target: it vanishes.
@ Despawned
It left the play area: no effect.
@ Killed
It was destroyed: an explosion.
std::vector< std::byte > write_event(const GameEvent &event)
Encodes an event as the bytes of RFC section 4.4: type, tick, then its fields.
constexpr std::size_t spawn_event_size
Size of a Spawn event, type and tick included.
Definition events.hpp:62
constexpr std::size_t player_left_event_size
Size of a PlayerLeft event, type and tick included.
Definition events.hpp:68
EventType
Type of an event, its first byte (RFC section 4.4).
Definition events.hpp:19
@ Destroy
An entity disappears.
@ Spawn
An entity appears; a missile's is also its shot.
@ Death
A player lost a life.
@ PlayerLeft
A player left the game.
@ GameOver
No player has lives left.
@ PlayerJoined
A player joined the game.
std::optional< GameEvent > read_event(std::span< const std::byte > bytes)
Decodes the bytes of one event, as a client does (RFC section 6.4).
constexpr std::size_t destroy_event_size
Size of a Destroy event, type and tick included.
Definition events.hpp:64
constexpr std::uint8_t no_player
Player number meaning "no player", as the owner of an enemy.
Definition events.hpp:59
constexpr std::size_t death_event_size
Size of a Death event, type and tick included.
Definition events.hpp:66
Snapshots of the world sent to the clients (RFC section 4.3).
A player lost a life where its ship was.
Definition events.hpp:113
float x
Position of the ship when it was hit, in logical pixels.
Definition events.hpp:121
bool operator==(const DeathEvent &) const =default
Field-by-field equality.
std::uint8_t player
Player number, 0 to 3.
Definition events.hpp:117
float y
Position of the ship when it was hit, in logical pixels.
Definition events.hpp:123
std::uint32_t tick
Server tick of the death.
Definition events.hpp:115
std::uint8_t lives
Lives left; 0 means the player is out, and a Destroy of its ship follows.
Definition events.hpp:119
An entity disappears, at its last position.
Definition events.hpp:95
bool operator==(const DestroyEvent &) const =default
Field-by-field equality.
std::uint32_t tick
Server tick at which it disappeared.
Definition events.hpp:97
float x
Last position of its center, in logical pixels.
Definition events.hpp:103
float y
Last position of its center, in logical pixels.
Definition events.hpp:105
DestroyReason reason
Why, which tells the client what to show.
Definition events.hpp:101
A player joined the game.
Definition events.hpp:131
bool operator==(const PlayerJoinedEvent &) const =default
Field-by-field equality.
std::string name
Name given at login, valid as valid_player_name() says.
Definition events.hpp:137
std::uint32_t tick
Server tick at which it joined.
Definition events.hpp:133
std::uint8_t player
Player number, 0 to 3.
Definition events.hpp:135
A player left the game; the Destroy of its ship follows if it had one.
Definition events.hpp:145
bool operator==(const PlayerLeftEvent &) const =default
Field-by-field equality.
std::uint8_t player
Player number, 0 to 3.
Definition events.hpp:149
std::uint32_t tick
Server tick at which it left.
Definition events.hpp:147
LeaveReason reason
Why it left.
Definition events.hpp:151
An entity appears, with its kind, position and velocity.
Definition events.hpp:71
float vy
Velocity, in logical pixels per second.
Definition events.hpp:85
float y
Position of its center, in logical pixels.
Definition events.hpp:81
float vx
Velocity, in logical pixels per second.
Definition events.hpp:83
bool operator==(const SpawnEvent &) const =default
Field-by-field equality.
std::uint8_t owner
Player it belongs to (a ship's player, a missile's shooter), or no_player.
Definition events.hpp:87
float x
Position of its center, in logical pixels.
Definition events.hpp:79
std::uint8_t kind
Kind, an EntityKind value.
Definition events.hpp:77
std::uint32_t tick
Server tick at which it appeared.
Definition events.hpp:73