8#include "net/wire/bit_stream.h"
9#include "platform/input/input_command.h"
11namespace Vkm::Engine {
21constexpr uint32_t NET_COMMAND_REDUNDANCY = 12;
30constexpr uint32_t NET_MAX_PACKET_COMMANDS = 16;
39constexpr uint32_t NET_COMMAND_MEMORY = 64;
47constexpr uint32_t NET_DRAWN_FRACTION_BITS = 8;
50constexpr uint32_t NET_DRAWN_TICK_BITS = 32 + NET_DRAWN_FRACTION_BITS;
58constexpr uint32_t NET_AXIS_BITS = 8;
77size_t firstCommandToSend(
const std::vector<InputCommand>& unconfirmed, uint32_t heard, uint32_t sent);
96 const std::vector<InputCommand>& commands,
109bool readCommands(
BitReader& in, uint32_t actionCount, std::vector<InputCommand>& out);
123class NetCommandBuffer {
153 NetCommandBuffer() =
default;
154 ~NetCommandBuffer() =
default;
156 NetCommandBuffer(
const NetCommandBuffer& other) =
delete;
157 NetCommandBuffer& operator=(
const NetCommandBuffer& other) =
delete;
159 NetCommandBuffer(NetCommandBuffer && other) =
delete;
160 NetCommandBuffer& operator=(NetCommandBuffer && other) =
delete;
205 size_t pending()
const {
return m_commands.size(); }
217 return m_lowWater == std::numeric_limits<size_t>::max() ? m_commands.size() : m_lowWater;
243 std::vector<InputCommand> m_commands;
245 uint32_t m_newestSequence = 0;
246 uint32_t m_newestTick = 0;
247 uint32_t m_consumedSequence = 0;
248 uint32_t m_ranCommandTick = 0;
249 uint32_t m_carriedPressed = 0;
250 uint32_t m_carriedReleased = 0;
251 uint32_t m_starved = 0;
252 uint32_t m_repeatedTicks = 0;
253 uint32_t m_skippedCommands = 0;
256 size_t m_lowWater = std::numeric_limits<size_t>::max();
258 bool m_ranReal =
false;
259 bool m_started =
false;
Reads back what a BitWriter wrote, in the same order.
Definition bit_stream.h:145
Packs values to the bit into a byte buffer.
Definition bit_stream.h:19
void restartLowWater()
Start measuring lowWater() again, once it has been said.
Definition command.h:221
uint32_t skippedCommands() const
Commands passed over unrun, since clear(): skipped down to MAX_DEPTH, or pushed out of a queue at MAX...
Definition command.h:238
static constexpr size_t MAX_QUEUED
Most commands held at once, however fast they arrive.
Definition command.h:142
size_t lowWater() const
The fewest commands waiting at any take() since restartLowWater().
Definition command.h:216
uint32_t newestRunTick() const
The newest command tick actually run, in the client's numbering.
Definition command.h:187
static constexpr size_t MAX_DEPTH
Commands the queue may hold before the oldest are skipped, all at once.
Definition command.h:134
size_t pending() const
How many commands are waiting.
Definition command.h:205
uint32_t repeatedTicks() const
Ticks that ran on a repeat because nothing was waiting, since clear().
Definition command.h:230
uint32_t newestSequence() const
The newest sequence this buffer has accepted.
Definition command.h:198
void accept(const InputCommand &command)
Take one command, ignoring a sequence already seen.
static constexpr uint32_t REPEAT_TICKS
Ticks a repeat may stand in for before it stops moving the body.
Definition command.h:150
InputCommand take(uint32_t tick)
The command to run on the tick about to happen.