fix world rendering at non-integer coordinates
This commit is contained in:
parent
050eee0e3c
commit
f0b3095eb9
2 changed files with 14 additions and 7 deletions
|
@ -45,7 +45,7 @@ pub struct CellData {
|
||||||
pub color: [u8; 3],
|
pub color: [u8; 3],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug)]
|
||||||
struct Chunk {
|
struct Chunk {
|
||||||
pub contents: Box<[[Cell; CHUNK_SIZE]; CHUNK_SIZE]>,
|
pub contents: Box<[[Cell; CHUNK_SIZE]; CHUNK_SIZE]>,
|
||||||
}
|
}
|
||||||
|
@ -338,8 +338,8 @@ impl Rule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Chunk {
|
impl Default for Chunk {
|
||||||
fn new() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
contents: vec![[Cell(0); CHUNK_SIZE]; CHUNK_SIZE]
|
contents: vec![[Cell(0); CHUNK_SIZE]; CHUNK_SIZE]
|
||||||
.into_boxed_slice()
|
.into_boxed_slice()
|
||||||
|
@ -347,7 +347,9 @@ impl Chunk {
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Chunk {
|
||||||
fn fill(&mut self, cell: Cell) {
|
fn fill(&mut self, cell: Cell) {
|
||||||
self.contents.fill([cell; CHUNK_SIZE]);
|
self.contents.fill([cell; CHUNK_SIZE]);
|
||||||
}
|
}
|
||||||
|
@ -416,7 +418,7 @@ impl Dish {
|
||||||
|
|
||||||
let mut new = Self {
|
let mut new = Self {
|
||||||
world: World {
|
world: World {
|
||||||
chunk: Chunk::new().with_random_ones(),
|
chunk: Chunk::default().with_random_ones(),
|
||||||
},
|
},
|
||||||
rules: default_rules,
|
rules: default_rules,
|
||||||
types: vec![
|
types: vec![
|
||||||
|
|
|
@ -92,8 +92,11 @@ impl eframe::App for UScope {
|
||||||
.min_width(100.)
|
.min_width(100.)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ui.heading("Simulation");
|
ui.heading("Simulation");
|
||||||
ui.label("speed");
|
ui.add(
|
||||||
ui.add(Slider::new(&mut self.speed, 0..=500).clamp_to_range(false));
|
Slider::new(&mut self.speed, 0..=500)
|
||||||
|
.clamp_to_range(false)
|
||||||
|
.text("speed"),
|
||||||
|
);
|
||||||
ui.label(format!("sim time: {sim_time:?}"));
|
ui.label(format!("sim time: {sim_time:?}"));
|
||||||
let avg_sim_time =
|
let avg_sim_time =
|
||||||
self.sim_times.iter().sum::<Duration>() / self.sim_times.len() as u32;
|
self.sim_times.iter().sum::<Duration>() / self.sim_times.len() as u32;
|
||||||
|
@ -207,7 +210,9 @@ impl eframe::App for UScope {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
CentralPanel::default().show(ctx, |ui| {
|
CentralPanel::default().show(ctx, |ui| {
|
||||||
let bounds = ui.available_rect_before_wrap();
|
let mut bounds = ui.available_rect_before_wrap();
|
||||||
|
bounds.min = bounds.min.floor();
|
||||||
|
bounds.max = bounds.max.floor();
|
||||||
let painter = ui.painter_at(bounds);
|
let painter = ui.painter_at(bounds);
|
||||||
paint_world(painter, &self.dish, self.show_grid);
|
paint_world(painter, &self.dish, self.show_grid);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue