Skip to content

Commit

Permalink
Merge pull request #253 from zer0-dev/main
Browse files Browse the repository at this point in the history
Fix tall grass generating on non-grass blocks. Colored roofs only for single houses
  • Loading branch information
louis-e authored Jan 12, 2025
2 parents a92c5bb + ea3cf80 commit 0efa681
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/data_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn generate_world(
let progress_increment_prcs: f64 = 50.0 / elements_count as f64;
let mut current_progress_prcs: f64 = 10.0;
let mut last_emitted_progress: f64 = current_progress_prcs;

for element in &elements {
process_pb.inc(1);
current_progress_prcs += progress_increment_prcs;
Expand Down
18 changes: 17 additions & 1 deletion src/element_processing/buildings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,23 @@ pub fn generate_buildings(
})
})
.flatten()
.unwrap_or_else(|| building_floor_variations()[variation_index_floor]);
.unwrap_or_else(|| {
if let Some(building_type) = element
.tags
.get("building")
.or_else(|| element.tags.get("building:part"))
{
//Random roof color only for single houses
match building_type.as_str() {
"yes" | "house" | "detached" | "static_caravan" | "semidetached_house"
| "bungalow" | "manor" | "villa" => {
return building_floor_variations()[variation_index_floor];
}
_ => return LIGHT_GRAY_CONCRETE,
}
}
LIGHT_GRAY_CONCRETE
});
let window_block: Block = WHITE_STAINED_GLASS;

// Set to store processed flood fill points
Expand Down
16 changes: 14 additions & 2 deletions src/element_processing/landuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,25 @@ pub fn generate_landuse(
}
"grass" => {
if rng.gen_range(1..=7) != 1
&& !editor.check_for_block(x, ground_level, z, None, Some(&[WATER]))
&& editor.check_for_block(
x,
ground_level,
z,
Some(&[GRASS_BLOCK, SNOW_BLOCK]),
None,
)
{
editor.set_block(GRASS, x, ground_level + 1, z, None, None);
}
}
"meadow" => {
if !editor.check_for_block(x, ground_level, z, None, Some(&[WATER])) {
if editor.check_for_block(
x,
ground_level,
z,
Some(&[GRASS_BLOCK, SNOW_BLOCK]),
None,
) {
let random_choice: i32 = rng.gen_range(0..1001);
if random_choice < 5 {
create_tree(
Expand Down
13 changes: 11 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,17 @@ fn gui_start_generation(
Ok(raw_data) => {
let (mut parsed_elements, scale_factor_x, scale_factor_z) =
osm_parser::parse_osm_data(&raw_data, reordered_bbox, &args);
parsed_elements.sort_by_key(|element: &osm_parser::ProcessedElement| {
osm_parser::get_priority(element)
parsed_elements.sort_by(|el1, el2| {
let (el1_priority, el2_priority) =
(osm_parser::get_priority(el1), osm_parser::get_priority(el2));
match (
el1.tags().contains_key("landuse"),
el2.tags().contains_key("landuse"),
) {
(true, false) => std::cmp::Ordering::Greater,
(false, true) => std::cmp::Ordering::Less,
_ => el1_priority.cmp(&el2_priority),
}
});

let _ = data_processing::generate_world(
Expand Down

0 comments on commit 0efa681

Please sign in to comment.