|
R-Type
Distributed multiplayer game engine in C++
|
Buffer for storing player input history. More...
#include <InputBuffer.hpp>

Classes | |
| struct | StoredInput |
| Structure representing a stored input with metadata. More... | |
Public Member Functions | |
| InputBuffer ()=default | |
| Default constructor. | |
| ~InputBuffer ()=default | |
| Default destructor. | |
| void | addInput (uint32_t frameNumber, InputAction action, InputState state) |
| Add an input to the buffer. | |
| std::vector< StoredInput > | getInputsSince (uint32_t startFrame) const |
| Get all inputs since a given frame. | |
| void | clearUntil (uint32_t frameNumber) |
| Clear inputs up to a given frame. | |
| std::optional< StoredInput > | getLastInput () const |
| Get the last stored input. | |
| void | clear () |
| Clear the buffer completely. | |
| size_t | size () const |
| Get the number of stored inputs. | |
Private Attributes | |
| std::deque< StoredInput > | _inputs |
| uint32_t | _oldestFrame = 0 |
Buffer for storing player input history.
InputBuffer maintains a history of player inputs with their frame numbers. This history is essential for:
Client prediction architecture:
Definition at line 36 of file InputBuffer.hpp.
|
default |
Default constructor.
|
default |
Default destructor.
| void InputBuffer::addInput | ( | uint32_t | frameNumber, |
| InputAction | action, | ||
| InputState | state | ||
| ) |
Add an input to the buffer.
Stores a new input with its frame number for later replay. Inputs are maintained in chronological order.
| frameNumber | Frame number where input was captured |
| action | Player action (MOVE_UP, SHOOT, etc.) |
| state | Input state (PRESSED, RELEASED, HELD) |
Definition at line 10 of file InputBuffer.cpp.
References _inputs, and _oldestFrame.
| void InputBuffer::clear | ( | ) |
Clear the buffer completely.
Removes all stored inputs. Used during disconnection or game reset.
Definition at line 59 of file InputBuffer.cpp.
References _inputs.
| void InputBuffer::clearUntil | ( | uint32_t | frameNumber | ) |
Clear inputs up to a given frame.
Removes inputs before a certain frame to save memory. Usually called after receiving a server ACK.
| frameNumber | Frame up to which to clear (exclusive) |
Definition at line 40 of file InputBuffer.cpp.
References _inputs, and _oldestFrame.
| std::vector< InputBuffer::StoredInput > InputBuffer::getInputsSince | ( | uint32_t | startFrame | ) | const |
Get all inputs since a given frame.
Returns all stored inputs from a specific frame onwards. Used to replay inputs after a server correction.
| startFrame | Starting frame number (inclusive) |
Definition at line 28 of file InputBuffer.cpp.
References _inputs.
| std::optional< InputBuffer::StoredInput > InputBuffer::getLastInput | ( | ) | const |
Get the last stored input.
Definition at line 52 of file InputBuffer.cpp.
References _inputs.
| size_t InputBuffer::size | ( | ) | const |
Get the number of stored inputs.
Definition at line 63 of file InputBuffer.cpp.
References _inputs.
|
private |
Definition at line 126 of file InputBuffer.hpp.
Referenced by addInput(), clear(), clearUntil(), getInputsSince(), getLastInput(), and size().
|
private |
Definition at line 127 of file InputBuffer.hpp.
Referenced by addInput(), and clearUntil().