Skip to content

Commit

Permalink
cleanup layer/level terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
plule committed May 9, 2024
1 parent 14e09a0 commit b50101e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn build(
context: &DFContext,
vox: &mut DotVoxBuilder,
palette: &mut crate::palette::Palette,
layer_group_id: NodeId,
level_group_id: NodeId,
) {
// Collect all the tiles of the block
let tiles: Vec<_> = rfr::TileIterator::new(block, &context.tile_types).collect();
Expand All @@ -51,7 +51,7 @@ pub fn build(
// The full block is hidden, skip the construction and add the
// hidden model to save space
let block_group = vox.insert_group_node_simple(
layer_group_id,
level_group_id,
format!("block {} {}", block.map_x(), block.map_y(),),
Some(DotVoxModelCoords::new(x, y, 0)),
Layers::All.id(),
Expand Down Expand Up @@ -86,7 +86,7 @@ pub fn build(
}

let block_group = vox.insert_group_node_simple(
layer_group_id,
level_group_id,
format!("block {} {}", block.map_x(), block.map_y(),),
Some(DotVoxModelCoords::new(x, y, 0)),
Layers::All.id(),
Expand Down
12 changes: 9 additions & 3 deletions src/building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ pub impl BuildingInstance {
if let Some((name, model)) = self.do_build(map, context, palette) {
let coords = self
.bounding_box()
.layer_dot_vox_coords()
.into_layer_global_coords(context.max_vox_x(), context.max_vox_y());
.level_dot_vox_coords()
.into_level_global_coords(context.max_vox_x(), context.max_vox_y());

vox.insert_model_and_shape_node(group, Some(coords), model, Layers::Building.id(), name);
vox.insert_model_and_shape_node(
group,
Some(coords),
model,
Layers::Building.id(),
name,
);
}
}
fn do_build(
Expand Down
4 changes: 2 additions & 2 deletions src/coords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl VoxelCoords {
}
}

pub fn into_layer_global_coords(self, max_x: i32, max_y: i32) -> DotVoxModelCoords {
pub fn into_level_global_coords(self, max_x: i32, max_y: i32) -> DotVoxModelCoords {
DotVoxModelCoords {
x: self.x - max_x,
y: max_y - self.y,
Expand Down Expand Up @@ -268,7 +268,7 @@ impl DFBoundingBox {
)
}

pub fn layer_dot_vox_coords(&self) -> VoxelCoords {
pub fn level_dot_vox_coords(&self) -> VoxelCoords {
let size = dot_vox::Size::from(self.dimension());
VoxelCoords::from_df(
self.origin(),
Expand Down
33 changes: 11 additions & 22 deletions src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,21 @@ pub fn try_export_voxels(
}

let min_z = z_range.start * HEIGHT as i32;
let block_count = map.layers.values().map(|l| l.blocks.len()).sum();
let block_count = map.levels.values().map(|l| l.blocks.len()).sum();
progress_tx.send(Progress::start("Building blocks...", block_count))?;
let mut progress = 0;

for (layer, layer_data) in map.layers.iter().sorted_by_key(|(l, _)| *l) {
for (level, level_data) in map.levels.iter().sorted_by_key(|(l, _)| *l) {
// Create a group for the layer
let z = HEIGHT as i32 / 2 + layer * HEIGHT as i32 - min_z;
let layer_group_id = vox.insert_group_node_simple(
let z = HEIGHT as i32 / 2 + level * HEIGHT as i32 - min_z;
let level_group = vox.insert_group_node_simple(
vox.root_group,
format!("elevation {}", layer + z_offset),
format!("level {}", level + z_offset),
Some(DotVoxModelCoords::new(0, 0, z)),
Layers::All.id(),
);

for block in &layer_data.blocks {
for block in &level_data.blocks {
progress += 1;
progress_tx.send(Progress::update(
"Building blocks...",
Expand All @@ -260,24 +260,13 @@ pub fn try_export_voxels(
}

// Create the terrain model
crate::block::build(
block,
&map,
&context,
&mut vox,
&mut palette,
layer_group_id,
);
crate::block::build(block, &map, &context, &mut vox, &mut palette, level_group);
}

if !layer_data.buildings.is_empty() {
let building_group_id = vox.insert_group_node_simple(
layer_group_id,
"buildings",
None,
Layers::Building.id(),
);
for building in &layer_data.buildings {
if !level_data.buildings.is_empty() {
let building_group_id =
vox.insert_group_node_simple(level_group, "buildings", None, Layers::Building.id());
for building in &level_data.buildings {
building.build(&map, &context, &mut vox, &mut palette, building_group_id);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use itertools::Itertools;
use std::collections::HashMap;

#[derive(Default)]
pub struct LayerData<'a> {
pub struct LevelData<'a> {
pub blocks: Vec<&'a MapBlock>,
pub buildings: Vec<&'a BuildingInstance>,
}
Expand All @@ -20,7 +20,7 @@ pub struct LayerData<'a> {
#[derive(Default)]
pub struct Map<'a> {
/// The map stored by layers
pub layers: HashMap<i32, LayerData<'a>>,
pub levels: HashMap<i32, LevelData<'a>>,
/// Quick access to the occupancy data of each tile, for connectivity checks
pub occupancy: HashMap<DFMapCoords, Occupancy<'a>>,
/// True if the building where added already, they are streamed multiple times
Expand All @@ -38,8 +38,8 @@ impl<'a> Map<'a> {
if !self.buildings_added {
self.add_buildings(&block.buildings);
}
let layer = block.block_coords().z;
self.layers.entry(layer).or_default().blocks.push(block);
let level = block.block_coords().z;
self.levels.entry(level).or_default().blocks.push(block);

for tile in rfr::TileIterator::new(block, &context.tile_types) {
let coords = tile.global_coords();
Expand All @@ -60,7 +60,7 @@ impl<'a> Map<'a> {
continue;
}

self.layers
self.levels
.entry(building.bounding_box().origin().z)
.or_default()
.buildings
Expand Down
2 changes: 1 addition & 1 deletion src/ui/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl App {
ui.group(|ui| {
ui.add(df_client_group(&mut self.df, |ui, df| {
ui.label("Pick the elevation range to export");
ui.label("It works best by covering the surface layer.");
ui.label("It works best by covering the surface level.");
ui.horizontal(|ui| {
ui.add_space(ui.available_width());
});
Expand Down

0 comments on commit b50101e

Please sign in to comment.