euv-core 0.48.3

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::*;

/// Declarative physical configuration for `LiquidFluidSolver` and `GyroLiquidGameScene`.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct GyroLiquidConfig {
    /// Physical glass vessel interior width in SI meters (default `0.12 m`).
    #[get(type(copy))]
    pub(crate) vessel_width_m: f32,
    /// Physical glass vessel interior height in SI meters (default `0.09 m`).
    #[get(type(copy))]
    pub(crate) vessel_height_m: f32,
    /// Fraction of vessel area filled with liquid water (`0.20..=0.85`).
    #[get(type(copy))]
    pub(crate) fill_ratio: f32,
    /// Relative viscosity multiplier (`1.0` = pure water at 20 °C; range `0.2..=6.0`).
    #[get(type(copy))]
    pub(crate) viscosity_scale: f32,
    /// Relative surface tension multiplier (`1.0` = pure water `0.0728 N/m`; range `0.0..=3.0`).
    #[get(type(copy))]
    pub(crate) surface_tension_scale: f32,
    /// Whether Archimedes buoyant floating objects (orb + ice cube) are active.
    #[get(type(copy))]
    pub(crate) buoyant_bodies_enabled: bool,
    /// Number of PBF substeps per fixed simulation tick (`2..=4`).
    #[get(type(copy))]
    pub(crate) substeps: u32,
    /// Number of Jacobi PBF density constraint iterations per substep (`2..=6`).
    #[get(type(copy))]
    pub(crate) solver_iterations: u32,
    /// Target particle count at `fill_ratio == 0.50` (`240..=FLUID_MAX_PARTICLES`).
    #[get(type(copy))]
    pub(crate) base_particle_count: usize,
}

/// Interactive buoyant rigid body experiencing real Archimedes buoyancy, hydrodynamic drag, and wave torque.
#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
pub struct BuoyantBody {
    /// Visual and physical classification (`FloatingOrb` or `IceCube`).
    #[get(type(copy))]
    pub(crate) kind: BuoyantBodyKind,
    /// Center x-coordinate inside the vessel in SI meters.
    #[get(type(copy))]
    pub(crate) x: f32,
    /// Center y-coordinate inside the vessel in SI meters.
    #[get(type(copy))]
    pub(crate) y: f32,
    /// Linear x-velocity in `m/s`.
    #[get(type(copy))]
    pub(crate) vx: f32,
    /// Linear y-velocity in `m/s`.
    #[get(type(copy))]
    pub(crate) vy: f32,
    /// Orientation angle in radians.
    #[get(type(copy))]
    pub(crate) angle: f32,
    /// Angular velocity in `rad/s`.
    #[get(type(copy))]
    pub(crate) omega: f32,
    /// Characteristic radius (half-diagonal / sphere radius) in SI meters.
    #[get(type(copy))]
    pub(crate) radius: f32,
    /// Material mass density in `kg/m³` (`< 1000.0` floats in water).
    #[get(type(copy))]
    pub(crate) density_kgm3: f32,
    /// Live submerged volume fraction in `[0.0, 1.0]` evaluated from the fluid density field.
    #[get(type(copy))]
    pub(crate) submerged_fraction: f32,
}

/// Entrained aerated foam or rising micro-bubble sample captured for optical rendering.
#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
pub struct FluidBubble {
    /// Bubble x-coordinate inside the vessel in SI meters.
    #[get(type(copy))]
    pub(crate) x: f32,
    /// Bubble y-coordinate inside the vessel in SI meters.
    #[get(type(copy))]
    pub(crate) y: f32,
    /// Bubble x-velocity in `m/s`.
    #[get(type(copy))]
    pub(crate) vx: f32,
    /// Bubble y-velocity in `m/s`.
    #[get(type(copy))]
    pub(crate) vy: f32,
    /// Bubble radius in SI meters.
    #[get(type(copy))]
    pub(crate) radius: f32,
    /// Elapsed age in seconds.
    #[get(type(copy))]
    pub(crate) age: f32,
    /// Maximum lifetime in seconds.
    #[get(type(copy))]
    pub(crate) lifetime: f32,
    /// Surface foam intensity factor in `[0.0, 1.0]` (`1.0` = bright crest foam, `0.0` = crisp rising underwater micro-bubble).
    #[get(type(copy))]
    pub(crate) foam_factor: f32,
}

/// Read-only live physics, optical rendering, and sensor telemetry emitted by `GyroLiquidGameScene`.
#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
pub struct GyroLiquidStats {
    /// Active PBF liquid particle count.
    #[get(type(copy))]
    pub(crate) particle_count: usize,
    /// Active entrained foam and rising micro-bubble count.
    #[get(type(copy))]
    pub(crate) bubble_count: usize,
    /// Active floating buoyant body count.
    #[get(type(copy))]
    pub(crate) buoyant_body_count: usize,
    /// Total fluid kinetic energy in millijoules per meter tank depth (`mJ/m`).
    #[get(type(copy))]
    pub(crate) kinetic_energy_mj: f32,
    /// Active screen-aligned gravity x-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) gravity_x: f32,
    /// Active screen-aligned gravity y-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) gravity_y: f32,
    /// Active screen-aligned gravity z-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) gravity_z: f32,
    /// Current device/container roll tilt angle in degrees (`0.0` = upright, `+90.0` = clockwise right-down).
    #[get(type(copy))]
    pub(crate) tilt_angle_deg: f32,
    /// Peak wave free-surface elevation amplitude relative to hydrostatic mean in meters.
    #[get(type(copy))]
    pub(crate) peak_wave_height_m: f32,
    /// Last fixed-update simulation time in milliseconds.
    #[get(type(copy))]
    pub(crate) sim_time_ms: f32,
    /// Last optical liquid frame render time in milliseconds.
    #[get(type(copy))]
    pub(crate) render_time_ms: f32,
    /// Active sensor driving mode (`Auto`, `LiveHardware`, or `VirtualTilt`).
    #[get(type(copy))]
    pub(crate) sensor_mode: FluidSensorMode,
    /// Whether live hardware motion sensor data is actively driving the simulation.
    #[get(type(copy))]
    pub(crate) sensor_active: bool,
    /// Current physical vessel width in SI meters.
    #[get(type(copy))]
    pub(crate) vessel_width_m: f32,
    /// Current physical vessel height in SI meters.
    #[get(type(copy))]
    pub(crate) vessel_height_m: f32,
    /// Current liquid fill ratio (`0.20..=0.85`).
    #[get(type(copy))]
    pub(crate) fill_ratio: f32,
    /// Last optical framebuffer width in pixels.
    #[get(type(copy))]
    pub(crate) render_width: u32,
    /// Last optical framebuffer height in pixels.
    #[get(type(copy))]
    pub(crate) render_height: u32,
}

/// Zero-allocation double-buffered simulation snapshot consumed by `LiquidOpticalRenderer`.
#[derive(Clone, Data, Debug)]
pub struct FluidSimSnapshot {
    /// Physical vessel width in SI meters at snapshot capture time.
    #[get(type(copy))]
    pub(crate) vessel_width_m: f32,
    /// Physical vessel height in SI meters at snapshot capture time.
    #[get(type(copy))]
    pub(crate) vessel_height_m: f32,
    /// Smoothing kernel radius `h` in SI meters.
    #[get(type(copy))]
    pub(crate) kernel_radius_m: f32,
    /// Active fluid particle count (`<= pos_x.len()`).
    #[get(type(copy))]
    pub(crate) particle_count: usize,
    /// Active bubble/foam count (`<= bubbles.len()`).
    #[get(type(copy))]
    pub(crate) bubble_count: usize,
    /// Active buoyant body count (`<= buoyant_bodies.len()`).
    #[get(type(copy))]
    pub(crate) buoyant_body_count: usize,
    /// Active screen-aligned gravity x-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) gravity_x: f32,
    /// Active screen-aligned gravity y-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) gravity_y: f32,
    /// Active screen-aligned gravity z-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) gravity_z: f32,
    /// Monotonic simulation time in seconds for subtle caustic shimmer continuity.
    #[get(type(copy))]
    pub(crate) sim_time_secs: f32,
    /// Pre-allocated particle x-coordinates in SI meters.
    pub(crate) pos_x: Vec<f32>,
    /// Pre-allocated particle y-coordinates in SI meters.
    pub(crate) pos_y: Vec<f32>,
    /// Pre-allocated particle x-velocities in `m/s`.
    pub(crate) vel_x: Vec<f32>,
    /// Pre-allocated particle y-velocities in `m/s`.
    pub(crate) vel_y: Vec<f32>,
    /// Pre-allocated particle normalized density ratios (`ρ / ρ₀`).
    pub(crate) density_ratio: Vec<f32>,
    /// Pre-allocated active buoyant bodies.
    pub(crate) buoyant_bodies: Vec<BuoyantBody>,
    /// Pre-allocated active bubbles and foam particles.
    pub(crate) bubbles: Vec<FluidBubble>,
}

/// Real-time SI Position-Based Fluids (PBF) 2D liquid engine with non-inertial rotating-device dynamics, Archimedes buoyancy, and zero steady-state heap allocations.
#[derive(Clone, Data, Debug)]
pub struct LiquidFluidSolver {
    /// Active physical simulation configuration.
    #[get(type(copy))]
    pub(crate) config: GyroLiquidConfig,
    /// Active PBF particle count (`<= FLUID_MAX_PARTICLES`).
    #[get(type(copy))]
    pub(crate) particle_count: usize,
    /// Nominal resting particle spacing `d0` in meters.
    #[get(type(copy))]
    pub(crate) rest_spacing_m: f32,
    /// Particle area `A_p = d0²` in `m²`.
    #[get(type(copy))]
    pub(crate) particle_area_m2: f32,
    /// Particle 2D mass `m_p = ρ₀ * A_p` in `kg/m`.
    #[get(type(copy))]
    pub(crate) particle_mass_kgpm: f32,
    /// Smoothing kernel radius `h` in meters.
    #[get(type(copy))]
    pub(crate) kernel_radius_m: f32,
    /// Precomputed 2D Poly6 normalization factor `4 / (π h⁸)`.
    #[get(type(copy))]
    pub(crate) poly6_coeff: f32,
    /// Precomputed 2D Spiky gradient normalization factor `-30 / (π h⁵)`.
    #[get(type(copy))]
    pub(crate) spiky_grad_coeff: f32,
    /// Precomputed reference Poly6 weight `W_poly6(Δq, h)` for tensile instability `s_corr`.
    #[get(type(copy))]
    pub(crate) w_dq: f32,
    /// Current screen-aligned gravity `(gx, gy, gz)` in `m/s²`.
    #[get(type(copy))]
    pub(crate) gravity_x: f32,
    /// Current screen-aligned gravity y-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) gravity_y: f32,
    /// Current screen-aligned gravity z-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) gravity_z: f32,
    /// Active linear frame acceleration x-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) linear_accel_x: f32,
    /// Active linear frame acceleration y-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) linear_accel_y: f32,
    /// Decaying synthetic shake acceleration x-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) shake_accel_x: f32,
    /// Decaying synthetic shake acceleration y-component in `m/s²`.
    #[get(type(copy))]
    pub(crate) shake_accel_y: f32,
    /// Clockwise container angular velocity `Ω = -gyro_z` in `rad/s`.
    #[get(type(copy))]
    pub(crate) angular_vel_cw: f32,
    /// Previous step clockwise angular velocity for Euler angular acceleration `α = dΩ/dt`.
    #[get(type(copy))]
    pub(crate) prev_angular_vel_cw: f32,
    /// Smoothed clockwise angular acceleration `α` in `rad/s²`.
    #[get(type(copy))]
    pub(crate) angular_accel_cw: f32,
    /// Virtual desktop/simulator roll angle in radians (`0` = upright, `+π/2` = rotated CW right-down).
    #[get(type(copy))]
    pub(crate) virtual_roll_rad: f32,
    /// Virtual desktop/simulator pitch angle in radians (`0` = upright, `+π/2` = lying flat face-up).
    #[get(type(copy))]
    pub(crate) virtual_pitch_rad: f32,
    /// Previous virtual roll angle for deriving virtual rotational velocity `Ω`.
    #[get(type(copy))]
    pub(crate) prev_virtual_roll_rad: f32,
    /// Active container roll tilt angle in radians (derived from active gravity).
    #[get(type(copy))]
    pub(crate) active_roll_rad: f32,
    /// Elapsed simulation time in seconds.
    #[get(type(copy))]
    pub(crate) sim_time_secs: f32,
    /// Deterministic PRNG state word for bubble emission.
    #[get(type(copy))]
    pub(crate) rng_state: u64,
    /// Cached kinetic energy in `mJ/m`.
    #[get(type(copy))]
    pub(crate) kinetic_energy_mj: f32,
    /// Cached peak wave amplitude relative to resting hydrostatic level in meters.
    #[get(type(copy))]
    pub(crate) peak_wave_height_m: f32,
    /// Active spatial hash grid width in cells.
    #[get(type(copy))]
    pub(crate) grid_w: usize,
    /// Active spatial hash grid height in cells.
    #[get(type(copy))]
    pub(crate) grid_h: usize,
    /// Flat SoA particle x-positions in meters.
    pub(crate) pos_x: Vec<f32>,
    /// Flat SoA particle y-positions in meters.
    pub(crate) pos_y: Vec<f32>,
    /// Flat SoA predicted x-positions during PBF substeps.
    pub(crate) pred_x: Vec<f32>,
    /// Flat SoA predicted y-positions during PBF substeps.
    pub(crate) pred_y: Vec<f32>,
    /// Flat SoA particle x-velocities in `m/s`.
    pub(crate) vel_x: Vec<f32>,
    /// Flat SoA particle y-velocities in `m/s`.
    pub(crate) vel_y: Vec<f32>,
    /// Flat SoA PBF Lagrange multipliers `λ_i`.
    pub(crate) lambda: Vec<f32>,
    /// Flat SoA evaluated fluid densities `ρ_i` in `kg/m³`.
    pub(crate) density: Vec<f32>,
    /// Flat SoA 2D scalar vorticity `ω_i` in `s⁻¹`.
    pub(crate) vorticity: Vec<f32>,
    /// Flat SoA PBF position delta x scratch buffer.
    pub(crate) corr_x: Vec<f32>,
    /// Flat SoA PBF position delta y scratch buffer.
    pub(crate) corr_y: Vec<f32>,
    /// Flat SoA XSPH / vorticity velocity delta x scratch buffer.
    pub(crate) dvx_scratch: Vec<f32>,
    /// Flat SoA XSPH / vorticity velocity delta y scratch buffer.
    pub(crate) dvy_scratch: Vec<f32>,
    /// Pre-allocated spatial hash cell particle counts.
    pub(crate) cell_counts: Vec<u32>,
    /// Pre-allocated spatial hash cell CSR start offsets.
    pub(crate) cell_starts: Vec<u32>,
    /// Pre-allocated spatial hash cell write cursors.
    pub(crate) cell_cursors: Vec<u32>,
    /// Pre-allocated particle-to-cell index map.
    pub(crate) particle_cells: Vec<u32>,
    /// Pre-allocated counting-sorted particle indices grouped by spatial hash cell.
    pub(crate) sorted_indices: Vec<u32>,
    /// Flat pre-allocated per-particle neighbor index table (`FLUID_MAX_PARTICLES * FLUID_MAX_NEIGHBORS`).
    pub(crate) neighbor_indices: Vec<u16>,
    /// Flat pre-allocated per-particle cached neighbor counts (`<= FLUID_MAX_NEIGHBORS`).
    pub(crate) neighbor_counts: Vec<u8>,
    /// Pre-allocated buoyant floating rigid bodies.
    pub(crate) buoyant_bodies: Vec<BuoyantBody>,
    /// Active buoyant body count.
    #[get(type(copy))]
    pub(crate) buoyant_body_count: usize,
    /// Pre-allocated entrained micro-bubble & foam pool.
    pub(crate) bubbles: Vec<FluidBubble>,
    /// Active bubble/foam count in prefix `[0..bubble_count]`.
    #[get(type(copy))]
    pub(crate) bubble_count: usize,
}