mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
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:
parent
722fe00d77
commit
427a992897
3 changed files with 18 additions and 14 deletions
|
@ -12,7 +12,7 @@ use minedmap::{io::fs::FileMetaVersion, resource::Biome, types::*, world::layer}
|
||||||
// Increase to force regeneration of all output files
|
// Increase to force regeneration of all output files
|
||||||
pub const FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0);
|
pub const FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0);
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct TileCoords {
|
pub struct TileCoords {
|
||||||
pub x: i32,
|
pub x: i32,
|
||||||
pub z: i32,
|
pub z: i32,
|
||||||
|
|
|
@ -16,25 +16,24 @@ pub struct RegionGroup<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> RegionGroup<T> {
|
impl<T> RegionGroup<T> {
|
||||||
pub fn new<F>(f: F) -> Result<Self>
|
pub fn new<F>(f: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn(i8, i8) -> Result<T>,
|
F: Fn(i8, i8) -> Option<T>,
|
||||||
{
|
{
|
||||||
RegionGroup {
|
RegionGroup {
|
||||||
center: (0, 0),
|
center: f(0, 0).expect("Center element of RegionGroup must not be None"),
|
||||||
neighs: [
|
neighs: [
|
||||||
Some((-1, -1)),
|
f(-1, -1),
|
||||||
Some((-1, 0)),
|
f(-1, 0),
|
||||||
Some((-1, 1)),
|
f(-1, 1),
|
||||||
Some((0, -1)),
|
f(0, -1),
|
||||||
None,
|
None,
|
||||||
Some((0, 1)),
|
f(0, 1),
|
||||||
Some((1, -1)),
|
f(1, -1),
|
||||||
Some((1, 0)),
|
f(1, 0),
|
||||||
Some((1, 1)),
|
f(1, 1),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
.try_map(|(x, z)| f(x, z))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn center(&self) -> &T {
|
pub fn center(&self) -> &T {
|
||||||
|
|
|
@ -51,6 +51,7 @@ pub struct TileRenderer<'a> {
|
||||||
config: &'a Config,
|
config: &'a Config,
|
||||||
rt: &'a tokio::runtime::Runtime,
|
rt: &'a tokio::runtime::Runtime,
|
||||||
regions: &'a [TileCoords],
|
regions: &'a [TileCoords],
|
||||||
|
region_set: rustc_hash::FxHashSet<TileCoords>,
|
||||||
region_cache: Mutex<LruCache<PathBuf, Arc<OnceCell<RegionRef>>>>,
|
region_cache: Mutex<LruCache<PathBuf, Arc<OnceCell<RegionRef>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,10 +64,12 @@ impl<'a> TileRenderer<'a> {
|
||||||
let region_cache = Mutex::new(LruCache::new(
|
let region_cache = Mutex::new(LruCache::new(
|
||||||
NonZeroUsize::new(6 + 6 * config.num_threads).unwrap(),
|
NonZeroUsize::new(6 + 6 * config.num_threads).unwrap(),
|
||||||
));
|
));
|
||||||
|
let region_set = regions.iter().copied().collect();
|
||||||
TileRenderer {
|
TileRenderer {
|
||||||
config,
|
config,
|
||||||
rt,
|
rt,
|
||||||
regions,
|
regions,
|
||||||
|
region_set,
|
||||||
region_cache,
|
region_cache,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,11 +207,13 @@ impl<'a> TileRenderer<'a> {
|
||||||
|
|
||||||
fn processed_sources(&self, coords: TileCoords) -> Result<(RegionGroup<PathBuf>, SystemTime)> {
|
fn processed_sources(&self, coords: TileCoords) -> Result<(RegionGroup<PathBuf>, SystemTime)> {
|
||||||
let sources = RegionGroup::new(|x, z| {
|
let sources = RegionGroup::new(|x, z| {
|
||||||
self.processed_source(TileCoords {
|
Some(TileCoords {
|
||||||
x: coords.x + (x as i32),
|
x: coords.x + (x as i32),
|
||||||
z: coords.z + (z 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))?;
|
.with_context(|| format!("Region {:?} from previous step must exist", coords))?;
|
||||||
|
|
||||||
let max_timestamp = *sources
|
let max_timestamp = *sources
|
||||||
|
|
Loading…
Add table
Reference in a new issue