mirror of
https://github.com/louis-e/arnis.git
synced 2026-04-22 15:10:10 -04:00
Address review: use shared constant and skip bitmap allocation when unused
- Make BUILDING_PASSAGE_HEIGHT pub(crate) and use it in buildings_interior.rs instead of hardcoded literal 4 (Copilot comment 4) - Add CoordinateBitmap::new_empty() zero-allocation constructor - Skip bitmap allocation in collect_building_passage_coords when no tunnel=building_passage ways exist (Copilot comment 5)
This commit is contained in:
@@ -55,7 +55,7 @@ pub(crate) struct HolePolygon {
|
||||
/// Height (in blocks above ground floor) of a building-passage archway.
|
||||
/// Walls and floors below this height are removed at tunnel=building_passage
|
||||
/// highway coordinates, creating a ground-level opening through the building.
|
||||
const BUILDING_PASSAGE_HEIGHT: i32 = 4;
|
||||
pub(crate) const BUILDING_PASSAGE_HEIGHT: i32 = 4;
|
||||
|
||||
/// Accent block options for building decoration
|
||||
const ACCENT_BLOCK_OPTIONS: [Block; 6] = [
|
||||
@@ -3607,8 +3607,7 @@ pub fn generate_buildings(
|
||||
// passage coordinate, place a wall column from ground to passage ceiling.
|
||||
// This creates the left/right corridor walls inside the archway.
|
||||
if !building_passages.is_empty() {
|
||||
let passage_height =
|
||||
BUILDING_PASSAGE_HEIGHT.min(config.building_height);
|
||||
let passage_height = BUILDING_PASSAGE_HEIGHT.min(config.building_height);
|
||||
let abs = config.abs_terrain_offset;
|
||||
for &(x, z) in &cached_floor_area {
|
||||
if building_passages.contains(x, z) {
|
||||
@@ -3620,17 +3619,9 @@ pub fn generate_buildings(
|
||||
|| building_passages.contains(x, z - 1)
|
||||
|| building_passages.contains(x, z + 1);
|
||||
if adjacent_to_passage {
|
||||
for y in (config.start_y_offset + 1)
|
||||
..=(config.start_y_offset + passage_height)
|
||||
for y in (config.start_y_offset + 1)..=(config.start_y_offset + passage_height)
|
||||
{
|
||||
editor.set_block_absolute(
|
||||
config.wall_block,
|
||||
x,
|
||||
y + abs,
|
||||
z,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
editor.set_block_absolute(config.wall_block, x, y + abs, z, None, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -988,6 +988,19 @@ pub fn collect_building_passage_coords(
|
||||
xzbbox: &XZBBox,
|
||||
scale: f64,
|
||||
) -> CoordinateBitmap {
|
||||
// Quick scan: skip bitmap allocation entirely when there are no passage ways.
|
||||
let has_any = elements.iter().any(|e| {
|
||||
if let ProcessedElement::Way(w) = e {
|
||||
w.tags.get("tunnel").map(|v| v.as_str()) == Some("building_passage")
|
||||
&& w.tags.contains_key("highway")
|
||||
} else {
|
||||
false
|
||||
}
|
||||
});
|
||||
if !has_any {
|
||||
return CoordinateBitmap::new_empty();
|
||||
}
|
||||
|
||||
let mut bitmap = CoordinateBitmap::new(xzbbox);
|
||||
|
||||
for element in elements {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::block_definitions::*;
|
||||
use crate::element_processing::buildings::BUILDING_PASSAGE_HEIGHT;
|
||||
use crate::floodfill_cache::CoordinateBitmap;
|
||||
use crate::world_editor::WorldEditor;
|
||||
use std::collections::HashSet;
|
||||
@@ -369,7 +370,7 @@ pub fn generate_building_interior(
|
||||
// Skip interior blocks in building-passage zones on floors
|
||||
// that fall within the archway opening.
|
||||
if building_passages.contains(x, z)
|
||||
&& floor_y < start_y_offset + 4.min(building_height)
|
||||
&& floor_y < start_y_offset + BUILDING_PASSAGE_HEIGHT.min(building_height)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -58,6 +58,18 @@ impl CoordinateBitmap {
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a zero-size bitmap that contains nothing and allocates no memory.
|
||||
pub fn new_empty() -> Self {
|
||||
Self {
|
||||
bits: Vec::new(),
|
||||
min_x: 0,
|
||||
min_z: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
count: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts (x, z) coordinate to bit index, returning None if out of bounds.
|
||||
#[inline]
|
||||
fn coord_to_index(&self, x: i32, z: i32) -> Option<usize> {
|
||||
|
||||
Reference in New Issue
Block a user