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

/// Visual and physical definition for a single tile ID inside a `TileMap`.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct TilePaletteEntry {
    /// Tile fill color.
    #[get(type(copy))]
    pub(crate) color: Color,
    /// Optional inner bevel or accent color.
    #[get(type(copy))]
    pub(crate) border_color: Color,
    /// Whether this tile blocks movement and collision queries.
    #[get(type(copy))]
    pub(crate) solid: bool,
}

/// Merged horizontal run of contiguous same-color tiles within a cached static `TileMap` chunk.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct TileRunBatch {
    /// Starting tile column index in grid space.
    #[get(type(copy))]
    pub(crate) col: usize,
    /// Tile row index in grid space.
    #[get(type(copy))]
    pub(crate) row: usize,
    /// Number of contiguous identical-color columns merged into this single rect draw.
    #[get(type(copy))]
    pub(crate) span_cols: usize,
    /// Shared fill color for the merged horizontal run.
    #[get(type(copy))]
    pub(crate) color: Color,
}

/// Cached static 16x16 tilemap chunk storing merged horizontal `TileRunBatch` spans for fast frustum-culled rendering.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct TileMapChunkBatch {
    /// Chunk column index (`col / 16`).
    #[get(type(copy))]
    pub(crate) chunk_col: usize,
    /// Chunk row index (`row / 16`).
    #[get(type(copy))]
    pub(crate) chunk_row: usize,
    /// Inclusive starting grid column.
    #[get(type(copy))]
    pub(crate) min_col: usize,
    /// Exclusive ending grid column.
    #[get(type(copy))]
    pub(crate) max_col: usize,
    /// Inclusive starting grid row.
    #[get(type(copy))]
    pub(crate) min_row: usize,
    /// Exclusive ending grid row.
    #[get(type(copy))]
    pub(crate) max_row: usize,
    /// Merged horizontal tile runs inside this static chunk.
    pub(crate) runs: Vec<TileRunBatch>,
}

/// Grid-based 2D tilemap supporting O(visible) frustum-culled rendering, cached static chunk batching, and tile solidity queries.
#[derive(Clone, Data, Debug)]
pub struct TileMap {
    /// Grid column count.
    #[get(type(copy))]
    pub(crate) columns: usize,
    /// Grid row count.
    #[get(type(copy))]
    pub(crate) rows: usize,
    /// Square tile edge size in world units.
    #[get(type(copy))]
    pub(crate) tile_size: f32,
    /// Flat row-major tile identifier grid (`0` = empty/air).
    pub(crate) cells: Vec<u16>,
    /// Palette mapping tile IDs to colors and collision flags.
    pub(crate) palette: Vec<TilePaletteEntry>,
    /// Retained cached 16x16 static chunk run batches built by `rebuild_chunk_cache`.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) cached_chunks: Vec<TileMapChunkBatch>,
    /// Monotonic revision incremented whenever tiles or palette entries change.
    #[get(type(copy))]
    pub(crate) cache_revision: u64,
    /// Revision at which `cached_chunks` was last built (`0` when stale/unbuilt).
    #[get(type(copy))]
    pub(crate) built_revision: u64,
}

/// Sprite sheet slicing descriptor over a zero-copy `Arc<[u8]>`-backed RGBA8 `ImageBuffer`.
#[derive(Clone, Data, Debug)]
pub struct SpriteSheet {
    /// Source RGBA8 sprite sheet texture (`Arc<[u8]>` zero-copy clone).
    pub(crate) texture: ImageBuffer,
    /// Individual frame width in pixels.
    #[get(type(copy))]
    pub(crate) frame_width: u32,
    /// Individual frame height in pixels.
    #[get(type(copy))]
    pub(crate) frame_height: u32,
    /// Number of frame columns in the sheet.
    #[get(type(copy))]
    pub(crate) columns: u32,
}

/// Frame-rate-driven sprite animation clip state.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct SpriteAnimator {
    /// Starting frame index in the sprite sheet.
    #[get(type(copy))]
    pub(crate) start_frame: u32,
    /// Total frame count in this clip.
    #[get(type(copy))]
    pub(crate) frame_count: u32,
    /// Playback cadence in frames per second.
    #[get(type(copy))]
    pub(crate) fps: f32,
    /// Whether playback wraps continuously.
    #[get(type(copy))]
    pub(crate) looping: bool,
    /// Elapsed clip playback time in seconds.
    #[get(type(copy))]
    pub(crate) elapsed_secs: f32,
}