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/manager.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/sim/cell_manager/manager.rs') diff --git a/src/sim/cell_manager/manager.rs b/src/sim/cell_manager/manager.rs index 6fa5f37..12cc1b7 100644 --- a/src/sim/cell_manager/manager.rs +++ b/src/sim/cell_manager/manager.rs @@ -5,6 +5,7 @@ use crate::{ sim::{ cell::Cell, cell_manager::{chunk::Chunk, sim::sim_tick}, + entity::EntityId, }, }; @@ -45,6 +46,40 @@ impl CellManager { } } + // VERY EXPENSIVE + pub fn get_data_from_game_position(&self, x: i32, y: i32) -> Option { + let ((cx, cy), (dx, dy)) = CellManager::split_game_position(x, y); + self.chunk_position_to_chunk_idx + .get(&(cx, cy)) + .map(|&idx| self.chunks[idx].get_data_at_local_position(dx, dy)) + .flatten() + } + + // VERY EXPENSIVE + pub fn set_data_from_game_position(&mut self, x: i32, y: i32, data: u16) { + let ((cx, cy), (dx, dy)) = CellManager::split_game_position(x, y); + if let Some(&idx) = self.chunk_position_to_chunk_idx.get(&(cx, cy)) { + self.chunks[idx].set_data_at_local_position(dx, dy, data); + } + } + + // VERY EXPENSIVE + pub fn get_entity_from_game_position(&self, x: i32, y: i32) -> Option { + let ((cx, cy), (dx, dy)) = CellManager::split_game_position(x, y); + self.chunk_position_to_chunk_idx + .get(&(cx, cy)) + .map(|&idx| self.chunks[idx].get_entity_at_local_position(dx, dy)) + .flatten() + } + + // VERY EXPENSIVE + pub fn set_entity_from_game_position(&mut self, x: i32, y: i32, entity_id: EntityId) { + let ((cx, cy), (dx, dy)) = CellManager::split_game_position(x, y); + if let Some(&idx) = self.chunk_position_to_chunk_idx.get(&(cx, cy)) { + self.chunks[idx].set_entity_at_local_position(dx, dy, entity_id); + } + } + pub fn insert(&mut self, x: i32, y: i32, chunk: Chunk) { self.chunk_position_to_chunk_idx .insert((x, y), self.chunks.len()); -- cgit v1.3.1