mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
minedmap: introduce generic tile path function, pass mipmap level
This commit is contained in:
parent
b53d34da3d
commit
b1f7f759f1
3 changed files with 29 additions and 19 deletions
|
@ -30,26 +30,28 @@ pub type ProcessedRegion = ChunkArray<Option<ProcessedChunk>>;
|
|||
pub struct Config {
|
||||
pub region_dir: PathBuf,
|
||||
pub processed_dir: PathBuf,
|
||||
pub light_dir: PathBuf,
|
||||
pub map_dir: PathBuf,
|
||||
pub output_dir: PathBuf,
|
||||
}
|
||||
|
||||
fn coord_filename(coords: TileCoords, ext: &str) -> String {
|
||||
format!("r.{}.{}.{}", coords.x, coords.z, ext)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum TileKind {
|
||||
Map,
|
||||
Lightmap,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new(args: super::Args) -> Self {
|
||||
let region_dir = [&args.input_dir, Path::new("region")].iter().collect();
|
||||
let processed_dir = [&args.output_dir, Path::new("processed")].iter().collect();
|
||||
let light_dir = [&args.output_dir, Path::new("light/0")].iter().collect();
|
||||
let map_dir = [&args.output_dir, Path::new("map/0")].iter().collect();
|
||||
|
||||
Config {
|
||||
region_dir,
|
||||
processed_dir,
|
||||
light_dir,
|
||||
map_dir,
|
||||
output_dir: args.output_dir,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,14 +60,19 @@ impl Config {
|
|||
[&self.processed_dir, Path::new(&filename)].iter().collect()
|
||||
}
|
||||
|
||||
pub fn light_path(&self, coords: TileCoords) -> PathBuf {
|
||||
let filename = coord_filename(coords, "png");
|
||||
[&self.light_dir, Path::new(&filename)].iter().collect()
|
||||
pub fn tile_dir(&self, kind: TileKind, level: usize) -> PathBuf {
|
||||
let prefix = match kind {
|
||||
TileKind::Map => "map",
|
||||
TileKind::Lightmap => "light",
|
||||
};
|
||||
let dir = format!("{}/{}", prefix, level);
|
||||
[&self.output_dir, Path::new(&dir)].iter().collect()
|
||||
}
|
||||
|
||||
pub fn map_path(&self, coords: TileCoords) -> PathBuf {
|
||||
pub fn tile_path(&self, kind: TileKind, level: usize, coords: TileCoords) -> PathBuf {
|
||||
let filename = coord_filename(coords, "png");
|
||||
[&self.map_dir, Path::new(&filename)].iter().collect()
|
||||
let dir = self.tile_dir(kind, level);
|
||||
[Path::new(&dir), Path::new(&filename)].iter().collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,11 +71,14 @@ impl<'a> RegionProcessor<'a> {
|
|||
}
|
||||
|
||||
fn save_lightmap(&self, coords: TileCoords, lightmap: &image::GrayAlphaImage) -> Result<()> {
|
||||
fs::create_with_tmpfile(&self.config.light_path(coords), |file| {
|
||||
lightmap
|
||||
.write_to(file, image::ImageFormat::Png)
|
||||
.context("Failed to save image")
|
||||
})
|
||||
fs::create_with_tmpfile(
|
||||
&self.config.tile_path(TileKind::Lightmap, 0, coords),
|
||||
|file| {
|
||||
lightmap
|
||||
.write_to(file, image::ImageFormat::Png)
|
||||
.context("Failed to save image")
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Processes a single region file
|
||||
|
@ -126,7 +129,7 @@ impl<'a> RegionProcessor<'a> {
|
|||
})?;
|
||||
|
||||
fs::create_dir_all(&self.config.processed_dir)?;
|
||||
fs::create_dir_all(&self.config.light_dir)?;
|
||||
fs::create_dir_all(&self.config.tile_dir(TileKind::Lightmap, 0))?;
|
||||
|
||||
let mut ret = BTreeSet::new();
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ impl<'a> TileRenderer<'a> {
|
|||
fn render_tile(&self, coords: TileCoords) -> Result<()> {
|
||||
const N: u32 = (BLOCKS_PER_CHUNK * CHUNKS_PER_REGION) as u32;
|
||||
|
||||
let output_path = self.config.map_path(coords);
|
||||
let output_path = self.config.tile_path(TileKind::Map, 0, coords);
|
||||
|
||||
println!(
|
||||
"Rendering tile {}",
|
||||
|
@ -81,7 +81,7 @@ impl<'a> TileRenderer<'a> {
|
|||
}
|
||||
|
||||
pub fn run(self, regions: impl IntoIterator<Item = TileCoords>) -> Result<()> {
|
||||
fs::create_dir_all(&self.config.map_dir)?;
|
||||
fs::create_dir_all(&self.config.tile_dir(TileKind::Map, 0))?;
|
||||
|
||||
for coords in regions {
|
||||
if let Err(err) = self.render_tile(coords) {
|
||||
|
|
Loading…
Add table
Reference in a new issue