mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 01:24:53 +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 struct Config {
|
||||||
pub region_dir: PathBuf,
|
pub region_dir: PathBuf,
|
||||||
pub processed_dir: PathBuf,
|
pub processed_dir: PathBuf,
|
||||||
pub light_dir: PathBuf,
|
pub output_dir: PathBuf,
|
||||||
pub map_dir: PathBuf,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn coord_filename(coords: TileCoords, ext: &str) -> String {
|
fn coord_filename(coords: TileCoords, ext: &str) -> String {
|
||||||
format!("r.{}.{}.{}", coords.x, coords.z, ext)
|
format!("r.{}.{}.{}", coords.x, coords.z, ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum TileKind {
|
||||||
|
Map,
|
||||||
|
Lightmap,
|
||||||
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn new(args: super::Args) -> Self {
|
pub fn new(args: super::Args) -> Self {
|
||||||
let region_dir = [&args.input_dir, Path::new("region")].iter().collect();
|
let region_dir = [&args.input_dir, Path::new("region")].iter().collect();
|
||||||
let processed_dir = [&args.output_dir, Path::new("processed")].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 {
|
Config {
|
||||||
region_dir,
|
region_dir,
|
||||||
processed_dir,
|
processed_dir,
|
||||||
light_dir,
|
output_dir: args.output_dir,
|
||||||
map_dir,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,14 +60,19 @@ impl Config {
|
||||||
[&self.processed_dir, Path::new(&filename)].iter().collect()
|
[&self.processed_dir, Path::new(&filename)].iter().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn light_path(&self, coords: TileCoords) -> PathBuf {
|
pub fn tile_dir(&self, kind: TileKind, level: usize) -> PathBuf {
|
||||||
let filename = coord_filename(coords, "png");
|
let prefix = match kind {
|
||||||
[&self.light_dir, Path::new(&filename)].iter().collect()
|
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");
|
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<()> {
|
fn save_lightmap(&self, coords: TileCoords, lightmap: &image::GrayAlphaImage) -> Result<()> {
|
||||||
fs::create_with_tmpfile(&self.config.light_path(coords), |file| {
|
fs::create_with_tmpfile(
|
||||||
lightmap
|
&self.config.tile_path(TileKind::Lightmap, 0, coords),
|
||||||
.write_to(file, image::ImageFormat::Png)
|
|file| {
|
||||||
.context("Failed to save image")
|
lightmap
|
||||||
})
|
.write_to(file, image::ImageFormat::Png)
|
||||||
|
.context("Failed to save image")
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes a single region file
|
/// 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.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();
|
let mut ret = BTreeSet::new();
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl<'a> TileRenderer<'a> {
|
||||||
fn render_tile(&self, coords: TileCoords) -> Result<()> {
|
fn render_tile(&self, coords: TileCoords) -> Result<()> {
|
||||||
const N: u32 = (BLOCKS_PER_CHUNK * CHUNKS_PER_REGION) as u32;
|
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!(
|
println!(
|
||||||
"Rendering tile {}",
|
"Rendering tile {}",
|
||||||
|
@ -81,7 +81,7 @@ impl<'a> TileRenderer<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(self, regions: impl IntoIterator<Item = TileCoords>) -> Result<()> {
|
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 {
|
for coords in regions {
|
||||||
if let Err(err) = self.render_tile(coords) {
|
if let Err(err) = self.render_tile(coords) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue