8#include "net/wire/bit_stream.h"
9#include "platform/input/input_command.h"
11namespace Vkm::Engine {
21constexpr uint32_t NET_COMMAND_REDUNDANCY = 12;
29constexpr uint32_t NET_MAX_PACKET_COMMANDS = 16;
38constexpr uint32_t NET_COMMAND_MEMORY = 64;
46constexpr uint32_t NET_AXIS_BITS = 8;
65size_t firstCommandToSend(
const std::vector<InputCommand>& unconfirmed, uint32_t heard, uint32_t sent);
84 const std::vector<InputCommand>& commands,
97bool readCommands(
BitReader& in, uint32_t actionCount, std::vector<InputCommand>& out);
111class NetCommandBuffer {
141 NetCommandBuffer() =
default;
142 ~NetCommandBuffer() =
default;
144 NetCommandBuffer(
const NetCommandBuffer& other) =
delete;
145 NetCommandBuffer& operator=(
const NetCommandBuffer& other) =
delete;
147 NetCommandBuffer(NetCommandBuffer && other) =
delete;
148 NetCommandBuffer& operator=(NetCommandBuffer && other) =
delete;
193 size_t pending()
const {
return m_commands.size(); }
205 return m_lowWater == std::numeric_limits<size_t>::max() ? m_commands.size() : m_lowWater;
231 std::vector<InputCommand> m_commands;
233 uint32_t m_newestSequence = 0;
234 uint32_t m_newestTick = 0;
235 uint32_t m_consumedSequence = 0;
236 uint32_t m_ranCommandTick = 0;
237 uint32_t m_carriedPressed = 0;
238 uint32_t m_carriedReleased = 0;
239 uint32_t m_starved = 0;
240 uint32_t m_repeatedTicks = 0;
241 uint32_t m_skippedCommands = 0;
244 size_t m_lowWater = std::numeric_limits<size_t>::max();
246 bool m_ranReal =
false;
247 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:209
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:226
static constexpr size_t MAX_QUEUED
Most commands held at once, however fast they arrive.
Definition command.h:130
size_t lowWater() const
The fewest commands waiting at any take() since restartLowWater().
Definition command.h:204
uint32_t newestRunTick() const
The newest command tick actually run, in the client's numbering.
Definition command.h:175
static constexpr size_t MAX_DEPTH
Commands the queue may hold before the oldest are skipped, all at once.
Definition command.h:122
size_t pending() const
How many commands are waiting.
Definition command.h:193
uint32_t repeatedTicks() const
Ticks that ran on a repeat because nothing was waiting, since clear().
Definition command.h:218
uint32_t newestSequence() const
The newest sequence this buffer has accepted.
Definition command.h:186
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:138
InputCommand take(uint32_t tick)
The command to run on the tick about to happen.