mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
minedmap: move inputs to processing steps from run() to new()
This commit is contained in:
parent
6a82fcc9b4
commit
722fe00d77
4 changed files with 26 additions and 18 deletions
|
@ -48,9 +48,9 @@ fn main() -> Result<()> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let regions = RegionProcessor::new(&config).run()?;
|
let regions = RegionProcessor::new(&config).run()?;
|
||||||
TileRenderer::new(&config, &rt).run(®ions)?;
|
TileRenderer::new(&config, &rt, ®ions).run()?;
|
||||||
let tiles = TileMipmapper::new(&config).run(®ions)?;
|
let tiles = TileMipmapper::new(&config, ®ions).run()?;
|
||||||
MetadataWriter::new(&config).run(tiles)?;
|
MetadataWriter::new(&config, &tiles).run()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,6 @@ use serde::Serialize;
|
||||||
|
|
||||||
use super::common::*;
|
use super::common::*;
|
||||||
|
|
||||||
pub struct MetadataWriter<'a> {
|
|
||||||
config: &'a Config,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct Bounds {
|
struct Bounds {
|
||||||
|
@ -35,9 +31,14 @@ struct Metadata<'t> {
|
||||||
spawn: Spawn,
|
spawn: Spawn,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct MetadataWriter<'a> {
|
||||||
|
config: &'a Config,
|
||||||
|
tiles: &'a [TileCoordMap],
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> MetadataWriter<'a> {
|
impl<'a> MetadataWriter<'a> {
|
||||||
pub fn new(config: &'a Config) -> Self {
|
pub fn new(config: &'a Config, tiles: &'a [TileCoordMap]) -> Self {
|
||||||
MetadataWriter { config }
|
MetadataWriter { config, tiles }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mipmap_entry(regions: &TileCoordMap) -> Mipmap {
|
fn mipmap_entry(regions: &TileCoordMap) -> Mipmap {
|
||||||
|
@ -87,7 +88,7 @@ impl<'a> MetadataWriter<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&self, tiles: Vec<TileCoordMap>) -> Result<()> {
|
pub fn run(self) -> Result<()> {
|
||||||
let level_dat = self.read_level_dat()?;
|
let level_dat = self.read_level_dat()?;
|
||||||
|
|
||||||
let mut metadata = Metadata {
|
let mut metadata = Metadata {
|
||||||
|
@ -95,7 +96,7 @@ impl<'a> MetadataWriter<'a> {
|
||||||
spawn: Self::spawn(&level_dat),
|
spawn: Self::spawn(&level_dat),
|
||||||
};
|
};
|
||||||
|
|
||||||
for tile_map in tiles.iter() {
|
for tile_map in self.tiles.iter() {
|
||||||
metadata.mipmaps.push(Self::mipmap_entry(tile_map));
|
metadata.mipmaps.push(Self::mipmap_entry(tile_map));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,12 @@ use super::common::*;
|
||||||
|
|
||||||
pub struct TileMipmapper<'a> {
|
pub struct TileMipmapper<'a> {
|
||||||
config: &'a Config,
|
config: &'a Config,
|
||||||
|
regions: &'a [TileCoords],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TileMipmapper<'a> {
|
impl<'a> TileMipmapper<'a> {
|
||||||
pub fn new(config: &'a Config) -> Self {
|
pub fn new(config: &'a Config, regions: &'a [TileCoords]) -> Self {
|
||||||
TileMipmapper { config }
|
TileMipmapper { config, regions }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn done(tiles: &TileCoordMap) -> bool {
|
fn done(tiles: &TileCoordMap) -> bool {
|
||||||
|
@ -129,11 +130,11 @@ impl<'a> TileMipmapper<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(self, tiles: &[TileCoords]) -> Result<Vec<TileCoordMap>> {
|
pub fn run(self) -> Result<Vec<TileCoordMap>> {
|
||||||
let mut tile_stack = {
|
let mut tile_stack = {
|
||||||
let mut tile_map = TileCoordMap::default();
|
let mut tile_map = TileCoordMap::default();
|
||||||
|
|
||||||
for &TileCoords { x, z } in tiles {
|
for &TileCoords { x, z } in self.regions {
|
||||||
tile_map.0.entry(z).or_default().insert(x);
|
tile_map.0.entry(z).or_default().insert(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,17 +50,23 @@ fn biome_at(
|
||||||
pub struct TileRenderer<'a> {
|
pub struct TileRenderer<'a> {
|
||||||
config: &'a Config,
|
config: &'a Config,
|
||||||
rt: &'a tokio::runtime::Runtime,
|
rt: &'a tokio::runtime::Runtime,
|
||||||
|
regions: &'a [TileCoords],
|
||||||
region_cache: Mutex<LruCache<PathBuf, Arc<OnceCell<RegionRef>>>>,
|
region_cache: Mutex<LruCache<PathBuf, Arc<OnceCell<RegionRef>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TileRenderer<'a> {
|
impl<'a> TileRenderer<'a> {
|
||||||
pub fn new(config: &'a Config, rt: &'a tokio::runtime::Runtime) -> Self {
|
pub fn new(
|
||||||
|
config: &'a Config,
|
||||||
|
rt: &'a tokio::runtime::Runtime,
|
||||||
|
regions: &'a [TileCoords],
|
||||||
|
) -> Self {
|
||||||
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(),
|
||||||
));
|
));
|
||||||
TileRenderer {
|
TileRenderer {
|
||||||
config,
|
config,
|
||||||
rt,
|
rt,
|
||||||
|
regions,
|
||||||
region_cache,
|
region_cache,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,11 +267,11 @@ impl<'a> TileRenderer<'a> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(self, regions: &[TileCoords]) -> Result<()> {
|
pub fn run(self) -> Result<()> {
|
||||||
fs::create_dir_all(&self.config.tile_dir(TileKind::Map, 0))?;
|
fs::create_dir_all(&self.config.tile_dir(TileKind::Map, 0))?;
|
||||||
|
|
||||||
// Use par_bridge to process items in order (for better use of region cache)
|
// Use par_bridge to process items in order (for better use of region cache)
|
||||||
regions.iter().par_bridge().try_for_each(|&coords| {
|
self.regions.iter().par_bridge().try_for_each(|&coords| {
|
||||||
self.render_tile(coords)
|
self.render_tile(coords)
|
||||||
.with_context(|| format!("Failed to render tile {:?}", coords))
|
.with_context(|| format!("Failed to render tile {:?}", coords))
|
||||||
})?;
|
})?;
|
||||||
|
|
Loading…
Add table
Reference in a new issue