pub struct ObjectiveGraph<const N: usize> { /* private fields */ }Implementations§
Source§impl<const N: usize> ObjectiveGraph<N>
impl<const N: usize> ObjectiveGraph<N>
pub fn new( rules: u64, specs: [ObjectiveSpec; N], ) -> Result<ObjectiveGraph<N>, ObjectiveError>
pub fn state(&self, i: usize) -> Option<ObjectiveState>
pub fn complete(&self, i: usize) -> bool
Sourcepub fn inspect(&self, i: usize) -> Option<ObjectiveView>
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);Sourcepub fn iter(
&self,
) -> impl ExactSizeIterator + DoubleEndedIterator + FusedIterator
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));Sourcepub fn event(
&mut self,
id: u16,
amount: u16,
serial: u64,
) -> Result<ObjectiveFrame, ObjectiveError>
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.
Sourcepub fn advance(&mut self, dt: f32) -> Result<ObjectiveFrame, ObjectiveError>
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.
pub fn last_event_serial(&self) -> u64
pub fn snapshot(&self) -> ObjectiveSnapshot<N>
pub fn restore( &mut self, saved: ObjectiveSnapshot<N>, ) -> Result<(), ObjectiveError>
Trait Implementations§
Source§impl<const N: usize> Clone for ObjectiveGraph<N>
impl<const N: usize> Clone for ObjectiveGraph<N>
Source§fn clone(&self) -> ObjectiveGraph<N>
fn clone(&self) -> ObjectiveGraph<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more