summaryrefslogtreecommitdiff
path: root/src/sim/cell_manager/chunk.rs
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-23 12:14:19 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-23 12:14:19 -0700
commite6742f59102f2beb305b813d7f0ee1d544bbc3e0 (patch)
treea4787655e441b4fb7acebf51373a8f3f7afbd9a4 /src/sim/cell_manager/chunk.rs
parent5f137b41ebeadfca3907221713f85f2c9fe431bf (diff)
separate data from cells
Diffstat (limited to 'src/sim/cell_manager/chunk.rs')
-rw-r--r--src/sim/cell_manager/chunk.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/sim/cell_manager/chunk.rs b/src/sim/cell_manager/chunk.rs
index 463242d..3bf1e9f 100644
--- a/src/sim/cell_manager/chunk.rs
+++ b/src/sim/cell_manager/chunk.rs
@@ -1,13 +1,16 @@
+use fxhash::FxHashMap;
use glam::IVec2;
use crate::{
config::{CELLS_IN_CHUNK, CHUNK_SIZE},
content::materials::MaterialForm,
- sim::{cell::Cell, lib::marching_squares::Marchable},
+ sim::{cell::Cell, entity::EntityId, lib::marching_squares::Marchable},
};
pub struct Chunk {
pub cells: Box<[Cell; CELLS_IN_CHUNK]>,
+ pub cell_data: FxHashMap<usize, u16>,
+ pub cell_entity: FxHashMap<usize, EntityId>,
pub sleeping: bool,
pub needs_texture_update: bool,
}
@@ -22,9 +25,35 @@ impl Chunk {
self.cells[x as usize + y as usize * CHUNK_SIZE as usize] = cell;
}
+ #[inline]
+ pub fn get_data_at_local_position(&self, x: u8, y: u8) -> Option<u16> {
+ self.cell_data
+ .get(&(x as usize + y as usize * CHUNK_SIZE as usize))
+ .copied()
+ }
+ #[inline]
+ pub fn set_data_at_local_position(&mut self, x: u8, y: u8, data: u16) {
+ self.cell_data
+ .insert(x as usize + y as usize * CHUNK_SIZE as usize, data);
+ }
+
+ #[inline]
+ pub fn get_entity_at_local_position(&self, x: u8, y: u8) -> Option<EntityId> {
+ self.cell_entity
+ .get(&(x as usize + y as usize * CHUNK_SIZE as usize))
+ .copied()
+ }
+ #[inline]
+ pub fn set_entity_at_local_position(&mut self, x: u8, y: u8, entity_id: EntityId) {
+ self.cell_entity
+ .insert(x as usize + y as usize * CHUNK_SIZE as usize, entity_id);
+ }
+
pub fn void() -> Self {
Chunk {
cells: Box::new([Cell::void(); CELLS_IN_CHUNK]),
+ cell_data: FxHashMap::default(),
+ cell_entity: FxHashMap::default(),
sleeping: true,
needs_texture_update: true,
}