euv-core 0.52.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Pops a recycled `Box<GpuOceanScenePass>` (preserving its `wake_rgba8` and `boat_vertices` capacities) or allocates a fresh default pass on first frame.
///
/// # Returns
///
/// - `Box<GpuOceanScenePass>` - Ready ocean scene pass container for zero-allocation population.
#[must_use]
pub fn take_recycled_ocean_scene_pass() -> Box<GpuOceanScenePass> {
    RECYCLED_OCEAN_SCENE_PASS
        .try_with(|slot: &RefCell<Option<Box<GpuOceanScenePass>>>| {
            slot.try_borrow_mut()
                .ok()
                .and_then(|mut guard: RefMut<'_, Option<Box<GpuOceanScenePass>>>| guard.take())
        })
        .ok()
        .flatten()
        .unwrap_or_default()
}

/// Pops a recycled `Box<GpuWorld3dScenePass>` (preserving its `instances` and `draw_batches` capacities) or allocates a fresh default pass on first frame.
///
/// # Returns
///
/// - `Box<GpuWorld3dScenePass>` - Ready 3D scene pass container for zero-allocation population.
#[must_use]
pub fn take_recycled_world3d_scene_pass() -> Box<GpuWorld3dScenePass> {
    RECYCLED_WORLD3D_SCENE_PASS
        .try_with(|slot: &RefCell<Option<Box<GpuWorld3dScenePass>>>| {
            slot.try_borrow_mut()
                .ok()
                .and_then(|mut guard: RefMut<'_, Option<Box<GpuWorld3dScenePass>>>| guard.take())
        })
        .ok()
        .flatten()
        .unwrap_or_default()
}

/// Stores a completed `DirectGpuScenePass` allocation in the per-thread recycle slot so the next frame reuses its heap capacity with zero allocations.
///
/// # Arguments
///
/// - `Option<DirectGpuScenePass>` - Completed GPU scene pass taken from `DisplayList` before frame reset.
pub(crate) fn recycle_gpu_scene_pass(pass: Option<DirectGpuScenePass>) {
    match pass {
        Some(DirectGpuScenePass::OceanFluid(ocean)) => {
            let _: Option<()> = RECYCLED_OCEAN_SCENE_PASS
                .try_with(|slot: &RefCell<Option<Box<GpuOceanScenePass>>>| {
                    if let Ok(mut guard) = slot.try_borrow_mut() {
                        *guard = Some(ocean);
                    }
                })
                .ok();
        }
        Some(DirectGpuScenePass::World3d(world3d)) => {
            let _: Option<()> = RECYCLED_WORLD3D_SCENE_PASS
                .try_with(|slot: &RefCell<Option<Box<GpuWorld3dScenePass>>>| {
                    if let Ok(mut guard) = slot.try_borrow_mut() {
                        *guard = Some(world3d);
                    }
                })
                .ok();
        }
        None => {}
    }
}

/// Updates the per-thread active offscreen 3D/water workload scale published by `FrameBudgetStabilizer` for the current frame.
///
/// # Arguments
///
/// - `f32` - Stabilized offscreen workload resolution scale clamped to `0.35..=1.0`.
pub(crate) fn set_active_scene_workload_scale(scale: f32) {
    let clamped: f32 = if scale.is_finite() {
        scale.clamp(0.35, 1.0)
    } else {
        1.0
    };
    let _: Option<()> = ACTIVE_SCENE_WORKLOAD_SCALE
        .try_with(|cell: &Cell<f32>| {
            cell.set(clamped);
        })
        .ok();
}

/// Returns the active offscreen 3D/water workload scale for the current frame (`1.0` = `100%` maximum visual quality).
///
/// # Returns
///
/// - `f32` - Stabilized offscreen workload scale in `[0.35, 1.0]`.
#[must_use]
pub(crate) fn active_scene_workload_scale() -> f32 {
    ACTIVE_SCENE_WORKLOAD_SCALE
        .try_with(Cell::get)
        .unwrap_or(1.0)
}