Struct Checkpoints

Source
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,

Source

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.

Source

pub fn index(&self) -> usize

Source

pub fn respawn(&self) -> T

Source

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 });
Source

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);
Source

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);
Source

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.

Source

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,
}));
Source

pub fn snapshot(&self) -> CheckpointSnapshot

Source

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.

Source

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>
where T: Clone + Copy,

Source§

fn clone(&self) -> Checkpoints<T, N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, const N: usize> Debug for Checkpoints<T, N>
where T: Debug + Copy,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T, const N: usize> Copy for Checkpoints<T, N>
where T: Copy,

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for Checkpoints<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for Checkpoints<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for Checkpoints<T, N>
where T: Send,

§

impl<T, const N: usize> Sync for Checkpoints<T, N>
where T: Sync,

§

impl<T, const N: usize> Unpin for Checkpoints<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for Checkpoints<T, N>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.