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],
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug)]
|
||||
struct Chunk {
|
||||
pub contents: Box<[[Cell; CHUNK_SIZE]; CHUNK_SIZE]>,
|
||||
}
|
||||
|
@ -338,8 +338,8 @@ impl Rule {
|
|||
}
|
||||
}
|
||||
|
||||
impl Chunk {
|
||||
fn new() -> Self {
|
||||
impl Default for Chunk {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
contents: vec![[Cell(0); CHUNK_SIZE]; CHUNK_SIZE]
|
||||
.into_boxed_slice()
|
||||
|
@ -347,7 +347,9 @@ impl Chunk {
|
|||
.unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Chunk {
|
||||
fn fill(&mut self, cell: Cell) {
|
||||
self.contents.fill([cell; CHUNK_SIZE]);
|
||||
}
|
||||
|
@ -416,7 +418,7 @@ impl Dish {
|
|||
|
||||
let mut new = Self {
|
||||
world: World {
|
||||
chunk: Chunk::new().with_random_ones(),
|
||||
chunk: Chunk::default().with_random_ones(),
|
||||
},
|
||||
rules: default_rules,
|
||||
types: vec![
|
||||
|
|
|
@ -92,8 +92,11 @@ impl eframe::App for UScope {
|
|||
.min_width(100.)
|
||||
.show(ctx, |ui| {
|
||||
ui.heading("Simulation");
|
||||
ui.label("speed");
|
||||
ui.add(Slider::new(&mut self.speed, 0..=500).clamp_to_range(false));
|
||||
ui.add(
|
||||
Slider::new(&mut self.speed, 0..=500)
|
||||
.clamp_to_range(false)
|
||||
.text("speed"),
|
||||
);
|
||||
ui.label(format!("sim time: {sim_time:?}"));
|
||||
let avg_sim_time =
|
||||
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| {
|
||||
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);
|
||||
paint_world(painter, &self.dish, self.show_grid);
|
||||
|
||||
|
|
Loading…
Reference in a new issue