Removed unions in gnarling site to make chunkgen more performant

This commit is contained in:
Sam
2022-02-14 12:40:06 -05:00
parent 6e46b4ddef
commit 2bcf9b9a26
3 changed files with 71 additions and 50 deletions

View File

@ -1010,6 +1010,8 @@ impl<'a> From<PrimitiveRef<'a>> for Id<Primitive> {
fn from(r: PrimitiveRef<'a>) -> Self { r.id } fn from(r: PrimitiveRef<'a>) -> Self { r.id }
} }
// TODO: Enable this
#[allow(clippy::return_self_not_must_use)]
impl<'a> PrimitiveRef<'a> { impl<'a> PrimitiveRef<'a> {
/// Joins two primitives together by returning the total of the blocks of /// Joins two primitives together by returning the total of the blocks of
/// both primitives. In boolean logic this is an `OR` operation. /// both primitives. In boolean logic this is an `OR` operation.

View File

@ -5,7 +5,7 @@ pub mod util;
use self::tile::{HazardKind, KeepKind, RoofKind, Tile, TileGrid, TileKind, TILE_SIZE}; use self::tile::{HazardKind, KeepKind, RoofKind, Tile, TileGrid, TileKind, TILE_SIZE};
pub use self::{ pub use self::{
gen::{aabr_with_z, Fill, Painter, Primitive, Structure}, gen::{aabr_with_z, Fill, Painter, Primitive, PrimitiveRef, Structure},
plot::{Plot, PlotKind}, plot::{Plot, PlotKind},
util::Dir, util::Dir,
}; };

View File

@ -1707,15 +1707,12 @@ impl Structure for GnarlingFortification {
let random_field = RandomField::new(self.seed); let random_field = RandomField::new(self.seed);
let mut tunnels = painter.empty(); let mut tunnels = Vec::new();
let mut path_tunnels = painter.empty(); let mut path_tunnels = Vec::new();
let mut tunnels_clear = painter.empty(); let mut tunnels_clear = Vec::new();
let mut ferns = painter.empty(); let mut ferns = Vec::new();
let mut velorite_ores = painter.empty(); let mut velorite_ores = Vec::new();
let mut fire_bowls = painter.empty(); let mut fire_bowls = Vec::new();
let mut fern_scatter = painter.empty();
let mut velorite_scatter = painter.empty();
let mut fire_bowl_scatter = painter.empty();
for branch in self.tunnels.branches.iter() { for branch in self.tunnels.branches.iter() {
let tunnel_radius_i32 = 4 + branch.0.x % 4; let tunnel_radius_i32 = 4 + branch.0.x % 4;
let in_path = let in_path =
@ -1729,6 +1726,9 @@ impl Structure for GnarlingFortification {
let ctrl1 = (((start + end) / 2) + end) / 2 + ctrl1_offset; let ctrl1 = (((start + end) / 2) + end) / 2 + ctrl1_offset;
let tunnel = painter.cubic_bezier(start, ctrl0, ctrl1, end, tunnel_radius); let tunnel = painter.cubic_bezier(start, ctrl0, ctrl1, end, tunnel_radius);
let tunnel_clear = painter.cubic_bezier(start, ctrl0, ctrl1, end, tunnel_radius - 1.0); let tunnel_clear = painter.cubic_bezier(start, ctrl0, ctrl1, end, tunnel_radius - 1.0);
let mut fern_scatter = painter.empty();
let mut velorite_scatter = painter.empty();
let mut fire_bowl_scatter = painter.empty();
let min_z = branch.0.z.min(branch.1.z); let min_z = branch.0.z.min(branch.1.z);
let max_z = branch.0.z.max(branch.1.z); let max_z = branch.0.z.max(branch.1.z);
@ -1758,21 +1758,21 @@ impl Structure for GnarlingFortification {
let velorite = tunnel_clear.intersect(velorite_scatter); let velorite = tunnel_clear.intersect(velorite_scatter);
let fire_bowl = tunnel_clear.intersect(fire_bowl_scatter); let fire_bowl = tunnel_clear.intersect(fire_bowl_scatter);
if in_path { if in_path {
path_tunnels = path_tunnels.union(tunnel); path_tunnels.push(tunnel);
} else { } else {
tunnels = tunnels.union(tunnel); tunnels.push(tunnel);
} }
tunnels_clear = tunnels_clear.union(tunnel_clear); tunnels_clear.push(tunnel_clear);
ferns = ferns.union(fern); ferns.push(fern);
velorite_ores = velorite_ores.union(velorite); velorite_ores.push(velorite);
fire_bowls = fire_bowls.union(fire_bowl); fire_bowls.push(fire_bowl);
} }
let mut rooms = painter.empty(); let mut rooms = Vec::new();
let mut rooms_clear = painter.empty(); let mut rooms_clear = Vec::new();
let mut chests_ori_0 = painter.empty(); let mut chests_ori_0 = Vec::new();
let mut chests_ori_2 = painter.empty(); let mut chests_ori_2 = Vec::new();
let mut chests_ori_4 = painter.empty(); let mut chests_ori_4 = Vec::new();
for terminal in self.tunnels.terminals.iter() { for terminal in self.tunnels.terminals.iter() {
let room = painter.sphere(Aabb { let room = painter.sphere(Aabb {
min: terminal - 8, min: terminal - 8,
@ -1782,15 +1782,15 @@ impl Structure for GnarlingFortification {
min: terminal - 7, min: terminal - 7,
max: terminal + 7 + 1, max: terminal + 7 + 1,
}); });
rooms = rooms.union(room); rooms.push(room);
rooms_clear = rooms_clear.union(room_clear); rooms_clear.push(room_clear);
// FIRE!!!!! // FIRE!!!!!
let fire_bowl = painter.aabb(Aabb { let fire_bowl = painter.aabb(Aabb {
min: terminal.with_z(terminal.z - 7), min: terminal.with_z(terminal.z - 7),
max: terminal.with_z(terminal.z - 7) + 1, max: terminal.with_z(terminal.z - 7) + 1,
}); });
fire_bowls = fire_bowls.union(fire_bowl); fire_bowls.push(fire_bowl);
// Chest // Chest
let chest_seed = random_field.get(*terminal) % 5; let chest_seed = random_field.get(*terminal) % 5;
@ -1800,55 +1800,74 @@ impl Structure for GnarlingFortification {
min: chest_pos, min: chest_pos,
max: chest_pos + 1, max: chest_pos + 1,
}); });
chests_ori_4 = chests_ori_4.union(chest); chests_ori_4.push(chest);
if chest_seed < 2 { if chest_seed < 2 {
let chest_pos = Vec3::new(terminal.x, terminal.y + 4, terminal.z - 6); let chest_pos = Vec3::new(terminal.x, terminal.y + 4, terminal.z - 6);
let chest = painter.aabb(Aabb { let chest = painter.aabb(Aabb {
min: chest_pos, min: chest_pos,
max: chest_pos + 1, max: chest_pos + 1,
}); });
chests_ori_0 = chests_ori_0.union(chest); chests_ori_0.push(chest);
if chest_seed < 1 { if chest_seed < 1 {
let chest_pos = Vec3::new(terminal.x - 4, terminal.y, terminal.z - 6); let chest_pos = Vec3::new(terminal.x - 4, terminal.y, terminal.z - 6);
let chest = painter.aabb(Aabb { let chest = painter.aabb(Aabb {
min: chest_pos, min: chest_pos,
max: chest_pos + 1, max: chest_pos + 1,
}); });
chests_ori_2 = chests_ori_2.union(chest); chests_ori_2.push(chest);
} }
} }
} }
} }
tunnels.fill(wood.clone()); tunnels
path_tunnels.fill(dirt); .into_iter()
rooms.fill(wood.clone()); .chain(rooms.into_iter())
boss_room.fill(wood.clone()); .chain(core::iter::once(boss_room))
stump.fill(wood); .chain(core::iter::once(stump))
.for_each(|prim| prim.fill(wood.clone()));
path_tunnels.into_iter().for_each(|t| t.fill(dirt.clone()));
// Clear out insides after filling the walls in // Clear out insides after filling the walls in
let cavern_clear = tunnels_clear.union(rooms_clear).union(boss_room_clear); let mut sprite_clear = Vec::new();
let sprite_clear = cavern_clear tunnels_clear
.translate(Vec3::new(0, 0, 1)) .into_iter()
.intersect(cavern_clear); .chain(rooms_clear.into_iter())
cavern_clear.clear(); .chain(core::iter::once(boss_room_clear))
.for_each(|prim| {
sprite_clear.push(prim.translate(Vec3::new(0, 0, 1)).intersect(prim));
prim.clear();
});
// Place sprites // Place sprites
ferns.fill(Fill::Block(Block::air(SpriteKind::JungleFern))); ferns
velorite_ores.fill(Fill::Block(Block::air(SpriteKind::Velorite))); .into_iter()
fire_bowls.fill(Fill::Block(Block::air(SpriteKind::FireBowlGround))); .for_each(|prim| prim.fill(Fill::Block(Block::air(SpriteKind::JungleFern))));
velorite_ores
.into_iter()
.for_each(|prim| prim.fill(Fill::Block(Block::air(SpriteKind::Velorite))));
fire_bowls
.into_iter()
.for_each(|prim| prim.fill(Fill::Block(Block::air(SpriteKind::FireBowlGround))));
chests_ori_0.fill(Fill::Block( chests_ori_0.into_iter().for_each(|prim| {
prim.fill(Fill::Block(
Block::air(SpriteKind::DungeonChest0).with_ori(0).unwrap(), Block::air(SpriteKind::DungeonChest0).with_ori(0).unwrap(),
)); ))
chests_ori_2.fill(Fill::Block( });
chests_ori_2.into_iter().for_each(|prim| {
prim.fill(Fill::Block(
Block::air(SpriteKind::DungeonChest0).with_ori(2).unwrap(), Block::air(SpriteKind::DungeonChest0).with_ori(2).unwrap(),
)); ))
chests_ori_4.fill(Fill::Block( });
chests_ori_4.into_iter().for_each(|prim| {
prim.fill(Fill::Block(
Block::air(SpriteKind::DungeonChest0).with_ori(4).unwrap(), Block::air(SpriteKind::DungeonChest0).with_ori(4).unwrap(),
)); ))
});
entrance_hollow.clear(); entrance_hollow.clear();
sprite_clear.clear(); sprite_clear.into_iter().for_each(|prim| prim.clear());
} }
} }