Fixed more silly issues

This commit is contained in:
Joshua Barretto 2021-03-03 13:31:25 +00:00
parent 6e6e322e90
commit fe8ffc8f87
4 changed files with 39 additions and 28 deletions

View File

@ -52,18 +52,27 @@ impl Fill {
Some(self.block).filter(|_| self.contains_at(tree, self.prim, pos))
}
fn get_bounds_inner(&self, tree: &Store<Primitive>, prim: Id<Primitive>) -> Aabb<i32> {
match &tree[prim] {
Primitive::Empty => Aabb::new_empty(Vec3::zero()),
fn get_bounds_inner(&self, tree: &Store<Primitive>, prim: Id<Primitive>) -> Option<Aabb<i32>> {
fn or_zip_with<T, F: FnOnce(T, T) -> T>(a: Option<T>, b: Option<T>, f: F) -> Option<T> {
match (a, b) {
(Some(a), Some(b)) => Some(f(a, b)),
(Some(a), _) => Some(a),
(_, b) => b,
}
}
Some(match &tree[prim] {
Primitive::Empty => return None,
Primitive::Aabb(aabb) => *aabb,
Primitive::Pyramid { aabb, .. } => *aabb,
Primitive::And(a, b) => self.get_bounds_inner(tree, *a).intersection(self.get_bounds_inner(tree, *b)),
Primitive::Or(a, b) | Primitive::Xor(a, b) => self.get_bounds_inner(tree, *a).union(self.get_bounds_inner(tree, *b)),
}
Primitive::And(a, b) => or_zip_with(self.get_bounds_inner(tree, *a), self.get_bounds_inner(tree, *b), |a, b| a.intersection(b))?,
Primitive::Or(a, b) | Primitive::Xor(a, b) =>
or_zip_with(self.get_bounds_inner(tree, *a), self.get_bounds_inner(tree, *b), |a, b| a.union(b))?,
})
}
pub fn get_bounds(&self, tree: &Store<Primitive>) -> Aabb<i32> {
self.get_bounds_inner(tree, self.prim)
self.get_bounds_inner(tree, self.prim).unwrap_or_else(|| Aabb::new_empty(Vec3::zero()))
}
}

View File

@ -250,7 +250,7 @@ impl Site {
});
site.blit_aabr(aabr, Tile {
kind: TileKind::Building { levels: size - 1 + rng.gen_range(0..2) },
kind: TileKind::Building,
plot: Some(plot),
});
}
@ -481,9 +481,9 @@ impl Site {
// b.with_sprite(SpriteKind::Empty)
// },
// )),
// TileKind::Building { levels } => {
// TileKind::Building => {
// let base_alt = tile.plot.map(|p| self.plot(p)).map_or(col.alt as i32, |p| p.base_alt);
// for z in base_alt - 12..base_alt + 4 + 6 * levels as i32 {
// for z in base_alt - 12..base_alt + 16 {
// canvas.set(
// Vec3::new(wpos2d.x, wpos2d.y, z),
// Block::new(BlockKind::Wood, Rgb::new(180, 90 + (seed % 64) as u8, 120))

View File

@ -54,23 +54,25 @@ impl Structure for House {
});
// wall pillars
let mut pillars = prim(Primitive::Empty);
for x in self.tile_aabr.min.x + 1..self.tile_aabr.max.x {
let mut pillars_y = prim(Primitive::Empty);
for x in self.tile_aabr.min.x..self.tile_aabr.max.x + 2 {
let pillar = prim(Primitive::Aabb(Aabb {
min: Vec3::from(site.tile_wpos(Vec2::new(x, self.tile_aabr.min.y))) + Vec3::unit_z() * self.alt,
max: Vec3::from(site.tile_wpos(Vec2::new(x, self.tile_aabr.max.y)) + Vec2::unit_x()) + Vec3::unit_z() * (self.alt + roof),
}));
pillars = prim(Primitive::Or(pillars, pillar));
pillars_y = prim(Primitive::Or(pillars_y, pillar));
}
for y in self.tile_aabr.min.y + 1..self.tile_aabr.max.y {
let mut pillars_x = prim(Primitive::Empty);
for y in self.tile_aabr.min.y..self.tile_aabr.max.y + 2 {
let pillar = prim(Primitive::Aabb(Aabb {
min: Vec3::from(site.tile_wpos(Vec2::new(self.tile_aabr.min.x, y))) + Vec3::unit_z() * self.alt,
max: Vec3::from(site.tile_wpos(Vec2::new(self.tile_aabr.max.x, y)) + Vec2::unit_y()) + Vec3::unit_z() * (self.alt + roof),
}));
pillars = prim(Primitive::Or(pillars, pillar));
pillars_x = prim(Primitive::Or(pillars_x, pillar));
}
let pillars = prim(Primitive::And(pillars_x, pillars_y));
fill(Fill {
prim: prim(Primitive::And(walls, pillars)),
prim: pillars,
block: Block::new(BlockKind::Wood, Rgb::new(89, 44, 14)),
});
@ -124,16 +126,16 @@ impl Structure for House {
}
// Corner pillars
for &rpos in SQUARE_4.iter() {
let pos = self.bounds.min + (self.bounds.max - self.bounds.min) * rpos;
fill(Fill {
prim: prim(Primitive::Aabb(Aabb {
min: Vec3::new(pos.x - 1, pos.y - 1, self.alt - foundations),
max: Vec3::new(pos.x + 1, pos.y + 1, self.alt + roof),
})),
block: Block::new(BlockKind::Wood, Rgb::new(89, 44, 14)),
});
}
// for &rpos in SQUARE_4.iter() {
// let pos = self.bounds.min + (self.bounds.max - self.bounds.min) * rpos;
// fill(Fill {
// prim: prim(Primitive::Aabb(Aabb {
// min: Vec3::new(pos.x - 1, pos.y - 1, self.alt - foundations),
// max: Vec3::new(pos.x + 1, pos.y + 1, self.alt + roof),
// })),
// block: Block::new(BlockKind::Wood, Rgb::new(89, 44, 14)),
// });
// }
let roof_lip = 3;

View File

@ -117,7 +117,7 @@ pub enum TileKind {
Hazard(HazardKind),
Field,
Road,
Building { levels: u32 },
Building,
Castle,
Wall,
}
@ -150,7 +150,7 @@ impl Tile {
matches!(
self.kind,
TileKind::Hazard(_)
| TileKind::Building { .. }
| TileKind::Building
| TileKind::Castle
| TileKind::Wall
)