R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
input.hpp
Go to the documentation of this file.
1
3#pragma once
4#include <cstddef>
5#include <cstdint>
6#include <optional>
7#include <span>
8#include <vector>
9
10namespace rtype {
11
14inline constexpr std::uint8_t valid_actions = 0x1FU;
15
18inline constexpr std::size_t max_inputs_per_datagram = 4;
19
24[[nodiscard]] constexpr std::size_t input_payload_size(std::size_t count) noexcept {
25 return 3 + count;
26}
27
32 std::uint16_t sequence = 0;
34 std::uint8_t actions = 0;
35
38 bool operator==(const InputRecord&) const = default;
39};
40
47[[nodiscard]] std::vector<std::byte> write_inputs(std::span<const InputRecord> inputs);
48
55[[nodiscard]] std::optional<std::vector<InputRecord>>
56read_inputs(std::span<const std::byte> payload);
57
58} // namespace rtype
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
std::optional< std::vector< InputRecord > > read_inputs(std::span< const std::byte > payload)
Decodes the payload of an Input datagram.
constexpr std::size_t max_inputs_per_datagram
Inputs an Input datagram carries at most: the newest and the 3 before it, so a lost datagram's input ...
Definition input.hpp:18
std::vector< std::byte > write_inputs(std::span< const InputRecord > inputs)
Encodes the payload of an Input datagram, header excluded.
constexpr std::uint8_t valid_actions
Bits of the actions of an Input: up, down, left, right and fire; bits 5 to 7 must be clear.
Definition input.hpp:14
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,...
Definition input.hpp:24
One input of the player: the actions held at one tick of the client.
Definition input.hpp:29
std::uint8_t actions
Actions held, one aegis2d::ecs::Action bit each.
Definition input.hpp:34
bool operator==(const InputRecord &) const =default
Field-by-field equality.
std::uint16_t sequence
Number of the input: 0 for the first input of a session, then one more for each, from 65535 back to 0...
Definition input.hpp:32