R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
rtype Namespace Reference

R-Type game code, built on the Aegis2D engine. More...

Namespaces

namespace  layer
 One bit per kind of entity, for ecs::Collider::layer and ecs::Collider::mask.
 
namespace  mask
 What each layer collides with.
 
namespace  tuning
 Values tuned for the game, in logical pixels, seconds and health points.
 

Classes

class  AdminConsole
 The commands of the server's administrator, on the engine's command system. More...
 
class  BanList
 The IP addresses that cannot log in, kept in a JSON file. More...
 
class  Bot
 A client without window nor sound: a ClientSession whose inputs are RandomInputs, or ScriptedInputs when its settings have a script. More...
 
struct  BotOptions
 Settings of a bot run, read from the command line. More...
 
struct  BotSettings
 What a bot needs to join a server. More...
 
struct  BotStats
 The link of one bot over its game, as the network benchmark reads it. More...
 
class  ChatLog
 The chat messages to show, newest last, each for shown_for. More...
 
struct  ChatMessage
 Content of a ChatMessage. More...
 
class  ChatRate
 The chat rate of one session (RFC section 3.8): a token bucket. More...
 
struct  ClientOptions
 Settings of a client run, read from the command line. More...
 
class  ClientSession
 The client side of a session (RFC section 3). More...
 
struct  ClientSettings
 What the client needs to join a server. More...
 
class  ClientWorld
 The world as the server describes it (RFC sections 4.3 to 4.5). More...
 
class  ConnectForm
 What the player types on the connect screen, checked before joining. More...
 
class  ConsoleInput
 The lines typed on a stream, read on a thread of their own, for the network thread to take between two updates. More...
 
struct  CreateRoomRequest
 Content of a CreateRoom. More...
 
struct  DeathEvent
 A player lost a life where its ship was. More...
 
struct  DeltaSnapshot
 One payload of a snapshot encoded against a baseline. More...
 
struct  DestroyEvent
 An entity disappears, at its last position. More...
 
struct  DraftEnemy
 An enemy of a wave, where and when the editor places it. More...
 
struct  DraftWave
 A wave of the editor. More...
 
class  DropReport
 Counts the datagrams dropped from each address, by reason, for a summary in the log at most every report_period per address (RFC section 6.7): a flood never becomes one log line per datagram. More...
 
struct  EditorPointer
 The mouse of a frame, in logical pixels of the screen. More...
 
struct  EditorView
 Where the editor draws the play area, shrunk to show the strip beyond its right edge where the enemies appear, and the timeline of the waves under it. More...
 
class  EnemyScripts
 The enemy types of a directory of Lua scripts, and the behaviors of their enemies. More...
 
struct  EnemyType
 Values of an enemy type, as its script gives them to enemy { ... }. More...
 
struct  EntityDelta
 What a delta snapshot says of one entity. More...
 
struct  EntityRecord
 What a snapshot says of an entity. More...
 
class  EventTracker
 Finds what changed in the game at each tick, as events. More...
 
class  GameInstance
 The one game of the server, with up to tuning::max_players players. More...
 
struct  GameRules
 How a game plays: the rules of its room, as the gameplay reads them. More...
 
class  GameServer
 Runs the games of its rooms for the players of its sockets, as r-type_server does. More...
 
struct  InputRecord
 One input of the player: the actions held at one tick of the client. More...
 
struct  InputScript
 A sequence of inputs, played in order, then again from the start. More...
 
class  Lagometer
 The last seconds of the network statistics, for the graphs of the lagometer. More...
 
struct  LagSample
 The figures of every graph at one time, in the unit of each graph. More...
 
struct  LevelDraft
 A waves file opened in the editor. More...
 
class  LevelEditor
 Places and moves the enemies of a wave with the mouse, and the waves in time. More...
 
struct  LoginAccepted
 Content of a LoginAccepted. More...
 
struct  LoginRequest
 Content of a LoginRequest. More...
 
class  NetworkStats
 Measures the loss and the jitter of the server's datagrams over a sliding window. More...
 
struct  NetworkSummary
 What the client received from the server over the last NetworkStats::window. More...
 
struct  PlayerJoinedEvent
 A player joined the game. More...
 
struct  PlayerLeftEvent
 A player left the game; the Destroy of its ship follows if it had one. More...
 
struct  PlayerNotice
 A message about a player, shown for a few seconds. More...
 
class  PlayerNotices
 Turns PlayerJoined and PlayerLeft events into messages for the players who stay. More...
 
struct  PlayerRecord
 What a snapshot says of a player. More...
 
struct  PlayerState
 What the game says of a player, for the snapshots. More...
 
class  PositionHistory
 The positions of the enemies over the last tuning::position_history_ticks ticks. More...
 
class  RandomInputs
 Random actions held for random times, like a player mashing the keys. More...
 
class  RateLimiter
 Counts the datagrams of each address in windows of one second. More...
 
struct  RateLimits
 Limits on the traffic of one IP address. More...
 
struct  RemotePlayer
 What the client knows of a player of the game. More...
 
struct  Replicated
 What the client knows of an entity of the server, next to its components. More...
 
class  Room
 One game of the server: its GameInstance, the Simulation thread that runs it, the EventTracker of what its clients learnt, and the names of its players. More...
 
class  RoomListForm
 What the player does on the room list screen. More...
 
struct  RoomPlayer
 A player of a room, as a RoomPlayers describes it. More...
 
struct  RoomPlayers
 Content of a RoomPlayers. More...
 
struct  RoomRecord
 A room, as a RoomList describes it. More...
 
struct  RoomRules
 How a room plays, chosen at its creation (CreateRoom, RFC section 3.6). More...
 
class  Scoreboard
 The max_entries best scores, best first, kept in a JSON file. More...
 
struct  ScoreEntry
 One score of the board. More...
 
struct  ScoreRecord
 One score of a ScoreList. More...
 
class  ScriptedInputs
 Plays an input script from the first call to update(), looping at its end. More...
 
struct  ScriptStep
 One line of an input script: actions held for a time. More...
 
class  ServerGame
 One R-Type game on the server: the world, its systems in order, and the players. More...
 
class  ServerNetwork
 The two ports the server listens on, and the TCP side of the sessions. More...
 
struct  ServerOptions
 Settings of a server run, read from the command line. More...
 
struct  Session
 A logged-in player (RFC section 3). More...
 
class  SessionTable
 The sessions of the server and the rooms they are in. More...
 
struct  ShipMotion
 Where a player ship is and how it moves, after a step. More...
 
class  ShipPrediction
 Where the client's own ship is, before the server says so. More...
 
class  Simulation
 Runs a GameInstance on its own thread, tuning::tick_rate times per second. More...
 
struct  Snapshot
 The state of the world at one tick. More...
 
class  SnapshotDecoder
 Rebuilds the snapshots of the server from the payloads of its Snapshot datagrams. More...
 
class  SnapshotHistory
 The last snapshots sent to one client, and the ones it acknowledged. More...
 
struct  SpawnEvent
 An entity appears, with its kind, position and velocity. More...
 
struct  Trail
 The latest positions of an entity, oldest first, to draw it between two of them. More...
 
struct  TrailPoint
 One position of an entity, as a snapshot (or its Spawn) gave it. More...
 
struct  WaveSpan
 When a wave plays, in seconds from the start of the waves. More...
 

Typedefs

using GameEvent = std::variant< SpawnEvent, DestroyEvent, DeathEvent, PlayerJoinedEvent, PlayerLeftEvent >
 One of the gameplay events the server sends.
 

Enumerations

enum class  ChatRejection : std::uint8_t { TooLong = 1 , BadText = 2 , TooFast = 3 }
 Why a chat message is not relayed, the reason of ChatRejected. More...
 
enum class  EntityChange : std::uint8_t { Updated = 0 , Added = 1 , Removed = 2 }
 What a delta snapshot says of an entity. More...
 
enum class  EntityField : std::uint8_t { X = 1U << 0U , Y = 1U << 1U , Velocity = 1U << 2U , Frame = 1U << 3U }
 Fields of an EntityChange::Updated record, one bit each. More...
 
enum class  EventType : std::uint8_t {
  Spawn = 1 , Destroy = 2 , Death = 3 , PlayerJoined = 4 ,
  PlayerLeft = 5 , GameOver = 6
}
 Type of an event, its first byte (RFC section 4.4). More...
 
enum class  DestroyReason : std::uint8_t { Despawned = 0 , Killed = 1 , Consumed = 2 , PlayerLeft = 3 }
 Why an entity was destroyed, which tells the client what to show. More...
 
enum class  LeaveReason : std::uint8_t { Left = 0 , TimedOut = 1 , Kicked = 2 }
 Why a player left the game, in PlayerLeft. More...
 
enum class  TcpKind : std::uint8_t {
  LoginRequest = 1 , LoginAccepted = 2 , LoginRejected = 3 , Logout = 4 ,
  ListRooms = 5 , RoomList = 6 , CreateRoom = 7 , RoomCreated = 8 ,
  RoomRejected = 9 , JoinRoom = 10 , RoomJoined = 11 , JoinRejected = 12 ,
  LeaveRoom = 13 , SetReady = 14 , RoomPlayers = 15 , GameStart = 16 ,
  ChatSend = 17 , ChatMessage = 18 , ChatRejected = 19 , ListScores = 20 ,
  ScoreList = 21
}
 First byte of every TCP message: what it is. More...
 
enum class  LoginRejection : std::uint8_t {
  ServerFull = 1 , BadVersion = 2 , BadName = 3 , NameTaken = 4 ,
  GameStarted = 5 , Banned = 6
}
 Why a login is refused, the reason of LoginRejected. More...
 
enum class  LogoutReason : std::uint8_t {
  Left = 0 , Shutdown = 1 , TimedOut = 2 , ProtocolError = 3 ,
  RoomClosed = 4 , Kicked = 5 , Banned = 6
}
 Why a session ends, the reason of Logout. More...
 
enum class  RoomState : std::uint8_t { Waiting = 0 , Playing = 1 }
 What a room is doing, the state of a RoomList record. More...
 
enum class  RoomRejection : std::uint8_t {
  NoRoomLeft = 1 , BadName = 2 , BadSize = 3 , BadLives = 4 ,
  BadDifficulty = 5 , UnknownWaves = 6 , BadFriendlyFire = 7
}
 Why a room is not created, the reason of RoomRejected. More...
 
enum class  Difficulty : std::uint8_t { Easy = 0 , Normal = 1 , Hard = 2 }
 How hard the enemies of a room are: how often they come and how much they take. More...
 
enum class  JoinRejection : std::uint8_t { NoSuchRoom = 1 , RoomFull = 2 , InGame = 3 }
 Why a room is not joined, the reason of JoinRejected. More...
 
enum class  EntityKind : std::uint8_t { PlayerShip = 1 , PlayerMissile = 2 , BydosSlave = 3 , EnemyMissile = 4 }
 Kind of an entity in snapshots and events (RFC section 4.1). More...
 
enum class  ServerCommand : std::uint8_t { Run , Help , Version }
 What the server was asked to do. More...
 
enum class  BindResult : std::uint8_t {
  Bound , AlreadyBound , UnknownSession , Taken ,
  NoRoom
}
 What SessionTable::bind() did with a Connect. More...
 
enum class  ClientCommand : std::uint8_t { Run , Help , Version }
 What the client was asked to do. More...
 
enum class  ClientState : std::uint8_t {
  Idle , Connecting , LoggingIn , Lobby ,
  InRoom , Binding , InGame , Failed ,
  Lost , Closed
}
 Where the client is in its session. More...
 
enum class  ConnectField : std::uint8_t { Host , Port , Name }
 A field of the connect screen. More...
 
enum class  LagGraph : std::uint8_t {
  Rtt , Jitter , Loss , Interval ,
  BytesIn , BytesOut , Corrections
}
 A graph of the lagometer. More...
 
enum class  LagLevel : std::uint8_t { Good , Warning , Bad }
 How a figure compares with a sound link. More...
 
enum class  BotCommand : std::uint8_t { Run , Help , Version }
 What the bot was asked to do. More...
 

Functions

std::filesystem::path default_enemies_directory ()
 Directory of the enemy scripts the server plays.
 
std::vector< std::string > enemy_types (const std::filesystem::path &directory=default_enemies_directory())
 The enemy types of a directory, as waves files name them.
 
aegis2d::Vec2 player_spawn (std::size_t slot)
 Where a player slot starts and respawns.
 
aegis2d::ecs::Entity spawn_player (aegis2d::ecs::Registry &registry, std::size_t slot)
 Creates the ship of a player.
 
aegis2d::ecs::Entity spawn_player_missile (aegis2d::ecs::Registry &registry, aegis2d::ecs::Entity shooter)
 Creates a missile fired by a player, in front of its ship.
 
aegis2d::ecs::Entity spawn_enemy_missile (aegis2d::ecs::Registry &registry, aegis2d::Vec2 position)
 Creates a missile fired by an enemy.
 
aegis2d::ecs::Entity fire_enemy_missile (aegis2d::ecs::Registry &registry, aegis2d::ecs::Entity shooter)
 Creates the missile an enemy fires, in front of it (on its left).
 
std::uint32_t rewind_ticks (std::chrono::nanoseconds rtt, std::chrono::nanoseconds interpolation) noexcept
 How many ticks back a player sees the enemies.
 
void find_rewound_contacts (aegis2d::ecs::Registry &registry, const PositionHistory &history, std::uint64_t tick, const std::function< std::uint32_t(aegis2d::ecs::Entity)> &rewind_of, std::vector< aegis2d::ecs::Contact > &contacts)
 Finds the contacts of the player missiles with the enemies as their shooters saw them.
 
aegis2d::Vec2 ship_velocity (aegis2d::ecs::PlayerInput input) noexcept
 Velocity of a player ship holding an input.
 
aegis2d::Vec2 keep_ship_in_area (aegis2d::Vec2 position) noexcept
 Keeps a player ship inside the play area.
 
ShipMotion step_ship (aegis2d::Vec2 position, aegis2d::ecs::PlayerInput input, float delta) noexcept
 Moves a player ship by one tick.
 
void steer_ships (aegis2d::ecs::Registry &registry, const aegis2d::ecs::Tick &tick)
 System that sets the velocity of every player ship from its input.
 
void keep_ships_in_area (aegis2d::ecs::Registry &registry, const aegis2d::ecs::Tick &tick)
 System that keeps every player ship inside the play area.
 
std::filesystem::path default_waves_file ()
 Waves file played by the server when none is given.
 
std::vector< std::string > waves_names (const std::filesystem::path &directory)
 The waves files of a directory, as a room names them (RFC section 3.6).
 
aegis2d::ecs::WaveSchedule load_waves (const std::filesystem::path &path, const std::vector< std::string > &types=enemy_types())
 Reads a waves file, accepting only the enemy types it is given.
 
std::string_view to_string (ChatRejection reason) noexcept
 Short name of a rejection, for logs.
 
std::optional< ChatRejection > check_chat_text (std::string_view text) noexcept
 Checks a text against the rules of ChatSend, the length first.
 
std::optional< std::string > read_chat_send (std::span< const std::byte > message)
 Reads a ChatSend.
 
std::optional< ChatMessage > read_chat_message (std::span< const std::byte > message)
 Reads a ChatMessage.
 
std::optional< std::uint8_t > read_chat_rejected (std::span< const std::byte > message) noexcept
 Reads a ChatRejected.
 
std::vector< std::byte > write_chat_send (std::string_view text)
 Encodes a ChatSend.
 
std::vector< std::byte > write_chat_message (const ChatMessage &message)
 Encodes a ChatMessage.
 
std::vector< std::byte > write_chat_rejected (ChatRejection reason)
 Encodes a ChatRejected.
 
std::int32_t quantize_position (float position) noexcept
 Rounds a position to the nearest 1/8 px, clamped to [position_min, position_max].
 
float dequantize_position (std::int32_t steps) noexcept
 Position of a number of steps.
 
std::int32_t quantize_velocity (float velocity) noexcept
 Rounds a velocity to the nearest whole pixel per second, clamped to [velocity_min, velocity_max].
 
void write_position (aegis2d::net::BitWriter &writer, float position)
 Writes a position on position_bits bits, see quantize_position().
 
std::optional< float > read_position (aegis2d::net::BitReader &reader) noexcept
 Reads a position written by write_position().
 
void write_velocity (aegis2d::net::BitWriter &writer, float velocity)
 Writes a velocity on velocity_bits bits, see quantize_velocity().
 
std::optional< float > read_velocity (aegis2d::net::BitReader &reader) noexcept
 Reads a velocity written by write_velocity().
 
void write_varint (aegis2d::net::BitWriter &writer, std::uint32_t value)
 Writes an id as a varint: groups of varint_group_bits bits, lowest first, each followed by a continuation bit set when another group follows.
 
std::optional< std::uint32_t > read_varint (aegis2d::net::BitReader &reader) noexcept
 Reads a varint written by write_varint().
 
std::size_t varint_bits (std::uint32_t value) noexcept
 Size of a varint.
 
EntityRecord quantized (const EntityRecord &entity) noexcept
 A record as the client gets it: position and velocity rounded as compact.hpp does, frame at most 15.
 
std::vector< std::vector< std::byte > > write_delta_snapshot (const Snapshot &snapshot, const Snapshot *baseline)
 Encodes a snapshot against a baseline, as the payloads of Snapshot datagrams.
 
std::optional< DeltaSnapshot > read_delta_snapshot (std::span< const std::byte > payload)
 Decodes one payload written by write_delta_snapshot().
 
std::optional< Snapshot > apply_delta (const Snapshot *baseline, std::span< const DeltaSnapshot > parts)
 Rebuilds a snapshot from its baseline and every payload of its tick.
 
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.
 
std::vector< std::vector< std::byte > > write_events (std::span< const GameEvent > events)
 Encodes events with write_event(), for ServerNetwork::send_events().
 
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 input_payload_size (std::size_t count) noexcept
 Size of the payload of an Input datagram carrying count inputs: the sequence of the newest, the count, then the actions of each.
 
std::vector< std::byte > write_inputs (std::span< const InputRecord > inputs)
 Encodes the payload of an Input datagram, header excluded.
 
std::optional< std::vector< InputRecord > > read_inputs (std::span< const std::byte > payload)
 Decodes the payload of an Input datagram.
 
std::string_view to_string (LoginRejection reason) noexcept
 Short name of a rejection, for logs.
 
bool valid_text (std::string_view text, std::size_t max_size) noexcept
 Tells whether a text is 1 to max_size bytes of valid UTF-8 without control characters, as player names and chat texts must be.
 
bool valid_player_name (std::string_view name) noexcept
 Tells whether a name follows the rules of LoginRequest.
 
std::optional< TcpKind > kind_of (std::span< const std::byte > message) noexcept
 Kind of a TCP message.
 
std::optional< LoginRequest > read_login_request (std::span< const std::byte > message)
 Reads a LoginRequest.
 
std::optional< LoginAccepted > read_login_accepted (std::span< const std::byte > message) noexcept
 Reads a LoginAccepted.
 
std::optional< std::uint8_t > read_login_rejected (std::span< const std::byte > message) noexcept
 Reads a LoginRejected.
 
std::optional< std::uint8_t > read_logout (std::span< const std::byte > message) noexcept
 Reads a Logout.
 
std::vector< std::byte > write_login_request (const LoginRequest &request)
 Encodes a LoginRequest.
 
std::vector< std::byte > write_login_accepted (const LoginAccepted &accepted)
 Encodes a LoginAccepted.
 
std::vector< std::byte > write_login_rejected (LoginRejection reason)
 Encodes a LoginRejected.
 
std::vector< std::byte > write_logout (LogoutReason reason)
 Encodes a Logout.
 
std::string_view to_string (RoomRejection reason) noexcept
 Short name of a rejection, for logs.
 
bool read_list_rooms (std::span< const std::byte > message) noexcept
 Tells whether a message is a well-formed ListRooms: its kind alone.
 
std::optional< std::vector< RoomRecord > > read_room_list (std::span< const std::byte > message)
 Reads a RoomList.
 
std::optional< CreateRoomRequest > read_create_room (std::span< const std::byte > message)
 Reads a CreateRoom.
 
std::optional< std::uint8_t > read_room_created (std::span< const std::byte > message) noexcept
 Reads a RoomCreated.
 
std::optional< std::uint8_t > read_room_rejected (std::span< const std::byte > message) noexcept
 Reads a RoomRejected.
 
std::string_view to_string (JoinRejection reason) noexcept
 Short name of a rejection, for logs.
 
std::optional< std::uint8_t > read_join_room (std::span< const std::byte > message) noexcept
 Reads a JoinRoom.
 
std::optional< std::pair< std::uint8_t, std::uint8_t > > read_room_joined (std::span< const std::byte > message) noexcept
 Reads a RoomJoined.
 
std::optional< std::uint8_t > read_join_rejected (std::span< const std::byte > message) noexcept
 Reads a JoinRejected.
 
bool read_leave_room (std::span< const std::byte > message) noexcept
 Tells whether a message is a well-formed LeaveRoom: its kind alone.
 
std::optional< bool > read_set_ready (std::span< const std::byte > message) noexcept
 Reads a SetReady.
 
std::optional< RoomPlayers > read_room_players (std::span< const std::byte > message)
 Reads a RoomPlayers.
 
bool read_game_start (std::span< const std::byte > message) noexcept
 Tells whether a message is a well-formed GameStart: its kind alone.
 
std::vector< std::byte > write_list_rooms ()
 Encodes a ListRooms.
 
std::vector< std::byte > write_room_list (std::span< const RoomRecord > rooms)
 Encodes a RoomList.
 
std::vector< std::byte > write_create_room (const CreateRoomRequest &request)
 Encodes a CreateRoom.
 
std::vector< std::byte > write_room_created (std::uint8_t room)
 Encodes a RoomCreated.
 
std::vector< std::byte > write_room_rejected (RoomRejection reason)
 Encodes a RoomRejected.
 
std::vector< std::byte > write_join_room (std::uint8_t room)
 Encodes a JoinRoom.
 
std::vector< std::byte > write_room_joined (std::uint8_t room, std::uint8_t player)
 Encodes a RoomJoined.
 
std::vector< std::byte > write_join_rejected (JoinRejection reason)
 Encodes a JoinRejected.
 
std::vector< std::byte > write_leave_room ()
 Encodes a LeaveRoom.
 
std::vector< std::byte > write_set_ready (bool ready)
 Encodes a SetReady.
 
std::vector< std::byte > write_room_players (const RoomPlayers &players)
 Encodes a RoomPlayers.
 
std::vector< std::byte > write_game_start ()
 Encodes a GameStart.
 
bool read_list_scores (std::span< const std::byte > message) noexcept
 Tells whether a message is a well-formed ListScores.
 
std::optional< std::vector< ScoreRecord > > read_score_list (std::span< const std::byte > message)
 Reads a ScoreList.
 
std::vector< std::byte > write_list_scores ()
 Encodes a ListScores.
 
std::vector< std::byte > write_score_list (std::span< const ScoreRecord > scores)
 Encodes a ScoreList.
 
std::size_t entity_record_bits (std::uint32_t id_gap) noexcept
 Size of an entity record.
 
std::vector< std::vector< std::byte > > write_snapshot (const Snapshot &snapshot)
 Encodes a snapshot as the payloads of Snapshot datagrams, header excluded.
 
std::optional< Snapshot > read_snapshot (std::span< const std::byte > payload)
 Decodes the payload of one Snapshot datagram.
 
GameRules game_rules (const RoomRules &rules) noexcept
 The gameplay of the rules a room was created with.
 
aegis2d::net::Endpoint address_of (const aegis2d::net::Endpoint &endpoint) noexcept
 The address of an endpoint, its port set to 0: the key of the limits.
 
std::variant< ServerOptions, std::string > parse_server_options (std::span< const std::string_view > args)
 Reads the command line of r-type_server.
 
bool install_stop_handlers ()
 Handles SIGINT and SIGTERM: the first one asks the server to stop cleanly (stop_requested() becomes true), a second one ends the process at once with forced_exit_status.
 
bool stop_requested () noexcept
 Tells whether a stop was asked by a signal. Thread-safe.
 
void request_stop () noexcept
 Asks the server to stop, as a first Ctrl+C does: stop_requested() becomes true.
 
std::optional< EntityKind > kind_of_layer (std::uint32_t layer) noexcept
 Kind of the entities of a collision layer, for snapshots and events.
 
constexpr bool snapshot_due (std::uint64_t tick) noexcept
 Tells whether a snapshot is due after a tick.
 
Snapshot take_snapshot (GameInstance &instance)
 Takes the state of the game, on the simulation thread.
 
std::string chat_rejection_text (std::uint8_t reason)
 Sentence telling why a message was not sent.
 
std::optional< std::uint16_t > parse_port (std::string_view text) noexcept
 Reads a TCP port, as --port and the connect screen take it.
 
std::variant< ClientOptions, std::string > parse_client_options (std::span< const std::string_view > args)
 Reads the command line of r-type_client.
 
std::string_view to_string (ClientState state) noexcept
 Short name of a state, for logs.
 
aegis2d::Vec2 interpolate (const Trail &trail, double tick) noexcept
 Position of an entity at a tick, between the positions of its trail.
 
LagSample measure_lag (const aegis2d::net::RttEstimator &rtt, const aegis2d::net::TrafficCounters &traffic, const NetworkStats &stats, std::chrono::steady_clock::time_point now)
 Reads the network statistics of the client into a sample.
 
LagLevel lag_level (LagGraph graph, double value) noexcept
 Level of a value of a graph: the RTT is bad above 200 ms, the loss above 5 %...
 
std::string lag_label (LagGraph graph, double value)
 Label of a value of a graph, for the overlay: "RTT 152 MS", "LOSS 2.5 %".
 
std::vector< std::string > lag_lines (const LagSample &sample)
 The figures of a sample as lines of the engine's metrics overlay, so that the frame metrics (F12) show the network too, with or without the lagometer (F6).
 
std::string left_message (const std::string &name, LeaveReason reason)
 Sentence telling why a player left.
 
std::vector< BotSettings > bot_team (const BotSettings &base, std::size_t count)
 The settings of count bots that play together, for --count.
 
std::variant< BotOptions, std::string > parse_bot_options (std::span< const std::string_view > args)
 Reads the command line of r-type_bot.
 
BotStats measure_bot (const Bot &bot, std::string name, std::chrono::steady_clock::duration played, std::chrono::steady_clock::time_point now)
 Reads what a bot measured, before it leaves.
 
std::string bot_stats_line (const BotStats &stats)
 One line of a --stats file, in the order of bot_stats_header, without its end.
 
std::variant< InputScript, std::string > parse_input_script (std::string_view text)
 Reads an input script.
 
std::variant< InputScript, std::string > load_input_script (const std::filesystem::path &file)
 Reads an input script from a file.
 

Variables

constexpr std::size_t max_chat_size = 200
 Longest chat text, in bytes of UTF-8.
 
constexpr std::uint8_t lobby_player = 255
 player of a ChatMessage whose sender is in the lobby, with no player number.
 
constexpr std::uint8_t server_player = 254
 player of a ChatMessage of the server itself, such as its administrator's say: no player has it (RFC section 3.8).
 
constexpr std::string_view server_name = "server"
 name of a ChatMessage of the server itself.
 
constexpr std::int32_t position_scale = 8
 Steps of a position per logical pixel: positions are sent to the 1/8 px.
 
constexpr unsigned position_bits = 15
 Bits of a position, sign included.
 
constexpr float position_min
 Smallest position sent, in logical pixels: -2048.
 
constexpr float position_max
 Largest position sent, in logical pixels: 2047.875.
 
constexpr float position_max_error = 0.5F / position_scale
 Largest error of a position within [position_min, position_max]: 1/16 px.
 
constexpr unsigned velocity_bits = 12
 Bits of a velocity, sign included; velocities are sent in whole pixels per second.
 
constexpr float velocity_min = -static_cast<float>(std::int32_t{1} << (velocity_bits - 1U))
 Smallest velocity sent, in logical pixels per second: -2048.
 
constexpr float velocity_max
 Largest velocity sent, in logical pixels per second: 2047.
 
constexpr float velocity_max_error = 0.5F
 Largest error of a velocity within [velocity_min, velocity_max]: 0.5 px/s.
 
constexpr unsigned varint_group_bits = 7
 Bits of each group of a varint, followed by one continuation bit.
 
constexpr std::size_t varint_max_groups = 5
 Most groups of a varint: 5, for 32 bits.
 
constexpr unsigned change_bits = 2
 Bits of the change of a delta record.
 
constexpr unsigned entity_field_bits = 4
 Bits of the fields of an EntityChange::Updated record.
 
constexpr std::uint8_t no_player = 255
 Player number meaning "no player", as the owner of an enemy.
 
constexpr std::size_t spawn_event_size = 27
 Size of a Spawn event, type and tick included.
 
constexpr std::size_t destroy_event_size = 18
 Size of a Destroy event, type and tick included.
 
constexpr std::size_t death_event_size = 15
 Size of a Death event, type and tick included.
 
constexpr std::size_t player_left_event_size = 7
 Size of a PlayerLeft event, type and tick included.
 
constexpr std::uint8_t valid_actions = 0x1FU
 Bits of the actions of an Input: up, down, left, right and fire; bits 5 to 7 must be clear.
 
constexpr std::size_t max_inputs_per_datagram = 4
 Inputs an Input datagram carries at most: the newest and the 3 before it, so a lost datagram's input arrives with one of the next three.
 
constexpr std::uint8_t protocol_version = 1
 Protocol version the server speaks, in LoginRequest and in the UDP header.
 
constexpr std::size_t max_name_size = 16
 Longest player name, in bytes of UTF-8.
 
constexpr std::size_t max_listed_rooms = 64
 Most rooms a server may have, and a RoomList may hold.
 
constexpr std::uint8_t max_room_lives = 9
 Most lives a room may give its players.
 
constexpr std::size_t max_listed_scores = 10
 Most scores in a ScoreList.
 
constexpr std::uint32_t no_entity = 0xFFFFFFFF
 Network id that names no entity, for a player out of lives.
 
constexpr std::size_t snapshot_fixed_bits = 32 + 3 + 16
 Bits of the tick, the player count and the entity count of a snapshot payload.
 
constexpr unsigned id_low_bits = 24
 Low bits of a network id, sent as their gap to those of the previous record: the index of the engine's Entity handles, small and dense among live entities.
 
constexpr unsigned id_high_bits = 8
 High bits of a network id, sent as they are: the generation of Entity handles.
 
constexpr unsigned kind_bits = 3
 Bits of the kind of an entity record: kinds 0 to 7.
 
constexpr unsigned frame_bits = 4
 Bits of the frame of an entity record: frames above 15 are sent as 15.
 
constexpr std::size_t entity_record_fixed_bits
 Bits of an entity record besides the gap of its id's low bits: the id's high bits, kind, position, velocity and frame (69).
 
constexpr std::uint32_t short_id_gap = (std::uint32_t{1} << varint_group_bits) - 1U
 Largest gap between the low bits of two records' ids that keeps a record within 10 bytes (77 bits).
 
constexpr std::uint16_t default_tcp_port = 4242
 TCP port the server listens on when --tcp-port is not given.
 
constexpr std::uint16_t default_udp_port = 4243
 UDP port the server listens on when --udp-port is not given.
 
constexpr std::uint32_t default_packet_rate = 300
 Datagrams accepted per second from one address when --max-packet-rate is not given; see RateLimits.
 
constexpr std::uint32_t default_max_rooms = 4
 Rooms played at once when --max-rooms is not given; see GameServer.
 
constexpr std::string_view default_scores_file = "scores.json"
 File of the best scores, in the folder the server runs from.
 
constexpr std::string_view default_bans_file = "bans.json"
 File of the banned addresses, in the folder the server runs from.
 
constexpr std::string_view server_usage
 Usage line printed by --help and after a command line error.
 
constexpr std::uint32_t no_room = 0xFFFFFFFFU
 Room of a session in the lobby, out of every room (LeaveRoom, RFC section 3.7).
 
constexpr int forced_exit_status = 130
 Exit status of a server stopped by a second signal, before its clean stop ended.
 
constexpr std::string_view client_usage
 Usage line printed by --help and after a command line error.
 
constexpr std::size_t connect_field_count = 3
 Number of fields of ConnectField.
 
constexpr std::size_t lag_graph_count = 7
 Number of graphs: LagGraph values are 0 to lag_graph_count - 1.
 
constexpr std::string_view bot_usage
 Usage line printed by --help and after a command line error.
 
constexpr std::uint32_t max_bots = 64
 Most bots --count runs in one process.
 
constexpr std::string_view bot_stats_header
 First line of a --stats file: the names of the columns of bot_stats_line().
 

Detailed Description

R-Type game code, built on the Aegis2D engine.

Typedef Documentation

◆ GameEvent

One of the gameplay events the server sends.

Enumeration Type Documentation

◆ BindResult

enum class rtype::BindResult : std::uint8_t
strong

What SessionTable::bind() did with a Connect.

Enumerator
Bound 

The endpoint is now bound to the session: answer with Accept.

AlreadyBound 

The endpoint was already bound to this session (the Accept was lost): answer with Accept again.

UnknownSession 

No session has this token: drop the datagram.

Taken 

The session is bound to another endpoint, or the endpoint to another session: drop the datagram, so a third party who learned a token cannot take over the session.

NoRoom 

The session is in the lobby, with no game to join: drop the datagram.

◆ BotCommand

enum class rtype::BotCommand : std::uint8_t
strong

What the bot was asked to do.

Enumerator
Run 

Join the server and play.

Help 

Print the usage and exit.

Version 

Print the version and exit.

◆ ChatRejection

enum class rtype::ChatRejection : std::uint8_t
strong

Why a chat message is not relayed, the reason of ChatRejected.

Enumerator
TooLong 

The text is longer than max_chat_size bytes.

BadText 

The text is empty, not UTF-8 or has control characters.

TooFast 

The sender is over the rate: the message is a flood.

◆ ClientCommand

enum class rtype::ClientCommand : std::uint8_t
strong

What the client was asked to do.

Enumerator
Run 

Join the server.

Help 

Print the usage and exit.

Version 

Print the version and exit.

◆ ClientState

enum class rtype::ClientState : std::uint8_t
strong

Where the client is in its session.

Enumerator
Idle 

Not started.

Connecting 

Opening the TCP connection.

LoggingIn 

LoginRequest sent, waiting for the answer.

Lobby 

Logged in with ClientSettings::choose_room: choosing a room (RFC 3.6, 3.7).

InRoom 

In the room joined from the lobby, until all its players are ready (RFC 3.7).

Binding 

Logged in, sending Connect until Accept arrives.

InGame 

UDP endpoint bound: the game may start.

Failed 

The session could not start; error() says why.

Lost 

The session was running and ended: the server stopped, went silent, closed the connection or ended the session; error() says why, for the connection-lost screen.

Closed 

The player left with leave().

◆ ConnectField

enum class rtype::ConnectField : std::uint8_t
strong

A field of the connect screen.

Enumerator
Host 

Address of the server.

Port 

TCP port of the server.

Name 

Player name.

◆ DestroyReason

enum class rtype::DestroyReason : std::uint8_t
strong

Why an entity was destroyed, which tells the client what to show.

The values are part of the protocol: never renumber them.

Enumerator
Despawned 

It left the play area: no effect.

Killed 

It was destroyed: an explosion.

Consumed 

A missile that hit its target: it vanishes.

PlayerLeft 

The ship of a player who left the game.

◆ Difficulty

enum class rtype::Difficulty : std::uint8_t
strong

How hard the enemies of a room are: how often they come and how much they take.

Enumerator
Easy 

Fewer enemies, easier to destroy.

Normal 

The game as tuned.

Hard 

More enemies, harder to destroy.

◆ EntityChange

enum class rtype::EntityChange : std::uint8_t
strong

What a delta snapshot says of an entity.

The values are part of the payload: never renumber them.

Enumerator
Updated 

Some fields changed since the baseline; EntityDelta::fields says which.

Added 

Not in the baseline (or no baseline): every field is sent.

Removed 

In the baseline, gone since.

◆ EntityField

enum class rtype::EntityField : std::uint8_t
strong

Fields of an EntityChange::Updated record, one bit each.

Enumerator
X 

x.

Y 

y.

Velocity 

vx and vy, together.

Frame 

frame.

◆ EntityKind

enum class rtype::EntityKind : std::uint8_t
strong

Kind of an entity in snapshots and events (RFC section 4.1).

The values are part of the protocol: never renumber them.

Enumerator
PlayerShip 

A player's ship.

PlayerMissile 

A missile fired by a player.

BydosSlave 

A Bydos slave.

EnemyMissile 

A missile fired by an enemy.

◆ EventType

enum class rtype::EventType : std::uint8_t
strong

Type of an event, its first byte (RFC section 4.4).

The values are part of the protocol: never renumber them.

Enumerator
Spawn 

An entity appears; a missile's is also its shot.

Destroy 

An entity disappears.

Death 

A player lost a life.

PlayerJoined 

A player joined the game.

PlayerLeft 

A player left the game.

GameOver 

No player has lives left.

◆ JoinRejection

enum class rtype::JoinRejection : std::uint8_t
strong

Why a room is not joined, the reason of JoinRejected.

Enumerator
NoSuchRoom 

No room in use has this number.

RoomFull 

The room has as many players as it takes.

InGame 

The player is in game: it plays in its room until its session ends.

◆ LagGraph

enum class rtype::LagGraph : std::uint8_t
strong

A graph of the lagometer.

Enumerator
Rtt 

Smoothed round trip time, in milliseconds.

Jitter 

Jitter of the snapshots' arrivals, in milliseconds.

Loss 

Share of the server's datagrams lost, in percent.

Interval 

Mean time between two snapshots, in milliseconds.

BytesIn 

Bytes received per second.

BytesOut 

Bytes sent per second.

Corrections 

Corrections of the predicted ship per second (ShipPrediction::corrections()).

◆ LagLevel

enum class rtype::LagLevel : std::uint8_t
strong

How a figure compares with a sound link.

Enumerator
Good 

As on a local network.

Warning 

Players start to notice.

Bad 

The game is hard to play.

◆ LeaveReason

enum class rtype::LeaveReason : std::uint8_t
strong

Why a player left the game, in PlayerLeft.

The values are part of the protocol: never renumber them.

Enumerator
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).

◆ LoginRejection

enum class rtype::LoginRejection : std::uint8_t
strong

Why a login is refused, the reason of LoginRejected.

Enumerator
ServerFull 

Every room of the server is full.

BadVersion 

The server does not speak the requested version.

BadName 

The name is empty, too long, not UTF-8 or has control characters.

NameTaken 

Another player of the server has this name.

GameStarted 

The game is running and does not take new players.

Banned 

The administrator banned the address the client connects from.

◆ LogoutReason

enum class rtype::LogoutReason : std::uint8_t
strong

Why a session ends, the reason of Logout.

Enumerator
Left 

The player quit (sent by the client).

Shutdown 

The server is stopping.

TimedOut 

No valid datagram for too long.

ProtocolError 

The client sent something invalid over UDP.

RoomClosed 

The administrator of the server closed the player's room.

Kicked 

The administrator of the server removed the player.

Banned 

The administrator banned the player's address: it cannot log in again.

◆ RoomRejection

enum class rtype::RoomRejection : std::uint8_t
strong

Why a room is not created, the reason of RoomRejected.

Enumerator
NoRoomLeft 

Every room of the server is in use.

BadName 

The name is empty, too long, not UTF-8 or has control characters.

BadSize 

The number of players is not 1 to 4.

BadLives 

The lives are not 1 to max_room_lives.

BadDifficulty 

The difficulty is not a Difficulty.

UnknownWaves 

The server has no waves file of this name.

BadFriendlyFire 

The friendly fire is not 0 or 1.

◆ RoomState

enum class rtype::RoomState : std::uint8_t
strong

What a room is doing, the state of a RoomList record.

Enumerator
Waiting 

None of its players is in game yet.

Playing 

Its game is running.

◆ ServerCommand

enum class rtype::ServerCommand : std::uint8_t
strong

What the server was asked to do.

Enumerator
Run 

Start the game and listen on the ports.

Help 

Print the usage and exit.

Version 

Print the version and exit.

◆ TcpKind

enum class rtype::TcpKind : std::uint8_t
strong

First byte of every TCP message: what it is.

The values are part of the protocol: never renumber them.

Enumerator
LoginRequest 

Client to server: version and name.

LoginAccepted 

Server to client: session token, player number and UDP port.

LoginRejected 

Server to client: why the login failed; the server closes afterwards.

Logout 

Both ways: the sender ends the session and closes.

ListRooms 

Client to server, after the login: asks for the rooms.

RoomList 

Server to client: the rooms, answering ListRooms.

CreateRoom 

Client to server, after the login: name and size of a room to create.

RoomCreated 

Server to client: the number of the room created, answering CreateRoom.

RoomRejected 

Server to client: why the room was not created, answering CreateRoom.

JoinRoom 

Client to server: the room to join.

RoomJoined 

Server to client: the room joined and the player's number there.

JoinRejected 

Server to client: why the room was not joined, answering JoinRoom.

LeaveRoom 

Client to server: leaves its room for the lobby.

SetReady 

Client to server: ready to start, or not.

RoomPlayers 

Server to client: the players of its room and whether each is ready.

GameStart 

Server to client: every player of its room is ready, bind and play.

ChatSend 

Client to server: a text for the players of its room (RFC section 3.8).

ChatMessage 

Server to client: a text relayed from a player of its room.

ChatRejected 

Server to client: why a ChatSend was not relayed.

ListScores 

Client to server: the best scores, please (RFC section 3.9).

ScoreList 

Server to client: the best scores, best first.

Function Documentation

◆ address_of()

aegis2d::net::Endpoint rtype::address_of ( const aegis2d::net::Endpoint &  endpoint)
noexcept

The address of an endpoint, its port set to 0: the key of the limits.

Parameters
endpointSource of a datagram or a connection.
Returns
The same address with port 0.

◆ apply_delta()

std::optional< Snapshot > rtype::apply_delta ( const Snapshot *  baseline,
std::span< const DeltaSnapshot >  parts 
)

Rebuilds a snapshot from its baseline and every payload of its tick.

Parameters
baselineThe snapshot of DeltaSnapshot::baseline, as the client rebuilt it, or nullptr for a full snapshot.
partsEvery payload of the tick, in any order.
Returns
The snapshot, its entities in the order of write_snapshot(), or std::nullopt if parts is empty, mixes ticks or baselines, does not match baseline, or updates or removes an entity the baseline does not have.

◆ bot_stats_line()

std::string rtype::bot_stats_line ( const BotStats &  stats)

One line of a --stats file, in the order of bot_stats_header, without its end.

Parameters
statsFigures of a bot.
Returns
The comma-separated values, the decimals with a dot.

◆ bot_team()

std::vector< BotSettings > rtype::bot_team ( const BotSettings &  base,
std::size_t  count 
)

The settings of count bots that play together, for --count.

One bot keeps base. Several are named after it with their number from 1 (bot1, bot2...), so the server takes them all, and the random ones each get their own seed: base's plus their index. They share the script, if any.

Parameters
baseSettings of the first bot.
countNumber of bots, at least 1.
Returns
One settings per bot.

◆ chat_rejection_text()

std::string rtype::chat_rejection_text ( std::uint8_t  reason)

Sentence telling why a message was not sent.

Parameters
reasonreason of a ChatRejected, unknown values included.
Returns
"Message not sent: too long", "... too fast"...

◆ check_chat_text()

std::optional< ChatRejection > rtype::check_chat_text ( std::string_view  text)
noexcept

Checks a text against the rules of ChatSend, the length first.

Parameters
textBytes received.
Returns
std::nullopt if the text may be relayed, or ChatRejection::TooLong or ChatRejection::BadText.

◆ default_enemies_directory()

std::filesystem::path rtype::default_enemies_directory ( )

Directory of the enemy scripts the server plays.

Returns
core::asset_path("enemies"): assets/enemies of the repository, copied next to r-type_server by the build.

◆ default_waves_file()

std::filesystem::path rtype::default_waves_file ( )

Waves file played by the server when none is given.

Returns
core::asset_path("waves/stage1.json"): assets/waves/stage1.json of the repository, copied next to r-type_server by the build.

◆ dequantize_position()

float rtype::dequantize_position ( std::int32_t  steps)
noexcept

Position of a number of steps.

Parameters
stepsPosition in 1/8 px.
Returns
The position in logical pixels, exact.

◆ enemy_types()

std::vector< std::string > rtype::enemy_types ( const std::filesystem::path &  directory = default_enemies_directory())

The enemy types of a directory, as waves files name them.

Parameters
directoryDirectory of the scripts.
Returns
The names of its .lua files without their extension, sorted; none if the directory cannot be read.

◆ entity_record_bits()

std::size_t rtype::entity_record_bits ( std::uint32_t  id_gap)
noexcept

Size of an entity record.

Parameters
id_gapThe low id_low_bits bits of its id minus those of the record before it in the payload, or those bits themselves for the first record.
Returns
entity_record_fixed_bits plus the bits of id_gap as a varint: 77 bits up to short_id_gap.

◆ find_rewound_contacts()

void rtype::find_rewound_contacts ( aegis2d::ecs::Registry &  registry,
const PositionHistory &  history,
std::uint64_t  tick,
const std::function< std::uint32_t(aegis2d::ecs::Entity)> &  rewind_of,
std::vector< aegis2d::ecs::Contact > &  contacts 
)

Finds the contacts of the player missiles with the enemies as their shooters saw them.

Each entity of the player_missile layer with an ecs::Owner whose rewind is above 0 is tested, at its position now, against each enemy of history at tick - rewind that is still alive, with the enemy's collider. The contacts found are added to contacts as ecs::find_contacts() writes them, so ecs::apply_damage() counts them with the others; a missile that hits both now and then is consumed by the first.

Parameters
registryWorld of the game.
historyPositions of the enemies at the last ticks.
tickNumber the current state will have in history once recorded.
rewind_ofRewind of a shooter, from rewind_ticks(); 0 for no compensation.
contactsContacts of the tick, to add to.

◆ fire_enemy_missile()

aegis2d::ecs::Entity rtype::fire_enemy_missile ( aegis2d::ecs::Registry &  registry,
aegis2d::ecs::Entity  shooter 
)

Creates the missile an enemy fires, in front of it (on its left).

A spawn_enemy_missile() just left of the enemy's sprite (or of its center without one), with ecs::Owner set to the enemy.

Parameters
registryWorld of the game.
shooterEnemy that fires; it must have a Transform.
Returns
The missile.
Exceptions
std::out_of_rangeIf shooter has no Transform.

◆ game_rules()

GameRules rtype::game_rules ( const RoomRules &  rules)
noexcept

The gameplay of the rules a room was created with.

Easy and Hard take the enemy health and the spawn intervals of their tuning::easy_* and tuning::hard_* values; Normal, and anything else, the game as tuned. The waves file is not part of it: GameServer picks the waves of the room.

Parameters
rulesRules checked by SessionTable::create_room().
Returns
The rules of the room's games.

◆ input_payload_size()

constexpr std::size_t rtype::input_payload_size ( std::size_t  count)
constexprnoexcept

Size of the payload of an Input datagram carrying count inputs: the sequence of the newest, the count, then the actions of each.

Parameters
countNumber of inputs, 1 to max_inputs_per_datagram.
Returns
3 + count bytes.

◆ install_stop_handlers()

bool rtype::install_stop_handlers ( )

Handles SIGINT and SIGTERM: the first one asks the server to stop cleanly (stop_requested() becomes true), a second one ends the process at once with forced_exit_status.

The handler only sets a lock-free atomic flag, or calls std::_Exit(): nothing else is safe in a signal handler. Windows has no SIGTERM from the system, but Ctrl+C raises SIGINT.

Returns
false if a handler could not be installed: that signal then ends the process.

◆ interpolate()

aegis2d::Vec2 rtype::interpolate ( const Trail &  trail,
double  tick 
)
noexcept

Position of an entity at a tick, between the positions of its trail.

Between two positions, the linear interpolation; before the oldest, the oldest; after the newest, the newest (the entity is not pushed past what the server said). Ticks may be fractional, the time between two ticks.

Parameters
trailPositions of the entity, at least one.
tickServer tick to draw.
Returns
The position, or the origin for an empty trail.

◆ keep_ship_in_area()

aegis2d::Vec2 rtype::keep_ship_in_area ( aegis2d::Vec2  position)
noexcept

Keeps a player ship inside the play area.

Its box (tuning::player_size) must fit in ServerGame::play_area(): holding a direction against an edge stops the ship there, and it can leave the edge at once.

Parameters
positionCenter of the ship.
Returns
The nearest position whose box fits.

◆ keep_ships_in_area()

void rtype::keep_ships_in_area ( aegis2d::ecs::Registry &  registry,
const aegis2d::ecs::Tick &  tick 
)

System that keeps every player ship inside the play area.

keep_ship_in_area() for each entity with shmup::PlayerShip and ecs::Transform; run it after ecs::apply_velocity().

Parameters
registryWorld holding the ships.
tickUnused.

◆ kind_of()

std::optional< TcpKind > rtype::kind_of ( std::span< const std::byte >  message)
noexcept

Kind of a TCP message.

Parameters
messageMessage received, length prefix excluded.
Returns
Its kind, or std::nullopt if it is empty or its kind is reserved.

◆ kind_of_layer()

std::optional< EntityKind > rtype::kind_of_layer ( std::uint32_t  layer)
noexcept

Kind of the entities of a collision layer, for snapshots and events.

Each layer holds one kind of entity for now.

Parameters
layerecs::Collider::layer, one of the values of rtype::layer.
Returns
The kind, or std::nullopt for a layer whose entities are not replicated.

◆ lag_label()

std::string rtype::lag_label ( LagGraph  graph,
double  value 
)

Label of a value of a graph, for the overlay: "RTT 152 MS", "LOSS 2.5 %".

Parameters
graphGraph of the value.
valueValue, in the unit of the graph.
Returns
The label, in capitals for the pixel font.

◆ lag_level()

LagLevel rtype::lag_level ( LagGraph  graph,
double  value 
)
noexcept

Level of a value of a graph: the RTT is bad above 200 ms, the loss above 5 %...

The bandwidth is always Good: how much is too much depends on the link.

Parameters
graphGraph of the value.
valueValue, in the unit of the graph.
Returns
Its level.

◆ lag_lines()

std::vector< std::string > rtype::lag_lines ( const LagSample &  sample)

The figures of a sample as lines of the engine's metrics overlay, so that the frame metrics (F12) show the network too, with or without the lagometer (F6).

Parameters
sampleFigures, such as Lagometer::latest().
Returns
Three lines: "RTT 42 MS JITTER 3 MS LOSS 0.0 %", "IN 1.5 KB/S OUT 0.8 KB/S" and "SNAPSHOTS 50 MS CORRECTED 0/S".

◆ left_message()

std::string rtype::left_message ( const std::string &  name,
LeaveReason  reason 
)

Sentence telling why a player left.

Parameters
nameName of the player.
reasonWhy it left, as PlayerLeft gives it.
Returns
"<name> left the game", "<name> lost the connection" or "<name> was removed from the game".

◆ load_input_script()

std::variant< InputScript, std::string > rtype::load_input_script ( const std::filesystem::path &  file)

Reads an input script from a file.

Parameters
fileScript file.
Returns
The script, or a message naming the file and the faulty line.

◆ load_waves()

aegis2d::ecs::WaveSchedule rtype::load_waves ( const std::filesystem::path &  path,
const std::vector< std::string > &  types = enemy_types() 
)

Reads a waves file, accepting only the enemy types it is given.

Parameters
pathJSON file in the format of ecs::WaveSchedule.
typesEnemy types it may name: by default, the scripts of default_enemies_directory().
Returns
The schedule, ready for ServerGame::play_waves().
Exceptions
aegis2d::core::ConfigErrorIf the file cannot be read or is not valid waves (an unknown type included); the message names the file and the faulty value.

◆ measure_bot()

BotStats rtype::measure_bot ( const Bot &  bot,
std::string  name,
std::chrono::steady_clock::duration  played,
std::chrono::steady_clock::time_point  now 
)

Reads what a bot measured, before it leaves.

Parameters
botThe bot.
nameIts player name.
playedTime it spent in game.
nowCurrent time, the end of the windows of the loss and the snapshot jitter.
Returns
The figures.

◆ measure_lag()

LagSample rtype::measure_lag ( const aegis2d::net::RttEstimator &  rtt,
const aegis2d::net::TrafficCounters &  traffic,
const NetworkStats &  stats,
std::chrono::steady_clock::time_point  now 
)

Reads the network statistics of the client into a sample.

Parameters
rttRound trip time to the server (ClientSession::rtt()).
trafficDatagrams exchanged (ClientSession::traffic()): the last whole second.
statsLoss and snapshots (ClientSession::network_stats()): the last 2 seconds.
nowCurrent time.
Returns
The sample.

◆ parse_bot_options()

std::variant< BotOptions, std::string > rtype::parse_bot_options ( std::span< const std::string_view >  args)

Reads the command line of r-type_bot.

Options may come in any order; a repeated option keeps its last value. --help and --version stop the reading. The port is a number from 1 to 65535, the seconds a number from 1, the count a number from 1 to max_bots, the seed any 32-bit number; the address and the name are checked when the bot joins (ClientSession::start()), the script when it is loaded.

Parameters
argsArguments after the program name.
Returns
The options, or a one-line message naming the faulty argument.

◆ parse_client_options()

std::variant< ClientOptions, std::string > rtype::parse_client_options ( std::span< const std::string_view >  args)

Reads the command line of r-type_client.

Options may come in any order; a repeated option keeps its last value. --help and --version stop the reading. The port is a number from 1 to 65535, the frames a number from 1; the address and the name are checked when the client joins (ClientSession::start()).

Parameters
argsArguments after the program name.
Returns
The options, or a one-line message naming the faulty argument.

◆ parse_input_script()

std::variant< InputScript, std::string > rtype::parse_input_script ( std::string_view  text)

Reads an input script.

One step per line: a duration in milliseconds, then the actions held, as the letters U (up), D (down), L (left), R (right) and F (fire), or - for none:

# Dodge up and down while firing, then rest.
500 UF
500 DF
250 -

Blank lines and lines starting with # are skipped; spaces and tabs separate the fields.

Parameters
textContents of the script.
Returns
The script, or a message naming the faulty line.

◆ parse_port()

std::optional< std::uint16_t > rtype::parse_port ( std::string_view  text)
noexcept

Reads a TCP port, as --port and the connect screen take it.

Parameters
textDecimal digits only: no sign, space or base prefix.
Returns
The port, from 1 to 65535, or nothing.

◆ parse_server_options()

std::variant< ServerOptions, std::string > rtype::parse_server_options ( std::span< const std::string_view >  args)

Reads the command line of r-type_server.

Options may come in any order; a repeated option keeps its last value. --help and --version stop the reading: what follows them is not checked. A port is a decimal number from 0 to 65535, 0 asking the system for a free port.

Parameters
argsArguments after the program name.
Returns
The options, or a one-line message naming the faulty argument.

◆ player_spawn()

aegis2d::Vec2 rtype::player_spawn ( std::size_t  slot)

Where a player slot starts and respawns.

Slots are spread over the height of the play area, at tuning::player_spawn_x.

Parameters
slotPlayer slot, from 0 to tuning::max_players - 1.
Returns
Center of the ship.
Exceptions
std::out_of_rangeIf slot is not a valid slot.

◆ quantize_position()

std::int32_t rtype::quantize_position ( float  position)
noexcept

Rounds a position to the nearest 1/8 px, clamped to [position_min, position_max].

Parameters
positionPosition in logical pixels; NaN gives 0.
Returns
The position in steps, from -2^14 to 2^14 - 1.

◆ quantize_velocity()

std::int32_t rtype::quantize_velocity ( float  velocity)
noexcept

Rounds a velocity to the nearest whole pixel per second, clamped to [velocity_min, velocity_max].

Parameters
velocityVelocity in logical pixels per second; NaN gives 0.
Returns
The velocity, from -2^11 to 2^11 - 1.

◆ quantized()

EntityRecord rtype::quantized ( const EntityRecord &  entity)
noexcept

A record as the client gets it: position and velocity rounded as compact.hpp does, frame at most 15.

Parameters
entityRecord of the server.
Returns
The record after a trip through a payload.

◆ read_chat_message()

std::optional< ChatMessage > rtype::read_chat_message ( std::span< const std::byte >  message)

Reads a ChatMessage.

Parameters
messageMessage received, length prefix excluded.
Returns
Its fields as received, or std::nullopt if the message is not a well-formed ChatMessage.

◆ read_chat_rejected()

std::optional< std::uint8_t > rtype::read_chat_rejected ( std::span< const std::byte >  message)
noexcept

Reads a ChatRejected.

Parameters
messageMessage received, length prefix excluded.
Returns
The reason as sent (unknown values included), or std::nullopt if the message is not a well-formed ChatRejected.

◆ read_chat_send()

std::optional< std::string > rtype::read_chat_send ( std::span< const std::byte >  message)

Reads a ChatSend.

Parameters
messageMessage received, length prefix excluded.
Returns
The text as received, or std::nullopt if the message is not a well-formed ChatSend.

◆ read_create_room()

std::optional< CreateRoomRequest > rtype::read_create_room ( std::span< const std::byte >  message)

Reads a CreateRoom.

Parameters
messageMessage received, length prefix excluded.
Returns
Its fields, or std::nullopt if the message is not a well-formed CreateRoom.

◆ read_delta_snapshot()

std::optional< DeltaSnapshot > rtype::read_delta_snapshot ( std::span< const std::byte >  payload)

Decodes one payload written by write_delta_snapshot().

Parameters
payloadBytes after the header.
Returns
The payload, or std::nullopt if it is malformed (as read_snapshot(), plus a baseline not older than the tick, a change of 3, an update of no field, or a removal without baseline).

◆ read_event()

std::optional< GameEvent > rtype::read_event ( std::span< const std::byte >  bytes)

Decodes the bytes of one event, as a client does (RFC section 6.4).

Parameters
bytesBytes of the event, as handed over by ReliableChannel::read_events().
Returns
The event, or std::nullopt if its type is not one of the five above or its bytes do not match the type: a wrong size, a non-finite position or velocity, an owner other than 0 to 3 and 255, a player above 3, or a name that breaks the rules of valid_player_name(). Unknown kinds and reasons are kept, for the caller to apply its rules.

◆ read_game_start()

bool rtype::read_game_start ( std::span< const std::byte >  message)
noexcept

Tells whether a message is a well-formed GameStart: its kind alone.

Parameters
messageMessage received, length prefix excluded.
Returns
true if it is.

◆ read_inputs()

std::optional< std::vector< InputRecord > > rtype::read_inputs ( std::span< const std::byte >  payload)

Decodes the payload of an Input datagram.

Parameters
payloadBytes after the header.
Returns
Its inputs, oldest first, their sequences consecutive and the last one the newest's; or std::nullopt if the count is 0 or above max_inputs_per_datagram, the payload is not input_payload_size() bytes for it, or an input sets a bit outside valid_actions.

◆ read_join_rejected()

std::optional< std::uint8_t > rtype::read_join_rejected ( std::span< const std::byte >  message)
noexcept

Reads a JoinRejected.

Parameters
messageMessage received, length prefix excluded.
Returns
The reason as sent (unknown values included), or std::nullopt if the message is not a well-formed JoinRejected.

◆ read_join_room()

std::optional< std::uint8_t > rtype::read_join_room ( std::span< const std::byte >  message)
noexcept

Reads a JoinRoom.

Parameters
messageMessage received, length prefix excluded.
Returns
The number of the room, or std::nullopt if the message is not a well-formed JoinRoom.

◆ read_leave_room()

bool rtype::read_leave_room ( std::span< const std::byte >  message)
noexcept

Tells whether a message is a well-formed LeaveRoom: its kind alone.

Parameters
messageMessage received, length prefix excluded.
Returns
true if it is.

◆ read_list_rooms()

bool rtype::read_list_rooms ( std::span< const std::byte >  message)
noexcept

Tells whether a message is a well-formed ListRooms: its kind alone.

Parameters
messageMessage received, length prefix excluded.
Returns
true if it is.

◆ read_list_scores()

bool rtype::read_list_scores ( std::span< const std::byte >  message)
noexcept

Tells whether a message is a well-formed ListScores.

Parameters
messageMessage received, length prefix excluded.
Returns
true for a ListScores, with no field.

◆ read_login_accepted()

std::optional< LoginAccepted > rtype::read_login_accepted ( std::span< const std::byte >  message)
noexcept

Reads a LoginAccepted.

Parameters
messageMessage received, length prefix excluded.
Returns
Its fields, or std::nullopt if the message is not a well-formed LoginAccepted.

◆ read_login_rejected()

std::optional< std::uint8_t > rtype::read_login_rejected ( std::span< const std::byte >  message)
noexcept

Reads a LoginRejected.

Parameters
messageMessage received, length prefix excluded.
Returns
The reason as sent (unknown values included), or std::nullopt if the message is not a well-formed LoginRejected.

◆ read_login_request()

std::optional< LoginRequest > rtype::read_login_request ( std::span< const std::byte >  message)

Reads a LoginRequest.

Parameters
messageMessage received, length prefix excluded.
Returns
The request, or std::nullopt if the message is not a well-formed LoginRequest: another kind, a field past the end, or bytes after the name.

◆ read_logout()

std::optional< std::uint8_t > rtype::read_logout ( std::span< const std::byte >  message)
noexcept

Reads a Logout.

Parameters
messageMessage received, length prefix excluded.
Returns
The reason as sent (unknown values included), or std::nullopt if the message is not a well-formed Logout.

◆ read_position()

std::optional< float > rtype::read_position ( aegis2d::net::BitReader &  reader)
noexcept

Reads a position written by write_position().

Parameters
readerSource.
Returns
The position in logical pixels, or nothing if the reader has failed or too few bits remain.

◆ read_room_created()

std::optional< std::uint8_t > rtype::read_room_created ( std::span< const std::byte >  message)
noexcept

Reads a RoomCreated.

Parameters
messageMessage received, length prefix excluded.
Returns
The number of the room, or std::nullopt if the message is not a well-formed RoomCreated.

◆ read_room_joined()

std::optional< std::pair< std::uint8_t, std::uint8_t > > rtype::read_room_joined ( std::span< const std::byte >  message)
noexcept

Reads a RoomJoined.

Parameters
messageMessage received, length prefix excluded.
Returns
The room and the player's number there, or std::nullopt if the message is not a well-formed RoomJoined.

◆ read_room_list()

std::optional< std::vector< RoomRecord > > rtype::read_room_list ( std::span< const std::byte >  message)

Reads a RoomList.

Parameters
messageMessage received, length prefix excluded.
Returns
Its rooms, in order, or std::nullopt if the message is not a well-formed RoomList: another kind, more than max_listed_rooms rooms, a field past the end, or bytes after the last room.

◆ read_room_players()

std::optional< RoomPlayers > rtype::read_room_players ( std::span< const std::byte >  message)

Reads a RoomPlayers.

Parameters
messageMessage received, length prefix excluded.
Returns
Its room and players, or std::nullopt if the message is not a well-formed RoomPlayers: another kind, more than 4 players, a ready other than 0 or 1, a field past the end, or bytes after the last player.

◆ read_room_rejected()

std::optional< std::uint8_t > rtype::read_room_rejected ( std::span< const std::byte >  message)
noexcept

Reads a RoomRejected.

Parameters
messageMessage received, length prefix excluded.
Returns
The reason as sent (unknown values included), or std::nullopt if the message is not a well-formed RoomRejected.

◆ read_score_list()

std::optional< std::vector< ScoreRecord > > rtype::read_score_list ( std::span< const std::byte >  message)

Reads a ScoreList.

Parameters
messageMessage received, length prefix excluded.
Returns
The scores as received, best first, or std::nullopt if the message is not a well-formed ScoreList (a count above max_listed_scores included).

◆ read_set_ready()

std::optional< bool > rtype::read_set_ready ( std::span< const std::byte >  message)
noexcept

Reads a SetReady.

Parameters
messageMessage received, length prefix excluded.
Returns
Whether the player is ready, or std::nullopt if the message is not a well-formed SetReady, its ready being 0 or 1.

◆ read_snapshot()

std::optional< Snapshot > rtype::read_snapshot ( std::span< const std::byte >  payload)

Decodes the payload of one Snapshot datagram.

Parameters
payloadBytes after the header.
Returns
Its tick and records, the entities in the order they were written, or std::nullopt if the payload is malformed (a record past the end, bytes or bits other than the padding after the last one, more than 4 players, a varint with another encoding than write_varint()'s, or the low bits of an id beyond id_low_bits).

◆ read_varint()

std::optional< std::uint32_t > rtype::read_varint ( aegis2d::net::BitReader &  reader)
noexcept

Reads a varint written by write_varint().

A varint has a single encoding: one with a last group of 0 bits (other than a lone first group), more than varint_max_groups groups or a value above 32 bits is rejected.

Parameters
readerSource; it fails on a rejected varint.
Returns
The value, or nothing if the varint is truncated or rejected.

◆ read_velocity()

std::optional< float > rtype::read_velocity ( aegis2d::net::BitReader &  reader)
noexcept

Reads a velocity written by write_velocity().

Parameters
readerSource.
Returns
The velocity in logical pixels per second, or nothing if the reader has failed or too few bits remain.

◆ request_stop()

void rtype::request_stop ( )
noexcept

Asks the server to stop, as a first Ctrl+C does: stop_requested() becomes true.

Thread-safe; the admin console's stop calls it.

◆ rewind_ticks()

std::uint32_t rtype::rewind_ticks ( std::chrono::nanoseconds  rtt,
std::chrono::nanoseconds  interpolation 
)
noexcept

How many ticks back a player sees the enemies.

The enemies reach its screen half a round trip after the server moved them, then wait its interpolation delay; its missile reaches the server half a round trip after it fired. So the player aims at the enemies of rtt + interpolation ago, rounded to the tick, and never further back than the history keeps (PositionHistory::capacity): a slower link is not compensated beyond 500 ms.

Parameters
rttRound trip time to the player, smoothed.
interpolationHow far behind the server the player's client draws the world.
Returns
0 to PositionHistory::capacity ticks.

◆ ship_velocity()

aegis2d::Vec2 rtype::ship_velocity ( aegis2d::ecs::PlayerInput  input)
noexcept

Velocity of a player ship holding an input.

Its held directions at tuning::player_speed, diagonals as fast as straight lines (ecs::direction_of()); opposite directions cancel out.

Parameters
inputHeld actions.
Returns
The velocity, zero when no direction is held.

◆ snapshot_due()

constexpr bool rtype::snapshot_due ( std::uint64_t  tick)
constexprnoexcept

Tells whether a snapshot is due after a tick.

tuning::snapshot_rate times per second: every third tick at 60 ticks per second.

Parameters
tickNumber of ticks run, ServerGame::ticks().
Returns
true every tuning::tick_rate / tuning::snapshot_rate ticks.

◆ spawn_enemy_missile()

aegis2d::ecs::Entity rtype::spawn_enemy_missile ( aegis2d::ecs::Registry &  registry,
aegis2d::Vec2  position 
)

Creates a missile fired by an enemy.

It flies left, hits only players, is consumed by its first hit and is destroyed once past the left edge.

Parameters
registryWorld of the game.
positionCenter of the missile.
Returns
The missile.

◆ spawn_player()

aegis2d::ecs::Entity rtype::spawn_player ( aegis2d::ecs::Registry &  registry,
std::size_t  slot 
)

Creates the ship of a player.

The ship is steered by its ecs::PlayerInput, kept in the play area, fires every tuning::player_fire_cooldown seconds while fire is held, has one health point, tuning::player_lives lives respawning at player_spawn(), a Score, a NetworkId, and rams enemies.

Parameters
registryWorld of the game.
slotPlayer slot, from 0 to tuning::max_players - 1.
Returns
The ship.
Exceptions
std::out_of_rangeIf slot is not a valid slot.

◆ spawn_player_missile()

aegis2d::ecs::Entity rtype::spawn_player_missile ( aegis2d::ecs::Registry &  registry,
aegis2d::ecs::Entity  shooter 
)

Creates a missile fired by a player, in front of its ship.

The missile flies right, hits only enemies, is consumed by its first hit, credits its kill to shooter (ecs::Owner) and is destroyed once past the right edge (ecs::OffscreenDespawn).

Parameters
registryWorld of the game.
shooterPlayer ship that fires; it must have a Transform.
Returns
The missile.
Exceptions
std::out_of_rangeIf shooter has no Transform.

◆ steer_ships()

void rtype::steer_ships ( aegis2d::ecs::Registry &  registry,
const aegis2d::ecs::Tick &  tick 
)

System that sets the velocity of every player ship from its input.

ship_velocity() for each entity with shmup::PlayerShip, ecs::PlayerInput and ecs::Velocity; ecs::apply_velocity() then moves it.

Parameters
registryWorld holding the ships.
tickUnused: the speed is per second.

◆ step_ship()

ShipMotion rtype::step_ship ( aegis2d::Vec2  position,
aegis2d::ecs::PlayerInput  input,
float  delta 
)
noexcept

Moves a player ship by one tick.

The velocity of its input (ship_velocity()), the position moved by it for delta seconds, then kept inside the play area (keep_ship_in_area()): what the server's steering, movement and play_area systems do to the ship, with the same arithmetic, so a client that runs it on its inputs finds the server's positions.

Parameters
positionCenter of the ship before the tick.
inputActions held during the tick.
deltaDuration of the tick in seconds, ecs::Tick::delta().
Returns
The position and velocity after the tick.

◆ stop_requested()

bool rtype::stop_requested ( )
noexcept

Tells whether a stop was asked by a signal. Thread-safe.

Returns
true once SIGINT or SIGTERM was received.

◆ take_snapshot()

Snapshot rtype::take_snapshot ( GameInstance &  instance)

Takes the state of the game, on the simulation thread.

Players in their number order; entities with a NetworkId, a Transform and a Collider whose layer gives their kind (entities of another layer are left out).

Parameters
instanceGame to read; the scores of players out of lives are the last ones seen.
Returns
The snapshot.

◆ to_string() [1/5]

std::string_view rtype::to_string ( ChatRejection  reason)
noexcept

Short name of a rejection, for logs.

Parameters
reasonReason to name.
Returns
"too long", "bad text", "too fast" or "unknown".

◆ to_string() [2/5]

std::string_view rtype::to_string ( ClientState  state)
noexcept

Short name of a state, for logs.

Parameters
stateState to name.
Returns
"idle", "connecting", "logging in"... or "unknown".

◆ to_string() [3/5]

std::string_view rtype::to_string ( JoinRejection  reason)
noexcept

Short name of a rejection, for logs.

Parameters
reasonReason to name.
Returns
"no such room", "room full", "in game" or "unknown".

◆ to_string() [4/5]

std::string_view rtype::to_string ( LoginRejection  reason)
noexcept

Short name of a rejection, for logs.

Parameters
reasonReason to name.
Returns
"server full", "bad version"... or "unknown".

◆ to_string() [5/5]

std::string_view rtype::to_string ( RoomRejection  reason)
noexcept

Short name of a rejection, for logs.

Parameters
reasonReason to name.
Returns
"no room left", "bad name", "bad size", "bad lives"... or "unknown".

◆ valid_player_name()

bool rtype::valid_player_name ( std::string_view  name)
noexcept

Tells whether a name follows the rules of LoginRequest.

1 to max_name_size bytes of valid UTF-8 (no overlong form, surrogate or code point above U+10FFFF), without control characters (below U+0020, and U+007F).

Parameters
nameBytes received.
Returns
true if the name can be given to a player.

◆ valid_text()

bool rtype::valid_text ( std::string_view  text,
std::size_t  max_size 
)
noexcept

Tells whether a text is 1 to max_size bytes of valid UTF-8 without control characters, as player names and chat texts must be.

No overlong form, surrogate or code point above U+10FFFF, and no control character (below U+0020, and U+007F).

Parameters
textBytes received.
max_sizeMost bytes allowed.
Returns
true if the text follows these rules.

◆ varint_bits()

std::size_t rtype::varint_bits ( std::uint32_t  value)
noexcept

Size of a varint.

Parameters
valueValue to write.
Returns
The number of bits write_varint() takes for value.

◆ waves_names()

std::vector< std::string > rtype::waves_names ( const std::filesystem::path &  directory)

The waves files of a directory, as a room names them (RFC section 3.6).

Parameters
directoryDirectory to look in, such as the parent of default_waves_file().
Returns
The names of its .json files without their extension, sorted; none if the directory cannot be read.

◆ write_chat_message()

std::vector< std::byte > rtype::write_chat_message ( const ChatMessage &  message)

Encodes a ChatMessage.

Parameters
messageSender and text; the strings must fit a string.
Returns
The message, without length prefix.

◆ write_chat_rejected()

std::vector< std::byte > rtype::write_chat_rejected ( ChatRejection  reason)

Encodes a ChatRejected.

Parameters
reasonWhy the message was not relayed.
Returns
The message, without length prefix.

◆ write_chat_send()

std::vector< std::byte > rtype::write_chat_send ( std::string_view  text)

Encodes a ChatSend.

Parameters
textText to send; it must fit a string.
Returns
The message, without length prefix.

◆ write_create_room()

std::vector< std::byte > rtype::write_create_room ( const CreateRoomRequest &  request)

Encodes a CreateRoom.

Parameters
requestName, number of players and rules; the strings must fit a string.
Returns
The message, without length prefix.

◆ write_delta_snapshot()

std::vector< std::vector< std::byte > > rtype::write_delta_snapshot ( const Snapshot &  snapshot,
const Snapshot *  baseline 
)

Encodes a snapshot against a baseline, as the payloads of Snapshot datagrams.

Entities whose quantized fields are all the same as in the baseline are skipped; changed ones carry only the fields that changed; new ones carry every field; those of the baseline that are gone are listed as removed. Without a baseline, every entity is added: a full snapshot. Records go by increasing index, as in write_snapshot(), and each payload holds the tick, the baseline, every player record and as many records as fit a datagram.

Parameters
snapshotState to send.
baselineA snapshot the client acknowledged, older than snapshot, or nullptr.
Returns
The payloads, in order; at least one.
Exceptions
std::invalid_argumentif a field does not fit, as write_snapshot(), or if baseline is not older than snapshot.

◆ write_event()

std::vector< std::byte > rtype::write_event ( const GameEvent &  event)

Encodes an event as the bytes of RFC section 4.4: type, tick, then its fields.

Parameters
eventEvent to encode.
Returns
spawn_event_size, destroy_event_size, death_event_size or player_left_event_size bytes; 8 plus the name for PlayerJoined.

◆ write_events()

std::vector< std::vector< std::byte > > rtype::write_events ( std::span< const GameEvent >  events)

Encodes events with write_event(), for ServerNetwork::send_events().

Parameters
eventsEvents to encode, in order.
Returns
Their bytes, in the same order.

◆ write_game_start()

std::vector< std::byte > rtype::write_game_start ( )

Encodes a GameStart.

Returns
The message, without length prefix.

◆ write_inputs()

std::vector< std::byte > rtype::write_inputs ( std::span< const InputRecord >  inputs)

Encodes the payload of an Input datagram, header excluded.

The sequence of the newest input (u16), the number of inputs (u8), then the actions of each (u8), newest first; actions outside valid_actions are cleared.

Parameters
inputs1 to max_inputs_per_datagram inputs of consecutive sequences, oldest first.
Returns
The input_payload_size() bytes.
Exceptions
std::invalid_argumentif inputs is empty, too long, or not consecutive.

◆ write_join_rejected()

std::vector< std::byte > rtype::write_join_rejected ( JoinRejection  reason)

Encodes a JoinRejected.

Parameters
reasonWhy the room is not joined.
Returns
The message, without length prefix.

◆ write_join_room()

std::vector< std::byte > rtype::write_join_room ( std::uint8_t  room)

Encodes a JoinRoom.

Parameters
roomNumber of the room to join.
Returns
The message, without length prefix.

◆ write_leave_room()

std::vector< std::byte > rtype::write_leave_room ( )

Encodes a LeaveRoom.

Returns
The message, without length prefix.

◆ write_list_rooms()

std::vector< std::byte > rtype::write_list_rooms ( )

Encodes a ListRooms.

Returns
The message, without length prefix.

◆ write_list_scores()

std::vector< std::byte > rtype::write_list_scores ( )

Encodes a ListScores.

Returns
The message, without length prefix.

◆ write_login_accepted()

std::vector< std::byte > rtype::write_login_accepted ( const LoginAccepted &  accepted)

Encodes a LoginAccepted.

Parameters
acceptedToken, player and port.
Returns
The message, without length prefix.

◆ write_login_rejected()

std::vector< std::byte > rtype::write_login_rejected ( LoginRejection  reason)

Encodes a LoginRejected.

Parameters
reasonWhy the login failed.
Returns
The message, without length prefix.

◆ write_login_request()

std::vector< std::byte > rtype::write_login_request ( const LoginRequest &  request)

Encodes a LoginRequest.

Parameters
requestVersion and name; the name must fit a string.
Returns
The message, without length prefix.

◆ write_logout()

std::vector< std::byte > rtype::write_logout ( LogoutReason  reason)

Encodes a Logout.

Parameters
reasonWhy the session ends.
Returns
The message, without length prefix.

◆ write_position()

void rtype::write_position ( aegis2d::net::BitWriter &  writer,
float  position 
)

Writes a position on position_bits bits, see quantize_position().

Parameters
writerDestination.
positionPosition in logical pixels.

◆ write_room_created()

std::vector< std::byte > rtype::write_room_created ( std::uint8_t  room)

Encodes a RoomCreated.

Parameters
roomNumber of the room created.
Returns
The message, without length prefix.

◆ write_room_joined()

std::vector< std::byte > rtype::write_room_joined ( std::uint8_t  room,
std::uint8_t  player 
)

Encodes a RoomJoined.

Parameters
roomNumber of the room joined.
playerNumber of the player there.
Returns
The message, without length prefix.

◆ write_room_list()

std::vector< std::byte > rtype::write_room_list ( std::span< const RoomRecord >  rooms)

Encodes a RoomList.

Parameters
roomsThe rooms, at most max_listed_rooms, their names fitting a string.
Returns
The message, without length prefix.
Exceptions
std::invalid_argumentIf there are more than max_listed_rooms rooms.

◆ write_room_players()

std::vector< std::byte > rtype::write_room_players ( const RoomPlayers &  players)

Encodes a RoomPlayers.

Parameters
playersThe room and its players, at most 4, their names fitting a string.
Returns
The message, without length prefix.
Exceptions
std::invalid_argumentIf there are more than 4 players.

◆ write_room_rejected()

std::vector< std::byte > rtype::write_room_rejected ( RoomRejection  reason)

Encodes a RoomRejected.

Parameters
reasonWhy the room is not created.
Returns
The message, without length prefix.

◆ write_score_list()

std::vector< std::byte > rtype::write_score_list ( std::span< const ScoreRecord >  scores)

Encodes a ScoreList.

Parameters
scoresBest first; only the first max_listed_scores are written, and the names must fit a string.
Returns
The message, without length prefix.

◆ write_set_ready()

std::vector< std::byte > rtype::write_set_ready ( bool  ready)

Encodes a SetReady.

Parameters
readyWhether the player is ready to start.
Returns
The message, without length prefix.

◆ write_snapshot()

std::vector< std::vector< std::byte > > rtype::write_snapshot ( const Snapshot &  snapshot)

Encodes a snapshot as the payloads of Snapshot datagrams, header excluded.

Fields are packed bit by bit (RFC section 4.3): positions to the 1/8 px and velocities to the pixel per second, see compact.hpp, and the entities in increasing order of the low bits of their id (then of the id), each id written as the gap of its low bits to the previous record's and its high bits. Each payload holds the tick, every player record and as many entity records as fit a datagram; a snapshot with no entity still gives one payload.

Parameters
snapshotState to send: at most 7 player records, player numbers below 4 and entity kinds below 8.
Returns
The payloads, in order.
Exceptions
std::invalid_argumentif a player count, player number or entity kind does not fit its field.

◆ write_varint()

void rtype::write_varint ( aegis2d::net::BitWriter &  writer,
std::uint32_t  value 
)

Writes an id as a varint: groups of varint_group_bits bits, lowest first, each followed by a continuation bit set when another group follows.

An id below 128 takes 8 bits, below 16384 16 bits, and 40 bits at most.

Parameters
writerDestination.
valueValue to write.

◆ write_velocity()

void rtype::write_velocity ( aegis2d::net::BitWriter &  writer,
float  velocity 
)

Writes a velocity on velocity_bits bits, see quantize_velocity().

Parameters
writerDestination.
velocityVelocity in logical pixels per second.

Variable Documentation

◆ bot_stats_header

constexpr std::string_view rtype::bot_stats_header
inlineconstexpr
Initial value:
=
"bot,seconds,inputs_sent,snapshots,bytes_in_per_s,bytes_out_per_s,rtt_ms,rtt_jitter_ms,"
"loss_percent,snapshot_jitter_ms"

First line of a --stats file: the names of the columns of bot_stats_line().

◆ bot_usage

constexpr std::string_view rtype::bot_usage
inlineconstexpr
Initial value:
=
"usage: r-type_bot [--host <address>] [--port <tcp port>] [--name <player name>]\n"
" [--count <bots>] [--inputs <script file>] [--seconds <play time>]\n"
" [--seed <number>] [--stats <csv file>] [--help] [--version]\n"

Usage line printed by --help and after a command line error.

◆ change_bits

constexpr unsigned rtype::change_bits = 2
inlineconstexpr

Bits of the change of a delta record.

◆ client_usage

constexpr std::string_view rtype::client_usage
inlineconstexpr
Initial value:
=
"usage: r-type_client [--host <address>] [--port <tcp port>] [--name <player name>]\n"
" [--join] [--settings <file>] [--frames <count>]\n"
" [--screenshot <png file>] [--metrics] [--edit <waves file>]\n"
" [--help] [--version]\n"

Usage line printed by --help and after a command line error.

◆ connect_field_count

constexpr std::size_t rtype::connect_field_count = 3
inlineconstexpr

Number of fields of ConnectField.

◆ death_event_size

constexpr std::size_t rtype::death_event_size = 15
inlineconstexpr

Size of a Death event, type and tick included.

◆ default_bans_file

constexpr std::string_view rtype::default_bans_file = "bans.json"
inlineconstexpr

File of the banned addresses, in the folder the server runs from.

◆ default_max_rooms

constexpr std::uint32_t rtype::default_max_rooms = 4
inlineconstexpr

Rooms played at once when --max-rooms is not given; see GameServer.

◆ default_packet_rate

constexpr std::uint32_t rtype::default_packet_rate = 300
inlineconstexpr

Datagrams accepted per second from one address when --max-packet-rate is not given; see RateLimits.

◆ default_scores_file

constexpr std::string_view rtype::default_scores_file = "scores.json"
inlineconstexpr

File of the best scores, in the folder the server runs from.

◆ default_tcp_port

constexpr std::uint16_t rtype::default_tcp_port = 4242
inlineconstexpr

TCP port the server listens on when --tcp-port is not given.

◆ default_udp_port

constexpr std::uint16_t rtype::default_udp_port = 4243
inlineconstexpr

UDP port the server listens on when --udp-port is not given.

◆ destroy_event_size

constexpr std::size_t rtype::destroy_event_size = 18
inlineconstexpr

Size of a Destroy event, type and tick included.

◆ entity_field_bits

constexpr unsigned rtype::entity_field_bits = 4
inlineconstexpr

Bits of the fields of an EntityChange::Updated record.

◆ entity_record_fixed_bits

constexpr std::size_t rtype::entity_record_fixed_bits
inlineconstexpr
Initial value:
=
id_high_bits + kind_bits + (2 * position_bits) + (2 * velocity_bits) + frame_bits
constexpr unsigned id_high_bits
High bits of a network id, sent as they are: the generation of Entity handles.
Definition snapshot.hpp:39
constexpr unsigned position_bits
Bits of a position, sign included.
Definition compact.hpp:16
constexpr unsigned frame_bits
Bits of the frame of an entity record: frames above 15 are sent as 15.
Definition snapshot.hpp:43
constexpr unsigned kind_bits
Bits of the kind of an entity record: kinds 0 to 7.
Definition snapshot.hpp:41

Bits of an entity record besides the gap of its id's low bits: the id's high bits, kind, position, velocity and frame (69).

◆ forced_exit_status

constexpr int rtype::forced_exit_status = 130
inlineconstexpr

Exit status of a server stopped by a second signal, before its clean stop ended.

◆ frame_bits

constexpr unsigned rtype::frame_bits = 4
inlineconstexpr

Bits of the frame of an entity record: frames above 15 are sent as 15.

◆ id_high_bits

constexpr unsigned rtype::id_high_bits = 8
inlineconstexpr

High bits of a network id, sent as they are: the generation of Entity handles.

◆ id_low_bits

constexpr unsigned rtype::id_low_bits = 24
inlineconstexpr

Low bits of a network id, sent as their gap to those of the previous record: the index of the engine's Entity handles, small and dense among live entities.

◆ kind_bits

constexpr unsigned rtype::kind_bits = 3
inlineconstexpr

Bits of the kind of an entity record: kinds 0 to 7.

◆ lag_graph_count

constexpr std::size_t rtype::lag_graph_count = 7
inlineconstexpr

Number of graphs: LagGraph values are 0 to lag_graph_count - 1.

◆ lobby_player

constexpr std::uint8_t rtype::lobby_player = 255
inlineconstexpr

player of a ChatMessage whose sender is in the lobby, with no player number.

◆ max_bots

constexpr std::uint32_t rtype::max_bots = 64
inlineconstexpr

Most bots --count runs in one process.

◆ max_chat_size

constexpr std::size_t rtype::max_chat_size = 200
inlineconstexpr

Longest chat text, in bytes of UTF-8.

◆ max_inputs_per_datagram

constexpr std::size_t rtype::max_inputs_per_datagram = 4
inlineconstexpr

Inputs an Input datagram carries at most: the newest and the 3 before it, so a lost datagram's input arrives with one of the next three.

◆ max_listed_rooms

constexpr std::size_t rtype::max_listed_rooms = 64
inlineconstexpr

Most rooms a server may have, and a RoomList may hold.

◆ max_listed_scores

constexpr std::size_t rtype::max_listed_scores = 10
inlineconstexpr

Most scores in a ScoreList.

◆ max_name_size

constexpr std::size_t rtype::max_name_size = 16
inlineconstexpr

Longest player name, in bytes of UTF-8.

◆ max_room_lives

constexpr std::uint8_t rtype::max_room_lives = 9
inlineconstexpr

Most lives a room may give its players.

◆ no_entity

constexpr std::uint32_t rtype::no_entity = 0xFFFFFFFF
inlineconstexpr

Network id that names no entity, for a player out of lives.

◆ no_player

constexpr std::uint8_t rtype::no_player = 255
inlineconstexpr

Player number meaning "no player", as the owner of an enemy.

◆ no_room

constexpr std::uint32_t rtype::no_room = 0xFFFFFFFFU
inlineconstexpr

Room of a session in the lobby, out of every room (LeaveRoom, RFC section 3.7).

◆ player_left_event_size

constexpr std::size_t rtype::player_left_event_size = 7
inlineconstexpr

Size of a PlayerLeft event, type and tick included.

◆ position_bits

constexpr unsigned rtype::position_bits = 15
inlineconstexpr

Bits of a position, sign included.

◆ position_max

constexpr float rtype::position_max
inlineconstexpr
Initial value:
=
static_cast<float>((std::int32_t{1} << (position_bits - 1U)) - 1) / position_scale

Largest position sent, in logical pixels: 2047.875.

◆ position_max_error

constexpr float rtype::position_max_error = 0.5F / position_scale
inlineconstexpr

Largest error of a position within [position_min, position_max]: 1/16 px.

◆ position_min

constexpr float rtype::position_min
inlineconstexpr
Initial value:
=
-static_cast<float>(std::int32_t{1} << (position_bits - 1U)) / position_scale
constexpr std::int32_t position_scale
Steps of a position per logical pixel: positions are sent to the 1/8 px.
Definition compact.hpp:14

Smallest position sent, in logical pixels: -2048.

The play area (0 to tuning::area_width, 0 to tuning::area_height) and the entities just beyond its edges lie well within [position_min, position_max].

◆ position_scale

constexpr std::int32_t rtype::position_scale = 8
inlineconstexpr

Steps of a position per logical pixel: positions are sent to the 1/8 px.

◆ protocol_version

constexpr std::uint8_t rtype::protocol_version = 1
inlineconstexpr

Protocol version the server speaks, in LoginRequest and in the UDP header.

◆ server_name

constexpr std::string_view rtype::server_name = "server"
inlineconstexpr

name of a ChatMessage of the server itself.

◆ server_player

constexpr std::uint8_t rtype::server_player = 254
inlineconstexpr

player of a ChatMessage of the server itself, such as its administrator's say: no player has it (RFC section 3.8).

◆ server_usage

constexpr std::string_view rtype::server_usage
inlineconstexpr
Initial value:
=
"usage: r-type_server [--tcp-port <port>] [--udp-port <port>] [--waves <file.json>]\n"
" [--max-packet-rate <datagrams per second>] [--compress <bytes>]\n"
" [--max-rooms <count>] [--scores <file.json>] [--bans <file.json>]\n"
" [--trace <file.json>] [--help] [--version]\n"

Usage line printed by --help and after a command line error.

◆ short_id_gap

constexpr std::uint32_t rtype::short_id_gap = (std::uint32_t{1} << varint_group_bits) - 1U
inlineconstexpr

Largest gap between the low bits of two records' ids that keeps a record within 10 bytes (77 bits).

◆ snapshot_fixed_bits

constexpr std::size_t rtype::snapshot_fixed_bits = 32 + 3 + 16
inlineconstexpr

Bits of the tick, the player count and the entity count of a snapshot payload.

◆ spawn_event_size

constexpr std::size_t rtype::spawn_event_size = 27
inlineconstexpr

Size of a Spawn event, type and tick included.

◆ valid_actions

constexpr std::uint8_t rtype::valid_actions = 0x1FU
inlineconstexpr

Bits of the actions of an Input: up, down, left, right and fire; bits 5 to 7 must be clear.

◆ varint_group_bits

constexpr unsigned rtype::varint_group_bits = 7
inlineconstexpr

Bits of each group of a varint, followed by one continuation bit.

◆ varint_max_groups

constexpr std::size_t rtype::varint_max_groups = 5
inlineconstexpr

Most groups of a varint: 5, for 32 bits.

◆ velocity_bits

constexpr unsigned rtype::velocity_bits = 12
inlineconstexpr

Bits of a velocity, sign included; velocities are sent in whole pixels per second.

◆ velocity_max

constexpr float rtype::velocity_max
inlineconstexpr
Initial value:
=
static_cast<float>((std::int32_t{1} << (velocity_bits - 1U)) - 1)
constexpr unsigned velocity_bits
Bits of a velocity, sign included; velocities are sent in whole pixels per second.
Definition compact.hpp:29

Largest velocity sent, in logical pixels per second: 2047.

◆ velocity_max_error

constexpr float rtype::velocity_max_error = 0.5F
inlineconstexpr

Largest error of a velocity within [velocity_min, velocity_max]: 0.5 px/s.

◆ velocity_min

constexpr float rtype::velocity_min = -static_cast<float>(std::int32_t{1} << (velocity_bits - 1U))
inlineconstexpr

Smallest velocity sent, in logical pixels per second: -2048.