mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 01:24:53 +01:00
main: introduce ProcessedRegion type alias
This commit is contained in:
parent
e0467de080
commit
89f35024b7
1 changed files with 6 additions and 10 deletions
16
src/main.rs
16
src/main.rs
|
@ -17,6 +17,7 @@ struct Args {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RegionCoords = (i32, i32);
|
type RegionCoords = (i32, i32);
|
||||||
|
type ProcessedRegion = ChunkArray<Option<Box<world::layer::BlockInfoArray>>>;
|
||||||
|
|
||||||
struct Config {
|
struct Config {
|
||||||
region_dir: PathBuf,
|
region_dir: PathBuf,
|
||||||
|
@ -89,13 +90,9 @@ impl<'a> RegionProcessor<'a> {
|
||||||
world::layer::top_layer(&chunk)
|
world::layer::top_layer(&chunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_region(
|
fn save_region(&self, coords: RegionCoords, processed_region: &ProcessedRegion) -> Result<()> {
|
||||||
&self,
|
|
||||||
coords: RegionCoords,
|
|
||||||
processed_data: &ChunkArray<Option<Box<world::layer::BlockInfoArray>>>,
|
|
||||||
) -> Result<()> {
|
|
||||||
let tmp_path = self.config.processed_path(coords, true);
|
let tmp_path = self.config.processed_path(coords, true);
|
||||||
storage::write(&tmp_path, processed_data)?;
|
storage::write(&tmp_path, processed_region)?;
|
||||||
|
|
||||||
let output_path = self.config.processed_path(coords, false);
|
let output_path = self.config.processed_path(coords, false);
|
||||||
fs::rename(&tmp_path, &output_path).with_context(|| {
|
fs::rename(&tmp_path, &output_path).with_context(|| {
|
||||||
|
@ -113,20 +110,19 @@ impl<'a> RegionProcessor<'a> {
|
||||||
fn process_region(&self, path: &Path, coords: RegionCoords) -> Result<()> {
|
fn process_region(&self, path: &Path, coords: RegionCoords) -> Result<()> {
|
||||||
println!("Processing region r.{}.{}.mca", coords.0, coords.1);
|
println!("Processing region r.{}.{}.mca", coords.0, coords.1);
|
||||||
|
|
||||||
let mut processed_data: ChunkArray<Option<Box<world::layer::BlockInfoArray>>> =
|
let mut processed_region = ProcessedRegion::default();
|
||||||
Default::default();
|
|
||||||
|
|
||||||
minedmap::io::region::from_file(path)?.foreach_chunk(
|
minedmap::io::region::from_file(path)?.foreach_chunk(
|
||||||
|chunk_coords, data: world::de::Chunk| {
|
|chunk_coords, data: world::de::Chunk| {
|
||||||
let processed_chunk = self
|
let processed_chunk = self
|
||||||
.process_chunk(data)
|
.process_chunk(data)
|
||||||
.with_context(|| format!("Failed to process chunk {:?}", chunk_coords))?;
|
.with_context(|| format!("Failed to process chunk {:?}", chunk_coords))?;
|
||||||
processed_data[chunk_coords] = Some(processed_chunk);
|
processed_region[chunk_coords] = Some(processed_chunk);
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.save_region(coords, &processed_data)?;
|
self.save_region(coords, &processed_region)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue