pub fn draw_sprites_parallel(
target: DrawTarget<'_>,
cam: &CameraState,
settings: &OpticastSettings,
lighting: &SpriteLighting<'_>,
sprites: &[Sprite],
) -> u32Expand description
Draw a sprite into a framebuffer + z-buffer.
Top-level dispatcher mirroring voxlap5.c:9818-9828:
- Skips on
flags & INVISIBLE. - Skips on
flags & KFA(animation path; out of scope for R6). - Skips on
flags & NO_Z(handled bydrawboundcubenozsse, not yet ported — the four oracle sprite poses all use z-tested rendering).
Otherwise: cull → setup math → 9-arm per-voxel iteration →
per-voxel rasterize via the R6.4 drawboundcubesse port.
Returns the total number of pixels written across all voxels of
the sprite (== sum of z-test passes). Zero means the sprite
produced no visible pixels (culled, fully behind near plane, or
totally occluded).
Render a batch of sprites in parallel via rayon::par_iter.
Each sprite runs its own draw_sprite pass on its own thread,
writing to the shared DrawTarget (raw pointers; `Copy + Send
- Sync`) under the z-test arbitration contract: a pixel write only fires when the new sprite’s z is strictly less than the current zbuffer value. For non-overlapping sprites the writes are pairwise-disjoint and the output is byte-identical to a sequential pass over the same sprite list. For overlapping pixels, two sprites at exactly tied z-values produce a non-deterministic last-writer-wins outcome — visually indistinguishable but hash-non-deterministic.
Returns the sum of draw_sprite return values (total pixels
written across all sprites).
RAYON_NUM_THREADS=1 (or no parallelism worth) ⇒ effectively
sequential; rayon falls back to running each closure on the
calling thread without contention.
Use this for engine scenes with dozens-to-hundreds of sprites; the per-sprite overhead amortises well past ~4 sprites on consumer-class hardware.