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
|
||||
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 x: i32,
|
||||
pub z: i32,
|
||||
|
|
|
@ -16,25 +16,24 @@ pub struct RegionGroup<T> {
|
|||
}
|
||||
|
||||
impl<T> RegionGroup<T> {
|
||||
pub fn new<F>(f: F) -> Result<Self>
|
||||
pub fn new<F>(f: F) -> Self
|
||||
where
|
||||
F: Fn(i8, i8) -> Result<T>,
|
||||
F: Fn(i8, i8) -> Option<T>,
|
||||
{
|
||||
RegionGroup {
|
||||
center: (0, 0),
|
||||
center: f(0, 0).expect("Center element of RegionGroup must not be None"),
|
||||
neighs: [
|
||||
Some((-1, -1)),
|
||||
Some((-1, 0)),
|
||||
Some((-1, 1)),
|
||||
Some((0, -1)),
|
||||
f(-1, -1),
|
||||
f(-1, 0),
|
||||
f(-1, 1),
|
||||
f(0, -1),
|
||||
None,
|
||||
Some((0, 1)),
|
||||
Some((1, -1)),
|
||||
Some((1, 0)),
|
||||
Some((1, 1)),
|
||||
f(0, 1),
|
||||
f(1, -1),
|
||||
f(1, 0),
|
||||
f(1, 1),
|
||||
],
|
||||
}
|
||||
.try_map(|(x, z)| f(x, z))
|
||||
}
|
||||
|
||||
pub fn center(&self) -> &T {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue