MilkContext

Struct MilkContext 

Source
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: HashMapContext

Math function registry (sin, cos, gmegabuf, …). Cold variables no longer live here — they’re in ColdSlab for index-based access from the bytecode VM.

§hot: HotVars

Hot 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: ColdSlab

Index-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

Source

pub fn new() -> Self

Create a new context with default values.

Source

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.

Source

pub fn cold_get_idx(&self, idx: usize) -> f64

Bytecode-VM fast path: read a cold-variable slot by index.

Source

pub fn cold_set_idx(&mut self, idx: usize, val: f64)

Bytecode-VM fast path: write a cold-variable slot by index.

Source

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.

Source

pub fn set(&mut self, name: &str, value: f64)

Set a variable value.

Source

pub fn get(&self, name: &str) -> Option<f64>

Get a variable value.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn inner(&self) -> &HashMapContext

Get the internal evalexpr context (cold vars + math functions).

Source

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).

Source

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.

Source

pub fn set_pixel(&mut self, x: f64, y: f64, rad: f64, ang: f64)

Set pixel position for per-pixel evaluation.

Source

pub fn set_var(&mut self, name: &str, value: f64)

Set a variable (alias for set).

Source

pub fn set_time(&mut self, time: f64)

Set time variable.

Source

pub fn set_frame(&mut self, frame: f64)

Set frame variable.

Source

pub fn set_audio(&mut self, bass: f64, mid: f64, treb: f64)

Set audio variables (bass, mid, treble).

Source

pub fn get_var(&self, name: &str) -> Option<f64>

Get a variable value (alias for get).

Trait Implementations§

Source§

impl Clone for MilkContext

Source§

fn clone(&self) -> MilkContext

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 Context for MilkContext

Source§

type NumericTypes = DefaultNumericTypes

The numeric types used for evaluation.
Source§

fn get_value(&self, identifier: &str) -> Option<&Value>

Returns the value that is linked to the given identifier.
Source§

fn call_function( &self, identifier: &str, argument: &Value, ) -> EvalexprResultValue

Calls the function that is linked to the given identifier with the given argument. If no function with the given identifier is found, this method returns EvalexprError::FunctionIdentifierNotFound.
Source§

fn are_builtin_functions_disabled(&self) -> bool

Checks if builtin functions are disabled.
Source§

fn set_builtin_functions_disabled( &mut self, disabled: bool, ) -> EvalexprResult<(), Self::NumericTypes>

Disables builtin functions if disabled is true, and enables them otherwise. If the context does not support enabling or disabling builtin functions, an error is returned.
Source§

impl ContextWithMutableVariables for MilkContext

Source§

fn set_value( &mut self, identifier: String, value: Value, ) -> EvalexprResult<(), Self::NumericTypes>

Sets the variable with the given identifier to the given value.
Source§

fn remove_value( &mut self, identifier: &str, ) -> EvalexprResult<Option<Value>, Self::NumericTypes>

Removes the variable with the given identifier from the context.
Source§

impl Debug for MilkContext

Source§

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

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

impl Default for MilkContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.