Struct ObjectiveGraph

Source
pub struct ObjectiveGraph<const N: usize> { /* private fields */ }

Implementations§

Source§

impl<const N: usize> ObjectiveGraph<N>

Source

pub fn new( rules: u64, specs: [ObjectiveSpec; N], ) -> Result<ObjectiveGraph<N>, ObjectiveError>

Source

pub fn state(&self, i: usize) -> Option<ObjectiveState>

Source

pub fn complete(&self, i: usize) -> bool

Source

pub fn inspect(&self, i: usize) -> Option<ObjectiveView>

Inspect one declaration slot without allocating or changing the graph. Returns None for any slot outside 0..N (including usize::MAX). Work is reported for locked, ready, complete and skipped objectives.

use ferravex_play::objective::{
    ObjectiveGraph, ObjectiveKind, ObjectiveProgress, ObjectiveSpec, ObjectiveState,
};
let mut graph = ObjectiveGraph::new(1, [ObjectiveSpec {
    id: 10, all: 0, any: 0, exclusive_group: 0,
    kind: ObjectiveKind::Event { id: 7, count: 3 },
}]).unwrap();
graph.event(7, 2, 1).unwrap();
let saved = graph.snapshot();
let view = graph.inspect(0).unwrap();
assert_eq!(view.spec.id, 10);
assert_eq!(view.state, ObjectiveState::Ready);
assert_eq!(view.progress, ObjectiveProgress::Event { count: 2, required: 3 });
assert_eq!(graph.snapshot(), saved);
assert_eq!(graph.last_event_serial(), 1);
assert_eq!(graph.inspect(1), None);
Source

pub fn iter( &self, ) -> impl ExactSizeIterator + DoubleEndedIterator + FusedIterator

Visit every objective in declaration order, including locked and skipped objectives, without allocating or mutating progress. This order matches prerequisite bit positions, even when dependency order differs.

A view scans at most N peers to find its exclusive winner. Iterating all views takes at most O(N * N) work, bounded by the graph’s 64-slot limit.

use ferravex_play::objective::{
    ObjectiveGraph, ObjectiveKind, ObjectiveSpec, ObjectiveState,
};
let mut graph = ObjectiveGraph::new(1, [
    ObjectiveSpec { id: 40, all: 0, any: 0, exclusive_group: 0,
        kind: ObjectiveKind::Event { id: 7, count: 1 } },
    ObjectiveSpec { id: 90, all: 1, any: 0, exclusive_group: 0,
        kind: ObjectiveKind::Gate },
]).unwrap();
let gate = graph.inspect(1).unwrap();
let blocker_ids = graph.iter().filter(|view|
    gate.blockers.missing_all & (1_u64 << view.index) != 0)
    .map(|view| view.spec.id);
assert!(blocker_ids.eq([40]));
graph.event(7, 1, 1).unwrap();
assert_eq!(graph.iter().len(), 2);
assert!(graph.iter().all(|view| view.state == ObjectiveState::Complete));
Source

pub fn event( &mut self, id: u16, amount: u16, serial: u64, ) -> Result<ObjectiveFrame, ObjectiveError>

Serials must be strictly increasing within the authoritative event stream. Older/duplicate deliveries are ignored, including after restoring a save.

Source

pub fn advance(&mut self, dt: f32) -> Result<ObjectiveFrame, ObjectiveError>

Timers newly unlocked inside this step begin at its end boundary. Parallel branch timers already active are resolved by earliest expiry, then slot.

Source

pub fn last_event_serial(&self) -> u64

Source

pub fn snapshot(&self) -> ObjectiveSnapshot<N>

Source

pub fn restore( &mut self, saved: ObjectiveSnapshot<N>, ) -> Result<(), ObjectiveError>

Trait Implementations§

Source§

impl<const N: usize> Clone for ObjectiveGraph<N>

Source§

fn clone(&self) -> ObjectiveGraph<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<const N: usize> Debug for ObjectiveGraph<N>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for ObjectiveGraph<N>

§

impl<const N: usize> RefUnwindSafe for ObjectiveGraph<N>

§

impl<const N: usize> Send for ObjectiveGraph<N>

§

impl<const N: usize> Sync for ObjectiveGraph<N>

§

impl<const N: usize> Unpin for ObjectiveGraph<N>

§

impl<const N: usize> UnwindSafe for ObjectiveGraph<N>

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.