summaryrefslogtreecommitdiff
path: root/src/sim/cell_manager/manager.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim/cell_manager/manager.rs')
-rw-r--r--src/sim/cell_manager/manager.rs35
1 files changed, 35 insertions, 0 deletions
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<u16> {
+ 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<EntityId> {
+ 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());