From 69f0407637a071d79d73115e4ae9c0ab526066a7 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Thu, 13 Aug 2026 21:31:53 -0700 Subject: parallelization --- src/main.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index b048122..313a7a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use egui::Id; use egui_wgpu::{RendererOptions, ScreenDescriptor}; use egui_winit::egui::{self, Context}; use pixels::{Pixels, ScalingMode, SurfaceTexture}; +use rand::random_range; use std::time::{Duration, Instant}; use winit::{ application::ApplicationHandler, @@ -30,10 +31,10 @@ pub type Error = Box; pub type Result = std::result::Result; struct Config { - show_ticks: bool, fps: u16, brush_radius: u8, brush_material: MaterialId, + use_threading: bool, } struct Input { @@ -118,7 +119,7 @@ impl Default for App { config: Config { fps: 120, - show_ticks: false, + use_threading: true, brush_radius: 10, brush_material: MaterialId::Sand, }, @@ -270,24 +271,26 @@ impl ApplicationHandler for App { // 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 { - // brush/selection + let r = random_range(0.0..1.0); if ((x - lm.0).pow(2) + (y - lm.1).pow(2)) < (self.config.brush_radius as i32).pow(2) + && r > 0.9 { + let mut cell = Cell::from_material(self.config.brush_material); + cell.flags = (self.sim_seqno as u8) & 0b1; world.set_cell_from_game_position( - x, - y, - Cell::from_material(self.config.brush_material), + x, y, cell, // wake the chunk + false, ); } } } } - // TODO check if we need to run another sim tick given the sim speed + // TODO check if we need to run another sim tick given the sim speed + delta_time // SIM logic if !self.sim_paused || self.ignore_pause_next_tick { - sim_tick(world, self.sim_seqno); + sim_tick(world, self.sim_seqno, self.config.use_threading); self.sim_seqno += 1; self.ignore_pause_next_tick = false; } -- cgit v1.3.1