minedmap/tile_renderer: keep HashSet of populated regions

Rather than attemping to read the file metadata, it's more elegant to
check whether a tile is supposed to be available first.
This commit is contained in:
Matthias Schiffer 2023-08-15 20:48:41 +02:00
parent 722fe00d77
commit 427a992897
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
3 changed files with 18 additions and 14 deletions

View file

@ -51,6 +51,7 @@ pub struct TileRenderer<'a> {
config: &'a Config,
rt: &'a tokio::runtime::Runtime,
regions: &'a [TileCoords],
region_set: rustc_hash::FxHashSet<TileCoords>,
region_cache: Mutex<LruCache<PathBuf, Arc<OnceCell<RegionRef>>>>,
}
@ -63,10 +64,12 @@ impl<'a> TileRenderer<'a> {
let region_cache = Mutex::new(LruCache::new(
NonZeroUsize::new(6 + 6 * config.num_threads).unwrap(),
));
let region_set = regions.iter().copied().collect();
TileRenderer {
config,
rt,
regions,
region_set,
region_cache,
}
}
@ -204,11 +207,13 @@ impl<'a> TileRenderer<'a> {
fn processed_sources(&self, coords: TileCoords) -> Result<(RegionGroup<PathBuf>, SystemTime)> {
let sources = RegionGroup::new(|x, z| {
self.processed_source(TileCoords {
Some(TileCoords {
x: coords.x + (x as i32),
z: coords.z + (z as i32),
})
.filter(|entry| self.region_set.contains(entry))
})
.try_map(|entry| self.processed_source(entry))
.with_context(|| format!("Region {:?} from previous step must exist", coords))?;
let max_timestamp = *sources