5#include <aegis2d/net/bits.hpp>
34 static_cast<float>((std::int32_t{1} << (
velocity_bits - 1U)) - 1);
65[[nodiscard]] std::optional<float>
read_position(aegis2d::net::BitReader& reader)
noexcept;
74[[nodiscard]] std::optional<float>
read_velocity(aegis2d::net::BitReader& reader)
noexcept;
81void write_varint(aegis2d::net::BitWriter& writer, std::uint32_t value);
88[[nodiscard]] std::optional<std::uint32_t>
read_varint(aegis2d::net::BitReader& reader)
noexcept;
92[[nodiscard]] std::size_t
varint_bits(std::uint32_t value)
noexcept;
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
constexpr float position_max_error
Largest error of a position within [position_min, position_max]: 1/16 px.
Definition compact.hpp:26
constexpr float position_max
Largest position sent, in logical pixels: 2047.875.
Definition compact.hpp:23
void write_velocity(aegis2d::net::BitWriter &writer, float velocity)
Writes a velocity on velocity_bits bits, see quantize_velocity().
float dequantize_position(std::int32_t steps) noexcept
Position of a number of steps.
std::int32_t quantize_position(float position) noexcept
Rounds a position to the nearest 1/8 px, clamped to [position_min, position_max].
std::optional< float > read_position(aegis2d::net::BitReader &reader) noexcept
Reads a position written by write_position().
constexpr unsigned position_bits
Bits of a position, sign included.
Definition compact.hpp:16
constexpr float velocity_max_error
Largest error of a velocity within [velocity_min, velocity_max]: 0.5 px/s.
Definition compact.hpp:36
constexpr unsigned varint_group_bits
Bits of each group of a varint, followed by one continuation bit.
Definition compact.hpp:39
std::int32_t quantize_velocity(float velocity) noexcept
Rounds a velocity to the nearest whole pixel per second, clamped to [velocity_min,...
void write_position(aegis2d::net::BitWriter &writer, float position)
Writes a position on position_bits bits, see quantize_position().
constexpr float velocity_max
Largest velocity sent, in logical pixels per second: 2047.
Definition compact.hpp:33
std::optional< std::uint32_t > read_varint(aegis2d::net::BitReader &reader) noexcept
Reads a varint written by write_varint().
constexpr float position_min
Smallest position sent, in logical pixels: -2048.
Definition compact.hpp:20
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 continua...
std::optional< float > read_velocity(aegis2d::net::BitReader &reader) noexcept
Reads a velocity written by write_velocity().
constexpr float velocity_min
Smallest velocity sent, in logical pixels per second: -2048.
Definition compact.hpp:31
std::size_t varint_bits(std::uint32_t value) noexcept
Size of a varint.
constexpr std::size_t varint_max_groups
Most groups of a varint: 5, for 32 bits.
Definition compact.hpp:41
constexpr unsigned velocity_bits
Bits of a velocity, sign included; velocities are sent in whole pixels per second.
Definition compact.hpp:29
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