summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-13 21:31:53 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-13 21:31:53 -0700
commit69f0407637a071d79d73115e4ae9c0ab526066a7 (patch)
treec22f8fa6e761985a70d86ad023b54fc374f6f6a3 /src/main.rs
parentfeefeecec6c6050635b2c016452dfa1529575987 (diff)
parallelization
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
1 files changed, 11 insertions, 8 deletions
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<dyn std::error::Error>;
pub type Result<T> = std::result::Result<T, Error>;
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;
}