Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Elevation #180

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/block_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl Block {
107 => "dark_oak_door",
108 => "potatoes",
109 => "wheat",
110 => "bedrock",
_ => panic!("Invalid id"),
}
}
Expand Down Expand Up @@ -291,6 +292,8 @@ pub const DARK_OAK_DOOR_UPPER: Block = Block::new(107);
pub const POTATOES: Block = Block::new(108);
pub const WHEAT: Block = Block::new(109);

pub const BEDROCK: Block = Block::new(110);

// Variations for building corners
pub fn building_corner_variations() -> Vec<Block> {
vec![
Expand Down
27 changes: 27 additions & 0 deletions src/cartesian.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#[derive(Copy, Clone)]
pub struct XZPoint {
pub x: i32,
pub z: i32,
}

impl XZPoint {
pub fn new(x: i32, z: i32) -> Self {
Self { x, z }
}
}

pub struct XYZPoint {
pub x: i32,
pub y: i32,
pub z: i32,
}

impl XYZPoint {
pub fn from_xz(xz: XZPoint, y: i32) -> Self {
Self {
x: xz.x,
y,
z: xz.z,
}
}
}
86 changes: 44 additions & 42 deletions src/data_processing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::args::Args;
use crate::block_definitions::{DIRT, GRASS_BLOCK};
use crate::block_definitions::{BEDROCK, DIRT, GRASS_BLOCK, STONE};
use crate::cartesian::XZPoint;
use crate::element_processing::*;
use crate::ground::Ground;
use crate::osm_parser::ProcessedElement;
use crate::world_editor::WorldEditor;
use colored::Colorize;
Expand All @@ -10,6 +12,9 @@ use std::fs;
use std::io::Write;
use std::path::Path;

const MIN_Y: i32 = -64;
const MAX_Y: i32 = 256;

pub fn generate_world(
elements: Vec<ProcessedElement>,
args: &Args,
Expand All @@ -20,7 +25,9 @@ pub fn generate_world(

let region_template_path: &str = "region.template";
let region_dir: String = format!("{}/region", args.path);
let ground_level: i32 = -62;

let ground = Ground::new();
let ground_level = 60; // TODO
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll see these in a few spots. They're only used by elements that I haven't updated to use the Ground struct yet.


// Check if the region.template file exists, and download if necessary
if !Path::new(region_template_path).exists() {
Expand Down Expand Up @@ -58,53 +65,33 @@ pub fn generate_world(
match element {
ProcessedElement::Way(way) => {
if way.tags.contains_key("building") || way.tags.contains_key("building:part") {
buildings::generate_buildings(
&mut editor,
way,
ground_level,
args.timeout.as_ref(),
);
buildings::generate_buildings(&mut editor, way, &ground, args.timeout.as_ref());
} else if way.tags.contains_key("highway") {
highways::generate_highways(
&mut editor,
element,
ground_level,
&ground,
args.timeout.as_ref(),
);
} else if way.tags.contains_key("landuse") {
landuse::generate_landuse(
&mut editor,
way,
ground_level,
args.timeout.as_ref(),
);
landuse::generate_landuse(&mut editor, way, &ground, args.timeout.as_ref());
} else if way.tags.contains_key("natural") {
natural::generate_natural(
&mut editor,
element,
ground_level,
args.timeout.as_ref(),
);
natural::generate_natural(&mut editor, element, &ground, args.timeout.as_ref());
} else if way.tags.contains_key("amenity") {
amenities::generate_amenities(
&mut editor,
element,
ground_level,
&ground,
args.timeout.as_ref(),
);
} else if way.tags.contains_key("leisure") {
leisure::generate_leisure(
&mut editor,
way,
ground_level,
args.timeout.as_ref(),
);
leisure::generate_leisure(&mut editor, way, &ground, args.timeout.as_ref());
} else if way.tags.contains_key("barrier") {
barriers::generate_barriers(&mut editor, element, ground_level);
barriers::generate_barriers(&mut editor, element, &ground);
} else if way.tags.contains_key("waterway") {
waterways::generate_waterways(&mut editor, way, ground_level);
} else if way.tags.contains_key("bridge") {
bridges::generate_bridges(&mut editor, way, ground_level);
bridges::generate_bridges(&mut editor, way, &ground);
} else if way.tags.contains_key("railway") {
railways::generate_railways(&mut editor, way, ground_level);
} else if way.tags.get("service") == Some(&"siding".to_string()) {
Expand All @@ -117,26 +104,21 @@ pub fn generate_world(
} else if node.tags.contains_key("natural")
&& node.tags.get("natural") == Some(&"tree".to_string())
{
natural::generate_natural(
&mut editor,
element,
ground_level,
args.timeout.as_ref(),
);
natural::generate_natural(&mut editor, element, &ground, args.timeout.as_ref());
} else if node.tags.contains_key("amenity") {
amenities::generate_amenities(
&mut editor,
element,
ground_level,
&ground,
args.timeout.as_ref(),
);
} else if node.tags.contains_key("barrier") {
barriers::generate_barriers(&mut editor, element, ground_level);
barriers::generate_barriers(&mut editor, element, &ground);
} else if node.tags.contains_key("highway") {
highways::generate_highways(
&mut editor,
element,
ground_level,
&ground,
args.timeout.as_ref(),
);
} else if node.tags.contains_key("tourism") {
Expand All @@ -145,7 +127,7 @@ pub fn generate_world(
}
ProcessedElement::Relation(rel) => {
if rel.tags.contains_key("water") {
water_areas::generate_water_areas(&mut editor, rel, ground_level);
water_areas::generate_water_areas(&mut editor, rel, &ground);
}
}
}
Expand All @@ -171,8 +153,28 @@ pub fn generate_world(

for x in 0..=(scale_factor_x as i32) {
for z in 0..=(scale_factor_z as i32) {
editor.set_block(GRASS_BLOCK, x, ground_level, z, None, None);
editor.set_block(DIRT, x, ground_level - 1, z, None, None);
// Use the smaller of [current block y, ground level y]
let max_y = (MIN_Y..MAX_Y)
.filter(|y| editor.block_at(x, *y, z))
.next()
.unwrap_or(MAX_Y)
.min(ground.level(XZPoint::new(x, z)));

// 1 layer of grass
editor.set_block(GRASS_BLOCK, x, max_y, z, None, None);

// 3 layers of dirt
for y in (max_y - 3)..max_y {
editor.set_block(DIRT, x, y, z, None, None);
}

// n - 1 layers of stone
for y in (MIN_Y + 1)..(max_y - 3) {
editor.set_block(STONE, x, y, z, None, None);
}

// 1 layer of bedrock
editor.set_block(BEDROCK, x, MIN_Y, z, None, None);

block_counter += 1;
if block_counter % batch_size == 0 {
Expand Down
Loading