euv-core 0.57.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::*;

/// Portable deterministic Xoshiro256** pseudo-random number generator seeded via SplitMix64.
#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
pub struct DeterministicRng {
    /// Internal 256-bit Xoshiro256** generator state.
    #[get(type(copy))]
    pub(crate) state: [u64; 4],
}

/// Seeded multi-octave procedural noise evaluator supporting Perlin, Simplex, Worley, fBm, Ridged, and Curl noise.
#[derive(Clone, Data, Debug)]
pub struct NoiseField {
    /// Original deterministic seed.
    #[get(type(copy))]
    pub(crate) seed: u64,
    /// Doubled 512-entry permutation lookup table built deterministically from `seed`.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) perm: [u8; 512],
}

/// Compact 128-bit tile domain bitmask supporting zero-allocation WFC propagation.
#[derive(Clone, Copy, Debug, Default, Eq, Getter, PartialEq)]
pub(crate) struct WfcMask {
    /// Lower 64 tile bits (`0..64`) and upper 64 tile bits (`64..128`).
    #[get(type(copy))]
    pub(crate) words: [u64; 2],
}

/// Tile weights and four-way adjacency compatibility rules for `WfcSolver2D`.
#[derive(Clone, Data, Debug)]
pub struct WfcRuleSet {
    /// Number of valid tile indices in `0..tile_count` (at most `128`).
    #[get(type(copy))]
    pub(crate) tile_count: usize,
    /// Positive selection weights per tile index.
    pub(crate) weights: Vec<f32>,
    /// Per-tile allowed neighbor masks indexed by `[tile][dir_index]`.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) compat: Vec<[WfcMask; 4]>,
}

/// Backtracking snapshot saved prior to speculative WFC tile collapse.
#[derive(Clone, Debug)]
pub(crate) struct WfcBacktrackFrame {
    /// Domain bitmask grid snapshot prior to speculative collapse.
    pub(crate) cells: Vec<WfcMask>,
    /// Index of the cell being speculatively collapsed.
    pub(crate) cell_index: usize,
    /// Remaining untried candidate tiles for `cell_index`.
    pub(crate) remaining: WfcMask,
}

/// Wave Function Collapse 2D solver with Shannon-entropy selection and deterministic backtracking.
#[derive(Clone, Data, Debug)]
pub struct WfcSolver2D {
    /// Tile weights and symmetric directional compatibility rules.
    pub(crate) rules: WfcRuleSet,
    /// Maximum backtracking steps before reporting unsatisfiable.
    #[get(type(copy))]
    pub(crate) max_backtracks: usize,
}

/// Solved 2D tile grid produced by `WfcSolver2D`.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct WfcResult2D {
    /// Solved grid width in tiles.
    #[get(type(copy))]
    pub(crate) width: usize,
    /// Solved grid height in tiles.
    #[get(type(copy))]
    pub(crate) height: usize,
    /// Row-major collapsed tile indices.
    pub(crate) tiles: Vec<usize>,
    /// Number of contradiction backtracks executed during solving.
    #[get(type(copy))]
    pub(crate) backtracks: usize,
}

/// Bridson's fast O(N) Poisson-disk blue-noise sampler in 2D and 3D.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct PoissonDiskSampler {
    /// Candidate attempts per active sample point (typically `30`).
    #[get(type(copy))]
    pub(crate) max_attempts: usize,
}

/// Configuration parameters for procedural BSP dungeon and interior generation.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct BspDungeonConfig {
    /// Total dungeon tile grid width.
    #[get(type(copy))]
    pub(crate) width: usize,
    /// Total dungeon tile grid height.
    #[get(type(copy))]
    pub(crate) height: usize,
    /// Minimum BSP leaf partition width and height.
    #[get(type(copy))]
    pub(crate) min_leaf_size: usize,
    /// Maximum BSP leaf partition width and height before forced splitting.
    #[get(type(copy))]
    pub(crate) max_leaf_size: usize,
    /// Minimum interior room width and height.
    #[get(type(copy))]
    pub(crate) min_room_size: usize,
    /// Margin reserved around rooms inside each BSP leaf.
    #[get(type(copy))]
    pub(crate) room_padding: usize,
    /// Width of carved connecting corridors in tiles.
    #[get(type(copy))]
    pub(crate) corridor_width: usize,
}

/// Axis-aligned integer room rectangle carved inside a BSP dungeon leaf.
#[derive(Clone, Copy, Data, Debug, Eq, Hash, New, PartialEq)]
pub struct BspRoomRect {
    /// Leftmost interior X tile coordinate.
    #[get(type(copy))]
    pub(crate) x: usize,
    /// Topmost interior Y tile coordinate.
    #[get(type(copy))]
    pub(crate) y: usize,
    /// Interior width in tiles.
    #[get(type(copy))]
    pub(crate) width: usize,
    /// Interior height in tiles.
    #[get(type(copy))]
    pub(crate) height: usize,
}

/// Straight orthogonal corridor segment linking two rooms or bends.
#[derive(Clone, Copy, Data, Debug, Eq, Hash, New, PartialEq)]
pub struct BspCorridorSegment {
    /// Starting tile coordinate.
    #[get(type(copy))]
    pub(crate) start: GridCoord,
    /// Ending tile coordinate.
    #[get(type(copy))]
    pub(crate) end: GridCoord,
    /// Corridor tile width.
    #[get(type(copy))]
    pub(crate) width: usize,
}

/// Doorway threshold connecting a carved corridor to a room perimeter.
#[derive(Clone, Copy, Data, Debug, Eq, Hash, New, PartialEq)]
pub struct BspDoorway {
    /// Tile coordinate of the doorway.
    #[get(type(copy))]
    pub(crate) position: GridCoord,
    /// Index into `BspDungeonMap::rooms` owning this doorway.
    #[get(type(copy))]
    pub(crate) room_index: usize,
}

/// Generated procedural dungeon containing tile grid, rooms, corridors, and doorways.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct BspDungeonMap {
    /// Map width in tiles.
    #[get(type(copy))]
    pub(crate) width: usize,
    /// Map height in tiles.
    #[get(type(copy))]
    pub(crate) height: usize,
    /// Row-major semantic tiles.
    pub(crate) tiles: Vec<BspTileKind>,
    /// Carved interior rooms.
    pub(crate) rooms: Vec<BspRoomRect>,
    /// Orthogonal corridor segments linking rooms.
    pub(crate) corridors: Vec<BspCorridorSegment>,
    /// Doorway tiles at room-corridor transitions.
    pub(crate) doors: Vec<BspDoorway>,
}

/// Internal binary space partition tree node used during dungeon construction.
#[derive(Clone, Debug)]
pub(crate) struct BspLeafNode {
    /// Partition region origin X.
    pub(crate) x: usize,
    /// Partition region origin Y.
    pub(crate) y: usize,
    /// Partition width.
    pub(crate) width: usize,
    /// Partition height.
    pub(crate) height: usize,
    /// Left child index (`usize::MAX` if leaf).
    pub(crate) left: usize,
    /// Right child index (`usize::MAX` if leaf).
    pub(crate) right: usize,
    /// Carved room index (`usize::MAX` if internal node).
    pub(crate) room_index: usize,
}

/// Stateless Binary Space Partitioning dungeon, interior, and city-block layout generator.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct BspDungeonGenerator {
    /// Active dungeon generation parameters.
    #[get(type(copy))]
    pub(crate) config: BspDungeonConfig,
}