pub struct MilkContext {
context: HashMapContext,
hot: HotVars,
q_vars: [f64; 64],
q_values_mirror: [Value; 64],
cold: ColdSlab,
}Expand description
Execution context containing all Milkdrop variables.
Fields§
§context: HashMapContextMath function registry (sin, cos, gmegabuf, …). Cold variables
no longer live here — they’re in ColdSlab for index-based
access from the bytecode VM.
hot: HotVarsHot per-point / per-vertex / per-shape scratch slots — see HotVars.
q_vars: [f64; 64]q1..q64 channel storage. q_vars is the f64 fast path the
bytecode VM addresses by index; q_values_mirror is kept in
sync so evalexpr’s Context::get_value can return &Value.
q_values_mirror: [Value; 64]§cold: ColdSlabIndex-based slab for cold variables — used by the bytecode VM
(resolved at compile time) and by the evalexpr API (resolved on
every get_value/set_value call).
Implementations§
Source§impl MilkContext
impl MilkContext
Sourcepub fn cold_intern(&mut self, name: &str) -> usize
pub fn cold_intern(&mut self, name: &str) -> usize
Intern a cold-variable name into the slab and return its index.
Called by the bytecode compiler so Op::LoadCold(idx) /
Op::StoreCold(idx) can address the slot directly at run time.
Sourcepub fn cold_get_idx(&self, idx: usize) -> f64
pub fn cold_get_idx(&self, idx: usize) -> f64
Bytecode-VM fast path: read a cold-variable slot by index.
Sourcepub fn cold_set_idx(&mut self, idx: usize, val: f64)
pub fn cold_set_idx(&mut self, idx: usize, val: f64)
Bytecode-VM fast path: write a cold-variable slot by index.
Sourcefn seed_cold_defaults(cold: &mut ColdSlab)
fn seed_cold_defaults(cold: &mut ColdSlab)
Pre-seed the cold slab with MD2’s documented default values. Mirrors
the old init_defaults behaviour (which used to write into the
HashMapContext) but routes the values through the slab so the
bytecode VM and the evalexpr Context impls below see the same
initial state.
Sourcepub fn hot_get_idx(&self, idx: usize) -> f64
pub fn hot_get_idx(&self, idx: usize) -> f64
Bytecode-VM fast path: read a hot var by slot index (one of the
HOT_* constants). One f64 array load — no enum-tag match.
Sourcepub fn hot_set_idx(&mut self, idx: usize, value: f64)
pub fn hot_set_idx(&mut self, idx: usize, value: f64)
Bytecode-VM fast path: write a hot var by slot index. Updates the
f64 array used by Self::hot_get_idx and the parallel Value
mirror used by evalexpr’s Context::get_value contract.
Sourcepub fn q_get_idx(&self, idx: usize) -> f64
pub fn q_get_idx(&self, idx: usize) -> f64
Bytecode-VM fast path: read q[idx] where idx is 0..63 (so
q_get_idx(0) returns the value of q1).
Sourcepub fn q_set_idx(&mut self, idx: usize, value: f64)
pub fn q_set_idx(&mut self, idx: usize, value: f64)
Bytecode-VM fast path: write q[idx]. Updates the f64 array used
by Self::q_get_idx and the parallel Value mirror used by
evalexpr’s Context::get_value contract.
Sourcepub fn inner(&self) -> &HashMapContext
pub fn inner(&self) -> &HashMapContext
Get the internal evalexpr context (cold vars + math functions).
Sourcepub fn inner_mut(&mut self) -> &mut HashMapContext
pub fn inner_mut(&mut self) -> &mut HashMapContext
Get a mutable reference to the internal evalexpr context. Most
call sites should instead pass &mut MilkContext directly to
evalexpr (the Context / ContextWithMutableVariables impls
below route hot-path reads/writes to HotVars without a
String alloc).
Sourcepub fn q_vars(&self) -> [f64; 64]
pub fn q_vars(&self) -> [f64; 64]
Get a snapshot of all 64 q variables as f64. The internal
storage is [Value; 64] (to support evalexpr’s &Value return
type for q-channel reads), so this conversion is on demand.
Sourcepub fn set_pixel(&mut self, x: f64, y: f64, rad: f64, ang: f64)
pub fn set_pixel(&mut self, x: f64, y: f64, rad: f64, ang: f64)
Set pixel position for per-pixel evaluation.
Trait Implementations§
Source§impl Clone for MilkContext
impl Clone for MilkContext
Source§fn clone(&self) -> MilkContext
fn clone(&self) -> MilkContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Context for MilkContext
impl Context for MilkContext
Source§type NumericTypes = DefaultNumericTypes
type NumericTypes = DefaultNumericTypes
Source§fn get_value(&self, identifier: &str) -> Option<&Value>
fn get_value(&self, identifier: &str) -> Option<&Value>
Source§fn call_function(
&self,
identifier: &str,
argument: &Value,
) -> EvalexprResultValue
fn call_function( &self, identifier: &str, argument: &Value, ) -> EvalexprResultValue
EvalexprError::FunctionIdentifierNotFound.Source§fn are_builtin_functions_disabled(&self) -> bool
fn are_builtin_functions_disabled(&self) -> bool
Source§fn set_builtin_functions_disabled(
&mut self,
disabled: bool,
) -> EvalexprResult<(), Self::NumericTypes>
fn set_builtin_functions_disabled( &mut self, disabled: bool, ) -> EvalexprResult<(), Self::NumericTypes>
disabled is true, and enables them otherwise.
If the context does not support enabling or disabling builtin functions, an error is returned.