Module buffer

Source
Expand description

One pending command, consumed only when the host can execute it.

Push only fresh gameplay input edges inside executed simulation ticks. Advance once per executed tick, not per render frame or per issued-but-skipped update. Outcome methods never invoke game code: Executed means the command was handed to the caller, which must apply its game rules before emitting accepted feedback.

use ferravex_play::gameplay::buffer::{
    AdvanceOutcome, CommandBuffer, ConsumeOutcome, PushOutcome,
};
let mut commands = CommandBuffer::new(0.125)?;
assert_eq!(commands.push_checked(1), PushOutcome::Queued);
assert_eq!(commands.push_checked(2), PushOutcome::Replaced(1));
assert_eq!(commands.remaining_life(), Some(0.125));
assert_eq!(commands.take_if_checked(false), ConsumeOutcome::Gated);
assert_eq!(commands.advance_checked(0.0625)?, AdvanceOutcome::Pending);
assert_eq!(commands.pending(), Some(2)); // Inspection does not consume.
assert_eq!(commands.remaining_life(), Some(0.0625));
assert_eq!(commands.take_if_checked(true), ConsumeOutcome::Executed(2));
assert_eq!(commands.take_if_checked(true), ConsumeOutcome::Empty);
assert_eq!(commands.push_checked(3), PushOutcome::Queued);
assert_eq!(commands.advance_checked(0.125)?, AdvanceOutcome::Expired(3));
assert_eq!(commands.advance_checked(0.0)?, AdvanceOutcome::Empty);
assert_eq!(commands.remaining_life(), None);

Structs§

CommandBuffer
Allocation-free storage for one pending input edge with a fixed lifetime.

Enums§

AdvanceOutcome
Result of advancing the command lifetime by a validated simulation delta.
ConsumeOutcome
Result of asking for a command with a caller-supplied execution gate.
PushOutcome
Result of admitting a fresh edge into the single command slot.