core/common: separate FileMetaVersion for different outputs

This commit is contained in:
Matthias Schiffer 2023-11-25 22:11:44 +01:00
parent 4574c06f5d
commit fa15a4e6e5
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
4 changed files with 21 additions and 11 deletions

View file

@ -11,10 +11,16 @@ use serde::{Deserialize, Serialize};
use crate::{io::fs::FileMetaVersion, resource::Biome, types::*, world::layer}; use crate::{io::fs::FileMetaVersion, resource::Biome, types::*, world::layer};
/// MinedMap data version number
///
/// Increase to force regeneration of all output files /// Increase to force regeneration of all output files
pub const FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0);
/// MinedMap processed region data version number
pub const REGION_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0);
/// MinedMap map tile data version number
pub const MAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0);
/// MinedMap lightmap data version number
pub const LIGHTMAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0);
/// Coordinate pair of a generated tile /// Coordinate pair of a generated tile
/// ///

View file

@ -126,7 +126,7 @@ impl<'a> RegionProcessor<'a> {
processed_region: &ProcessedRegion, processed_region: &ProcessedRegion,
timestamp: SystemTime, timestamp: SystemTime,
) -> Result<()> { ) -> Result<()> {
storage::write(path, processed_region, FILE_META_VERSION, timestamp) storage::write(path, processed_region, REGION_FILE_META_VERSION, timestamp)
} }
/// Saves a lightmap tile /// Saves a lightmap tile
@ -137,7 +137,7 @@ impl<'a> RegionProcessor<'a> {
lightmap: &image::GrayAlphaImage, lightmap: &image::GrayAlphaImage,
timestamp: SystemTime, timestamp: SystemTime,
) -> Result<()> { ) -> Result<()> {
fs::create_with_timestamp(path, FILE_META_VERSION, timestamp, |file| { fs::create_with_timestamp(path, LIGHTMAP_FILE_META_VERSION, timestamp, |file| {
lightmap lightmap
.write_to(file, image::ImageFormat::Png) .write_to(file, image::ImageFormat::Png)
.context("Failed to save image") .context("Failed to save image")
@ -156,9 +156,9 @@ impl<'a> RegionProcessor<'a> {
let input_timestamp = fs::modified_timestamp(&input_path)?; let input_timestamp = fs::modified_timestamp(&input_path)?;
let output_path = self.config.processed_path(coords); let output_path = self.config.processed_path(coords);
let output_timestamp = fs::read_timestamp(&output_path, FILE_META_VERSION); let output_timestamp = fs::read_timestamp(&output_path, REGION_FILE_META_VERSION);
let lightmap_path = self.config.tile_path(TileKind::Lightmap, 0, coords); let lightmap_path = self.config.tile_path(TileKind::Lightmap, 0, coords);
let lightmap_timestamp = fs::read_timestamp(&lightmap_path, FILE_META_VERSION); let lightmap_timestamp = fs::read_timestamp(&lightmap_path, LIGHTMAP_FILE_META_VERSION);
if Some(input_timestamp) <= output_timestamp && Some(input_timestamp) <= lightmap_timestamp if Some(input_timestamp) <= output_timestamp && Some(input_timestamp) <= lightmap_timestamp
{ {

View file

@ -70,8 +70,12 @@ impl<'a> TileMipmapper<'a> {
/// Tile width/height /// Tile width/height
const N: u32 = (BLOCKS_PER_CHUNK * CHUNKS_PER_REGION) as u32; 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_path = self.config.tile_path(kind, level, coords);
let output_timestamp = fs::read_timestamp(&output_path, FILE_META_VERSION); let output_timestamp = fs::read_timestamp(&output_path, version);
let sources: Vec<_> = [(0, 0), (0, 1), (1, 0), (1, 1)] let sources: Vec<_> = [(0, 0), (0, 1), (1, 0), (1, 1)]
.into_iter() .into_iter()
@ -145,7 +149,7 @@ impl<'a> TileMipmapper<'a> {
); );
} }
fs::create_with_timestamp(&output_path, FILE_META_VERSION, input_timestamp, |file| { fs::create_with_timestamp(&output_path, version, input_timestamp, |file| {
image image
.write_to(file, image::ImageFormat::Png) .write_to(file, image::ImageFormat::Png)
.context("Failed to save image") .context("Failed to save image")

View file

@ -270,7 +270,7 @@ impl<'a> TileRenderer<'a> {
let (processed_paths, processed_timestamp) = self.processed_sources(coords)?; let (processed_paths, processed_timestamp) = self.processed_sources(coords)?;
let output_path = self.config.tile_path(TileKind::Map, 0, coords); let output_path = self.config.tile_path(TileKind::Map, 0, coords);
let output_timestamp = fs::read_timestamp(&output_path, FILE_META_VERSION); let output_timestamp = fs::read_timestamp(&output_path, MAP_FILE_META_VERSION);
if Some(processed_timestamp) <= output_timestamp { if Some(processed_timestamp) <= output_timestamp {
debug!( debug!(
@ -300,7 +300,7 @@ impl<'a> TileRenderer<'a> {
fs::create_with_timestamp( fs::create_with_timestamp(
&output_path, &output_path,
FILE_META_VERSION, MAP_FILE_META_VERSION,
processed_timestamp, processed_timestamp,
|file| { |file| {
image image