From 0988ebe0951ddeee43c693099a41ab18985b57ce Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 8 Jan 2024 02:35:05 +0100 Subject: [PATCH] core/tile_mipmapper: fix file meta version for mipmap tiles The meta version should only change when the outputs must be regenerated even if the inputs stay the same. This should never be the case for mipmap tiles, so we separate the meta version from map/lightmap tiles. --- src/core/common.rs | 5 +++++ src/core/tile_mipmapper.rs | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/core/common.rs b/src/core/common.rs index d17056f..49c8301 100644 --- a/src/core/common.rs +++ b/src/core/common.rs @@ -31,6 +31,11 @@ pub const MAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0); /// (usually because of updated resource data) pub const LIGHTMAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0); +/// MinedMap mipmap data version number +/// +/// Increase when the mipmap generation changes (this should not happen) +pub const MIPMAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0); + /// Coordinate pair of a generated tile /// /// Each tile corresponds to one Minecraft region file diff --git a/src/core/tile_mipmapper.rs b/src/core/tile_mipmapper.rs index 355bd23..6ea8750 100644 --- a/src/core/tile_mipmapper.rs +++ b/src/core/tile_mipmapper.rs @@ -70,12 +70,8 @@ impl<'a> TileMipmapper<'a> { /// Tile width/height const N: u32 = (BLOCKS_PER_CHUNK * CHUNKS_PER_REGION) as u32; - let version = match kind { - TileKind::Map => REGION_FILE_META_VERSION, - TileKind::Lightmap => LIGHTMAP_FILE_META_VERSION, - }; let output_path = self.config.tile_path(kind, level, coords); - let output_timestamp = fs::read_timestamp(&output_path, version); + let output_timestamp = fs::read_timestamp(&output_path, MIPMAP_FILE_META_VERSION); let sources: Vec<_> = [(0, 0), (0, 1), (1, 0), (1, 1)] .into_iter() @@ -149,11 +145,16 @@ impl<'a> TileMipmapper<'a> { ); } - fs::create_with_timestamp(&output_path, version, input_timestamp, |file| { - image - .write_to(file, image::ImageFormat::Png) - .context("Failed to save image") - })?; + fs::create_with_timestamp( + &output_path, + MIPMAP_FILE_META_VERSION, + input_timestamp, + |file| { + image + .write_to(file, image::ImageFormat::Png) + .context("Failed to save image") + }, + )?; count_processed.send(()).unwrap(); Ok(())