From e6742f59102f2beb305b813d7f0ee1d544bbc3e0 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sun, 23 Aug 2026 12:14:19 -0700 Subject: separate data from cells --- src/sim/cell_manager/chunk.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/sim/cell_manager/chunk.rs') 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, + pub cell_entity: FxHashMap, 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 { + 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 { + 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, } -- cgit v1.3.1