Module preset_slot

Module preset_slot 

Source
Expand description

Per-preset state bundle.

Groups everything that varies between presets — the preset itself, the evaluator carrying its variable context, the pre-compiled per-vertex executor, the per-wave / per-shape compiled equations, and the RenderState their per-frame evaluation produces.

MilkEngine holds one PresetSlot for the active preset plus an Option<PresetSlot> for the outgoing preset that keeps evaluating on the renderer’s secondary chain during a crossfade.

Structs§

CompiledShape 🔒
Pre-compiled equations for one shapecode_N block. Same rationale as CompiledWave — shapes can run their per-frame block up to 1024 times per shape per frame, so caching the compiled form is non-optional. Both phases use CompiledBlock so the bytecode VM kicks in transparently when the block fully lowers.
CompiledWave 🔒
Pre-compiled equation Nodes for one wavecode_N block. We compile each phase exactly once per load_preset; per-frame and per-point evaluation just runs the cached Nodes, skipping the regex-based preprocess that MilkEvaluator::eval performs every call. This is load-bearing for performance: a single 512-sample wave with 5 per-point statements runs the loop 2 560 times per frame.
PresetSlot 🔒
Everything a single preset needs to render itself: the parsed .milk data, an evaluator context owning its variables, the per-vertex executor pre-compiled against the preset’s per_pixel_equations, the per-wave / per-shape compiled equation lists, and the render state the per-frame loop writes into.

Functions§

preset_id_for 🔒
Stable preset id used to seed sampler_rand0X resolution. Derived from the preset’s comp shader text (when present) — identical shaders share the same rand pick; distinct ones diverge. Falls back to a hash of the per-frame equations when the comp shader is absent.
run_block_with_logger 🔒
Run a CompiledBlock against eval, calling on_err(node_index, err) for each evalexpr-fallback node that fails. Centralises the “prefer bytecode (infallible) / log per-equation failures on the Nodes path” pattern shared by wave_phase, shape_phase and the per-frame eval in [MilkEngine::update].