mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-04-20 11:35:07 +02:00
core/region_processor: only return available regions
Ignore regions that failed to process and have no old processed data.
This commit is contained in:
parent
fd48f94f16
commit
506631a18f
1 changed files with 17 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
//! The [RegionProcessor] and related functions
|
//! The [RegionProcessor] and related functions
|
||||||
|
|
||||||
use std::{ffi::OsStr, path::Path, time::SystemTime};
|
use std::{ffi::OsStr, path::Path, sync::mpsc, time::SystemTime};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
|
@ -32,7 +32,7 @@ fn parse_region_filename(file_name: &OsStr) -> Option<TileCoords> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [RegionProcessor::process_region] return values
|
/// [RegionProcessor::process_region] return values
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
enum RegionProcessorStatus {
|
enum RegionProcessorStatus {
|
||||||
/// Region was processed
|
/// Region was processed
|
||||||
Ok,
|
Ok,
|
||||||
|
@ -224,23 +224,28 @@ impl<'a> RegionProcessor<'a> {
|
||||||
///
|
///
|
||||||
/// Returns a list of the coordinates of all processed regions
|
/// Returns a list of the coordinates of all processed regions
|
||||||
pub fn run(self) -> Result<Vec<TileCoords>> {
|
pub fn run(self) -> Result<Vec<TileCoords>> {
|
||||||
let mut regions = self.collect_regions()?;
|
|
||||||
|
|
||||||
// Sort regions in a zig-zag pattern to optimize cache usage
|
|
||||||
regions.sort_unstable_by_key(|&TileCoords { x, z }| (x, if x % 2 == 0 { z } else { -z }));
|
|
||||||
|
|
||||||
fs::create_dir_all(&self.config.processed_dir)?;
|
fs::create_dir_all(&self.config.processed_dir)?;
|
||||||
fs::create_dir_all(&self.config.tile_dir(TileKind::Lightmap, 0))?;
|
fs::create_dir_all(&self.config.tile_dir(TileKind::Lightmap, 0))?;
|
||||||
|
|
||||||
info!("Processing region files...");
|
info!("Processing region files...");
|
||||||
|
|
||||||
regions.par_iter().try_for_each(|&coords| {
|
let (region_send, region_recv) = mpsc::channel();
|
||||||
let _ = self
|
|
||||||
|
self.collect_regions()?.par_iter().try_for_each(|&coords| {
|
||||||
|
let ret = self
|
||||||
.process_region(coords)
|
.process_region(coords)
|
||||||
.with_context(|| format!("Failed to process region {:?}", coords))?;
|
.with_context(|| format!("Failed to process region {:?}", coords))?;
|
||||||
|
|
||||||
|
if ret != RegionProcessorStatus::ErrorMissing {
|
||||||
|
region_send.send(coords).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
anyhow::Ok(())
|
anyhow::Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
drop(region_send);
|
||||||
|
let mut regions: Vec<_> = region_recv.into_iter().collect();
|
||||||
|
|
||||||
// info!(
|
// info!(
|
||||||
// "Processed region files ({} processed, {} unchanged, {} errors)",
|
// "Processed region files ({} processed, {} unchanged, {} errors)",
|
||||||
// processed,
|
// processed,
|
||||||
|
@ -248,6 +253,9 @@ impl<'a> RegionProcessor<'a> {
|
||||||
// errors,
|
// errors,
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
// Sort regions in a zig-zag pattern to optimize cache usage
|
||||||
|
regions.sort_unstable_by_key(|&TileCoords { x, z }| (x, if x % 2 == 0 { z } else { -z }));
|
||||||
|
|
||||||
Ok(regions)
|
Ok(regions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue