euv_core/game/tilemap/struct.rs
1use super::*;
2
3/// Visual and physical definition for a single tile ID inside a `TileMap`.
4#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
5pub struct TilePaletteEntry {
6 /// Tile fill color.
7 #[get(type(copy))]
8 pub(crate) color: Color,
9 /// Optional inner bevel or accent color.
10 #[get(type(copy))]
11 pub(crate) border_color: Color,
12 /// Whether this tile blocks movement and collision queries.
13 #[get(type(copy))]
14 pub(crate) solid: bool,
15}
16
17/// Merged horizontal run of contiguous same-color tiles within a cached static `TileMap` chunk.
18#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
19pub struct TileRunBatch {
20 /// Starting tile column index in grid space.
21 #[get(type(copy))]
22 pub(crate) col: usize,
23 /// Tile row index in grid space.
24 #[get(type(copy))]
25 pub(crate) row: usize,
26 /// Number of contiguous identical-color columns merged into this single rect draw.
27 #[get(type(copy))]
28 pub(crate) span_cols: usize,
29 /// Shared fill color for the merged horizontal run.
30 #[get(type(copy))]
31 pub(crate) color: Color,
32}
33
34/// Cached static 16x16 tilemap chunk storing merged horizontal `TileRunBatch` spans for fast frustum-culled rendering.
35#[derive(Clone, Data, Debug, Default, PartialEq)]
36pub struct TileMapChunkBatch {
37 /// Chunk column index (`col / 16`).
38 #[get(type(copy))]
39 pub(crate) chunk_col: usize,
40 /// Chunk row index (`row / 16`).
41 #[get(type(copy))]
42 pub(crate) chunk_row: usize,
43 /// Inclusive starting grid column.
44 #[get(type(copy))]
45 pub(crate) min_col: usize,
46 /// Exclusive ending grid column.
47 #[get(type(copy))]
48 pub(crate) max_col: usize,
49 /// Inclusive starting grid row.
50 #[get(type(copy))]
51 pub(crate) min_row: usize,
52 /// Exclusive ending grid row.
53 #[get(type(copy))]
54 pub(crate) max_row: usize,
55 /// Merged horizontal tile runs inside this static chunk.
56 pub(crate) runs: Vec<TileRunBatch>,
57}
58
59/// Grid-based 2D tilemap supporting O(visible) frustum-culled rendering, cached static chunk batching, and tile solidity queries.
60#[derive(Clone, Data, Debug)]
61pub struct TileMap {
62 /// Grid column count.
63 #[get(type(copy))]
64 pub(crate) columns: usize,
65 /// Grid row count.
66 #[get(type(copy))]
67 pub(crate) rows: usize,
68 /// Square tile edge size in world units.
69 #[get(type(copy))]
70 pub(crate) tile_size: f32,
71 /// Flat row-major tile identifier grid (`0` = empty/air).
72 pub(crate) cells: Vec<u16>,
73 /// Palette mapping tile IDs to colors and collision flags.
74 pub(crate) palette: Vec<TilePaletteEntry>,
75 /// Retained cached 16x16 static chunk run batches built by `rebuild_chunk_cache`.
76 #[get(skip)]
77 #[get_mut(skip)]
78 #[set(skip)]
79 pub(crate) cached_chunks: Vec<TileMapChunkBatch>,
80 /// Monotonic revision incremented whenever tiles or palette entries change.
81 #[get(type(copy))]
82 pub(crate) cache_revision: u64,
83 /// Revision at which `cached_chunks` was last built (`0` when stale/unbuilt).
84 #[get(type(copy))]
85 pub(crate) built_revision: u64,
86}
87
88/// Sprite sheet slicing descriptor over a zero-copy `Arc<[u8]>`-backed RGBA8 `ImageBuffer`.
89#[derive(Clone, Data, Debug)]
90pub struct SpriteSheet {
91 /// Source RGBA8 sprite sheet texture (`Arc<[u8]>` zero-copy clone).
92 pub(crate) texture: ImageBuffer,
93 /// Individual frame width in pixels.
94 #[get(type(copy))]
95 pub(crate) frame_width: u32,
96 /// Individual frame height in pixels.
97 #[get(type(copy))]
98 pub(crate) frame_height: u32,
99 /// Number of frame columns in the sheet.
100 #[get(type(copy))]
101 pub(crate) columns: u32,
102}
103
104/// Frame-rate-driven sprite animation clip state.
105#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
106pub struct SpriteAnimator {
107 /// Starting frame index in the sprite sheet.
108 #[get(type(copy))]
109 pub(crate) start_frame: u32,
110 /// Total frame count in this clip.
111 #[get(type(copy))]
112 pub(crate) frame_count: u32,
113 /// Playback cadence in frames per second.
114 #[get(type(copy))]
115 pub(crate) fps: f32,
116 /// Whether playback wraps continuously.
117 #[get(type(copy))]
118 pub(crate) looping: bool,
119 /// Elapsed clip playback time in seconds.
120 #[get(type(copy))]
121 pub(crate) elapsed_secs: f32,
122}