Skip to content

Commit

Permalink
Make use of GridAab::from_ranges().
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Nov 26, 2023
1 parent cf3d6e2 commit 6c9c1c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 36 deletions.
40 changes: 17 additions & 23 deletions all-is-cubes-content/src/city.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,18 @@ pub(crate) async fn demo_city<I: Instant>(
.set_bias(0.0)
.set_scale(8.0);
let grass_threshold = 1.2;
space.fill(
GridAab::from_lower_upper(
[bounds.lower_bounds().x, 1, bounds.lower_bounds().z],
[bounds.upper_bounds().x, 2, bounds.upper_bounds().z],
),
|cube| {
if cube.x.abs() <= road_radius || cube.z.abs() <= road_radius {
return None;
}
if grass_noise.at_cube(cube) > grass_threshold * 2. {
Some(&landscape_blocks[GrassBlades { variant: true }])
} else if grass_noise.at_cube(cube) > grass_threshold {
Some(&landscape_blocks[GrassBlades { variant: false }])
} else {
None
}
},
)?;
space.fill(planner.y_range(1, 2), |cube| {
if cube.x.abs() <= road_radius || cube.z.abs() <= road_radius {
return None;
}
if grass_noise.at_cube(cube) > grass_threshold * 2. {
Some(&landscape_blocks[GrassBlades { variant: true }])
} else if grass_noise.at_cube(cube) > grass_threshold {
Some(&landscape_blocks[GrassBlades { variant: false }])
} else {
None
}
})?;
}
p.progress(0.3).await;

Expand Down Expand Up @@ -793,10 +787,10 @@ impl CityPlanner {
}

fn y_range(&self, lower_y: GridCoordinate, upper_y: GridCoordinate) -> GridAab {
let mut lower = self.space_bounds.lower_bounds();
let mut upper = self.space_bounds.upper_bounds();
lower.y = lower_y;
upper.y = upper_y;
GridAab::from_lower_upper(lower, upper)
GridAab::from_ranges([
self.space_bounds.x_range(),
lower_y..upper_y,
self.space_bounds.z_range(),
])
}
}
8 changes: 1 addition & 7 deletions all-is-cubes-content/src/dungeon/demo_dungeon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,13 +552,7 @@ pub(crate) async fn demo_dungeon(

// Fill in (under)ground areas
space.fill_uniform(
{
let mut l = space_bounds.lower_bounds();
let mut u = space_bounds.upper_bounds();
l.y = -1;
u.y = 0;
GridAab::from_lower_upper(l, u)
},
GridAab::from_ranges([space_bounds.x_range(), -1..0, space_bounds.z_range()]),
&landscape_blocks[LandscapeBlocks::Grass],
)?;
space.fill_uniform(
Expand Down
11 changes: 5 additions & 6 deletions all-is-cubes-mesh/src/block_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,11 @@ impl<M: MeshTypes + 'static> BlockMesh<M> {
// Compute the exact texture slice we will be accessing.
// TODO: It would be better if this were shrunk to the visible voxels
// in this specific layer, not just all voxels.
let rx = rotated_voxel_range.x_range();
let ry = rotated_voxel_range.y_range();
let slice_range = GridAab::from_lower_upper(
[rx.start, ry.start, layer],
[rx.end, ry.end, layer + 1],
)
let slice_range = GridAab::from_ranges([
rotated_voxel_range.x_range(),
rotated_voxel_range.y_range(),
layer..layer + 1,
])
.transform(face.face_transform(block_resolution))
.unwrap();

Expand Down

0 comments on commit 6c9c1c2

Please sign in to comment.