pub struct Checkpoints<T, const N: usize>where
T: Copy,{ /* private fields */ }Implementations§
Source§impl<T, const N: usize> Checkpoints<T, N>where
T: Copy,
impl<T, const N: usize> Checkpoints<T, N>where
T: Copy,
Sourcepub fn new(rules: u64, anchors: [T; N]) -> Result<Checkpoints<T, N>, LoopError>
pub fn new(rules: u64, anchors: [T; N]) -> Result<Checkpoints<T, N>, LoopError>
Hosts validate anchor geometry and supply a stable nonzero rules ID.
Change that ID whenever the route’s anchors, order or recovery rules change;
this generic container cannot derive a fingerprint from arbitrary T.
pub fn index(&self) -> usize
pub fn respawn(&self) -> T
Sourcepub fn current_anchor(&self) -> CheckpointAnchor<T>
pub fn current_anchor(&self) -> CheckpointAnchor<T>
Inspect the current respawn anchor with its authored index.
use ferravex_play::gameplay::checkpoint::{CheckpointAnchor, Checkpoints};
let checkpoints = Checkpoints::new(4, [10, 20]).unwrap();
assert_eq!(checkpoints.current_anchor(), CheckpointAnchor { index: 0, anchor: 10 });Sourcepub fn next_anchor(&self) -> Option<CheckpointAnchor<T>>
pub fn next_anchor(&self) -> Option<CheckpointAnchor<T>>
Inspect the next eligible anchor, or None at the last authored anchor.
This never wraps to the start or advances progress.
use ferravex_play::gameplay::checkpoint::{CheckpointAnchor, Checkpoints};
let mut checkpoints = Checkpoints::new(4, [10, 20]).unwrap();
assert_eq!(checkpoints.next_anchor(), Some(CheckpointAnchor { index: 1, anchor: 20 }));
checkpoints.activate(1).unwrap();
assert_eq!(checkpoints.next_anchor(), None);Sourcepub fn recovery(&self) -> CheckpointRecovery<T>
pub fn recovery(&self) -> CheckpointRecovery<T>
Describe recovery without consuming it or mutating checkpoint/world state. Repeated recovery remains available, including at a terminal anchor. The host decides whether to respawn and resets entities, velocity, camera history and any other world state in its own recovery transaction.
use ferravex_play::gameplay::checkpoint::{CheckpointRecovery, Checkpoints};
let checkpoints = Checkpoints::new(4, [(10, 5)]).unwrap();
let recovery: CheckpointRecovery<(i32, i32)> = checkpoints.recovery();
assert_eq!(recovery.current.index, 0);
assert_eq!(recovery.current.anchor, (10, 5));
assert_eq!(recovery.next, None);
assert_eq!(checkpoints.recovery(), recovery);Sourcepub fn activate(&mut self, index: usize) -> Result<bool, LoopError>
pub fn activate(&mut self, index: usize) -> Result<bool, LoopError>
Old/duplicate checkpoints cannot move the respawn backward. Skipping an authored checkpoint fails, preventing exit triggers from bypassing a route.
Sourcepub fn activate_with_outcome(
&mut self,
index: usize,
) -> Result<CheckpointActivation, LoopError>
pub fn activate_with_outcome( &mut self, index: usize, ) -> Result<CheckpointActivation, LoopError>
Activate the next anchor, distinguishing accepted, duplicate and stale
triggers. Only Activated changes state or warrants checkpoint feedback.
Out-of-range indices return Invalid; skipping ahead returns Unavailable.
Both errors leave progress unchanged.
use ferravex_play::gameplay::checkpoint::{CheckpointActivation, Checkpoints};
let mut checkpoints = Checkpoints::new(4, [10, 20, 30]).unwrap();
assert_eq!(checkpoints.activate_with_outcome(1), Ok(CheckpointActivation::Activated {
previous_index: 0, index: 1,
}));
assert_eq!(checkpoints.activate_with_outcome(1), Ok(CheckpointActivation::Current { index: 1 }));
assert_eq!(checkpoints.activate_with_outcome(0), Ok(CheckpointActivation::Stale {
index: 0, current_index: 1,
}));pub fn snapshot(&self) -> CheckpointSnapshot
Sourcepub fn restore(&mut self, saved: CheckpointSnapshot) -> Result<(), LoopError>
pub fn restore(&mut self, saved: CheckpointSnapshot) -> Result<(), LoopError>
Trusted save restoration only. This changes respawn state, not world state; the host restores inventory/objectives with its existing save transaction.
Sourcepub fn restore_with_outcome(
&mut self,
saved: CheckpointSnapshot,
) -> Result<CheckpointRestore, CheckpointRestoreError>
pub fn restore_with_outcome( &mut self, saved: CheckpointSnapshot, ) -> Result<CheckpointRestore, CheckpointRestoreError>
Restore a trusted snapshot, reporting a rewind, advance or unchanged index.
Rules and index are validated before mutation; either error preserves all
checkpoint state. A matching old save may rewind and a later save may skip
anchors, as with Self::restore. This is not a gameplay trigger or a
network freshness check; CheckpointSnapshot has no generation field.
Only checkpoint progress is restored. The host must coordinate its world
transaction before using Self::recovery to apply the resulting anchor.
use ferravex_play::gameplay::checkpoint::{
CheckpointRestore, CheckpointRestoreError, CheckpointSnapshot, Checkpoints,
};
let mut checkpoints = Checkpoints::new(4, [10, 20, 30]).unwrap();
let start = checkpoints.snapshot();
checkpoints.activate(1).unwrap();
assert_eq!(checkpoints.restore_with_outcome(start), Ok(CheckpointRestore::Rewound {
previous_index: 1, index: 0,
}));
let bad = CheckpointSnapshot { rules: 5, index: 2 };
assert_eq!(checkpoints.restore_with_outcome(bad), Err(CheckpointRestoreError::RulesMismatch {
expected: 4, actual: 5,
}));
assert_eq!(checkpoints.snapshot(), start);Trait Implementations§
Source§impl<T, const N: usize> Clone for Checkpoints<T, N>
impl<T, const N: usize> Clone for Checkpoints<T, N>
Source§fn clone(&self) -> Checkpoints<T, N>
fn clone(&self) -> Checkpoints<T, N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more