From 820e4d00837376bc63b614a382809469a719ed0b Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sun, 23 Aug 2026 22:48:38 -0700 Subject: entity partitioning --- src/sim/sim_manager/mod.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/sim/sim_manager/mod.rs') diff --git a/src/sim/sim_manager/mod.rs b/src/sim/sim_manager/mod.rs index 8fab9cf..b2441ef 100644 --- a/src/sim/sim_manager/mod.rs +++ b/src/sim/sim_manager/mod.rs @@ -1,12 +1,14 @@ use std::time::Instant; use fxhash::FxHashMap; +use rand::random_range; use crate::{ Config, InputManager, config::{PHYSICS_DELTA_TIME, PHYSICS_FPS, SIM_FPS}, input::Input, sim::{ + cell::Cell, cell_manager::manager::CellManager, entity::{Entity, EntityDef, EntityId}, particle_manager::ParticleManager, @@ -99,6 +101,41 @@ impl SimManager { // before we tick, write all the entities into the sim world let cells_written_by_entity = write_entities_to_world(self); + // --TEST DRAWING-- + if input_manager.lmb_held || input_manager.rmb_held { + // start with the bounding box of the drawing brush circle + some margin + // clamp the bounding box to the board sie + let bb_xl = (input_manager.world_mouse_pos.x - config.brush_radius).round() as i32; + let bb_xu = (input_manager.world_mouse_pos.x + config.brush_radius).round() as i32; + let bb_yl = (input_manager.world_mouse_pos.y - config.brush_radius).round() as i32; + let bb_yu = (input_manager.world_mouse_pos.y + config.brush_radius).round() as i32; + + // for each point, check if the distance is less than the brush size and write the pixel + for x in bb_xl..bb_xu { + for y in bb_yl..bb_yu { + let r = random_range(0.0..1.0); + if ((x - input_manager.world_mouse_pos.x.round() as i32).pow(2) + + (y - input_manager.world_mouse_pos.y.round() as i32).pow(2)) + < (config.brush_radius as i32).pow(2) + && r > 0.9 + { + let cell = if input_manager.lmb_held { + let mut cell = Cell::from_material(config.brush_material); + // ensure we simulate on the first tick + cell.match_parity(self.cell_manager.seqno); + cell + } else { + Cell::void() + }; + + self.cell_manager.set_cell_from_game_position( + x, y, cell, false, // wake the chunk + ) + } + } + } + } + // tick self.cell_manager.tick(config.use_threading); -- cgit v1.3.1