Module wave_phase

Module wave_phase 

Source
Expand description

Custom-wave (wavecode_N) phase of the engine update loop.

Runs each enabled wave’s pre-compiled per_frame_init (once per preset load), per_frame, and per_point blocks, then returns the resulting vertex stream + per-wave batches. Callers (engine) push the result to the right onedrop_renderer::RenderChain — primary for the current preset, secondary for the outgoing preset during a transition.

§Parallelism

Each of the up-to-4 enabled wavecode blocks is independent (per-MD2, waves don’t share state across blocks within one frame), so the four per-wave per_frame + 512-sample loops fan out across rayon workers. The dominant cost in 144.milk / 207.milk class presets is custom waves’ per_point eval (~37 ms / frame on a 12-thread box, single-threaded). After this parallelisation: ~10-12 ms.

Structs§

WaveOutput 🔒
Output of one wave’s sample loop: its vertex slice + the batch metadata describing how to draw it. Collected per wave so the parallel pass doesn’t need a shared mutex on the global vertex buffer.

Constants§

PARALLEL_SAMPLES_THRESHOLD 🔒
Minimum sample count to bother parallelising the per_point loop. Below this, rayon’s map_init overhead (per-worker MilkEvaluator clone + work-stealing dispatch) exceeds the eval time we’d save — stay sequential. 64 lines up roughly with the smallest “dense” waves we care about (the typical preset uses 256-512).

Functions§

compute_custom_waves 🔒
Run every enabled wavecode_N block in slot’s preset and return the per-frame vertex stream + batches. Returns empty Vecs when no preset is loaded or no waves are enabled — feed those through to the renderer’s update_custom_waves to reset its buffers.
compute_one_wave 🔒