pub struct Context {
pub globals: Vec<Value>,
pub visit_counts: HashMap<DefinitionId, u32>,
pub turn_counts: HashMap<DefinitionId, u32>,
pub turn_index: u32,
pub rng_seed: i32,
pub previous_random: i32,
}Expand description
Shared game state that lives above individual flows.
Holds globals, visit/turn tracking, and RNG state. This is the natural serialization boundary for save/load (deferred).
Multiple FlowInstances can share a single Context (matching
inklecate’s semantics where flow writes are immediately visible to other
flows), or each flow can hold its own cloned Context if the consumer
wants fork/branch/rollback semantics. The runtime’s step functions take
&mut Context (or any &mut impl ContextAccess) without prescribing
where it lives.
Fields§
§globals: Vec<Value>§visit_counts: HashMap<DefinitionId, u32>§turn_counts: HashMap<DefinitionId, u32>§turn_index: u32§rng_seed: i32§previous_random: i32Implementations§
Source§impl Context
impl Context
pub fn global(&self, idx: u32) -> &Value
pub fn set_global(&mut self, idx: u32, value: Value)
pub fn visit_count(&self, id: DefinitionId) -> u32
pub fn increment_visit(&mut self, id: DefinitionId)
pub fn turn_count(&self, id: DefinitionId) -> Option<u32>
pub fn set_turn_count(&mut self, id: DefinitionId, turn: u32)
pub fn turn_index(&self) -> u32
pub fn increment_turn_index(&mut self)
pub fn rng_seed(&self) -> i32
pub fn set_rng_seed(&mut self, seed: i32)
pub fn previous_random(&self) -> i32
pub fn set_previous_random(&mut self, val: i32)
pub fn next_random<R: StoryRng>(seed: i32) -> i32
pub fn random_sequence<R: StoryRng>(seed: i32, count: usize) -> Vec<i32>
Trait Implementations§
Source§impl ContextAccess for Context
impl ContextAccess for Context
fn global(&self, idx: u32) -> &Value
fn set_global(&mut self, idx: u32, value: Value)
fn visit_count(&self, id: DefinitionId) -> u32
fn increment_visit(&mut self, id: DefinitionId)
fn turn_count(&self, id: DefinitionId) -> Option<u32>
fn set_turn_count(&mut self, id: DefinitionId, turn: u32)
fn turn_index(&self) -> u32
fn increment_turn_index(&mut self)
fn rng_seed(&self) -> i32
fn set_rng_seed(&mut self, seed: i32)
fn previous_random(&self) -> i32
fn set_previous_random(&mut self, val: i32)
fn next_random<R: StoryRng>(&self, seed: i32) -> i32
fn random_sequence<R: StoryRng>(&self, seed: i32, count: usize) -> Vec<i32>
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more