Skip to content

Commit

Permalink
content: Split exhibits into separate files.
Browse files Browse the repository at this point in the history
I have just learned that using more separate files can improve rebuild
times, by reducing the amount of code whose spans (and hence panic
messages, debug info, etc.) change. In particular, this change cuts
1 second out of 10 seconds off the time to recompile a small change to
some exhibit code that also changes line breaks. Edit-to-rerun time
while tinkering with exhibits is important, so this feels  worthwhile.

Also, `exhibits.rs` was getting uncomfortably long anyway, and creating
more modules gives us an opportunity to explicitly group the code for
related exhibits, such as the three related to color processing and the
three related to transparency. (Of course, this grouping reduces the
benefit of the splitting somewhat.)
  • Loading branch information
kpreid committed Oct 2, 2024
1 parent a90d608 commit fc93bd4
Show file tree
Hide file tree
Showing 25 changed files with 1,711 additions and 1,659 deletions.
18 changes: 18 additions & 0 deletions all-is-cubes-content/src/alg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,24 @@ pub(crate) fn walk(start: Cube, end: Cube) -> impl Iterator<Item = CubeFace> + C
}
}

/// Place a series of blocks on top of each other, starting at the specified point.
///
/// TODO: think about whether this should be instead returning a `VoxelBrush` or a `SpaceTransaction` or something, for the future of composable worldgen
pub(crate) fn stack<'b, B>(
space: &mut Space,
origin: impl Into<Cube>,
blocks: impl IntoIterator<Item = B>,
) -> Result<(), SetCubeError>
where
B: Into<alloc::borrow::Cow<'b, Block>>,
{
let origin = origin.into();
for (y, block) in (0..).zip(blocks) {
space.set(origin + GridVector::new(0, y, 0), block)?;
}
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-content/src/city/exhibit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ macro_rules! exhibit {
$( $body:tt )*
}
) => {
const $name: Exhibit = Exhibit {
pub(in crate::city) const $name: Exhibit = Exhibit {
factory: |$( $args )*| { $( $body )* },
$( $fields )*
};
Expand Down
Loading

0 comments on commit fc93bd4

Please sign in to comment.