Stop duplicating terrian chunk metadata.

This commit is contained in:
Joshua Yanovski 2022-06-30 11:22:14 -07:00
parent ad5bcf3cd8
commit 4819a17ab6
2 changed files with 15 additions and 14 deletions

View File

@ -60,7 +60,7 @@ impl<V, Storage, ChonkSize: RectVolSize> VolSize<V> for SubChunkSize<V, Storage,
}; };
} }
pub type SubChunk<V, Storage, S, M> = Chunk<V, SubChunkSize<V, Storage, S>, M>; pub type SubChunk<V, Storage, S, M> = Chunk<V, SubChunkSize<V, Storage, S>, PhantomData<M>>;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Chonk<V, Storage, S: RectVolSize, M: Clone> { pub struct Chonk<V, Storage, S: RectVolSize, M: Clone> {
@ -229,7 +229,7 @@ impl<V: Clone + PartialEq, Storage: Clone + core::ops::DerefMut<Target=Vec<V>> +
return Ok(self.below.clone()); return Ok(self.below.clone());
} }
// Prepend exactly sufficiently many SubChunks via Vec::splice // Prepend exactly sufficiently many SubChunks via Vec::splice
let c = Chunk::<V, SubChunkSize<V, Storage, S>, M>::filled(self.below.clone(), self.meta.clone()); let c = SubChunk::<V, Storage, S, M>::filled(self.below.clone(), /*self.meta.clone()*/PhantomData);
let n = (-sub_chunk_idx) as usize; let n = (-sub_chunk_idx) as usize;
self.sub_chunks.splice(0..0, std::iter::repeat(c).take(n)); self.sub_chunks.splice(0..0, std::iter::repeat(c).take(n));
self.z_offset += sub_chunk_idx * SubChunkSize::<V, Storage, S>::SIZE.z as i32; self.z_offset += sub_chunk_idx * SubChunkSize::<V, Storage, S>::SIZE.z as i32;
@ -240,7 +240,7 @@ impl<V: Clone + PartialEq, Storage: Clone + core::ops::DerefMut<Target=Vec<V>> +
return Ok(self.above.clone()); return Ok(self.above.clone());
} }
// Append exactly sufficiently many SubChunks via Vec::extend // Append exactly sufficiently many SubChunks via Vec::extend
let c = Chunk::<V, SubChunkSize<V, Storage, S>, M>::filled(self.above.clone(), self.meta.clone()); let c = SubChunk::<V, Storage, S, M>::filled(self.above.clone(), /*self.meta.clone()*/PhantomData);
let n = 1 + sub_chunk_idx as usize - self.sub_chunks.len(); let n = 1 + sub_chunk_idx as usize - self.sub_chunks.len();
self.sub_chunks.extend(std::iter::repeat(c).take(n)); self.sub_chunks.extend(std::iter::repeat(c).take(n));
} }
@ -282,7 +282,7 @@ impl<V, Storage, S: RectVolSize, M: Clone> Iterator for ChonkIterHelper<V, Stora
pub struct ChonkPosIter<V, Storage, S: RectVolSize, M: Clone> { pub struct ChonkPosIter<V, Storage, S: RectVolSize, M: Clone> {
outer: ChonkIterHelper<V, Storage, S, M>, outer: ChonkIterHelper<V, Storage, S, M>,
opt_inner: Option<(i32, ChunkPosIter<V, SubChunkSize<V, Storage, S>, M>)>, opt_inner: Option<(i32, ChunkPosIter<V, SubChunkSize<V, Storage, S>, PhantomData<M>>)>,
} }
impl<V, Storage, S: RectVolSize, M: Clone> Iterator for ChonkPosIter<V, Storage, S, M> { impl<V, Storage, S: RectVolSize, M: Clone> Iterator for ChonkPosIter<V, Storage, S, M> {
@ -308,8 +308,8 @@ impl<V, Storage, S: RectVolSize, M: Clone> Iterator for ChonkPosIter<V, Storage,
} }
enum InnerChonkVolIter<'a, V, Storage, S: RectVolSize, M: Clone> { enum InnerChonkVolIter<'a, V, Storage, S: RectVolSize, M: Clone> {
Vol(ChunkVolIter<'a, V, SubChunkSize<V, Storage, S>, M>), Vol(ChunkVolIter<'a, V, SubChunkSize<V, Storage, S>, PhantomData<M>>),
Pos(ChunkPosIter<V, SubChunkSize<V, Storage, S>, M>), Pos(ChunkPosIter<V, SubChunkSize<V, Storage, S>, PhantomData<M>>),
} }
pub struct ChonkVolIter<'a, V, Storage, S: RectVolSize, M: Clone> { pub struct ChonkVolIter<'a, V, Storage, S: RectVolSize, M: Clone> {

View File

@ -13,6 +13,7 @@ use common_net::msg::compression::{
PackingFormula, QuadPngEncoding, TriPngEncoding, VoxelImageDecoding, VoxelImageEncoding, PackingFormula, QuadPngEncoding, TriPngEncoding, VoxelImageDecoding, VoxelImageEncoding,
WidePacking, WidePacking,
}; };
use core::marker::PhantomData;
use hashbrown::HashMap; use hashbrown::HashMap;
use image::ImageBuffer; use image::ImageBuffer;
use num_traits::cast::FromPrimitive; use num_traits::cast::FromPrimitive;
@ -363,7 +364,7 @@ impl VoxelImageEncoding for MixedEncodingSparseSprites {
type Output = ( type Output = (
Vec<u8>, Vec<u8>,
usize, usize,
CompressedData<HashMap<Vec2<u32>, (SpriteKind, u8)>>, CompressedData<'static, HashMap<Vec2<u32>, (SpriteKind, u8)>>,
); );
type Workspace = ( type Workspace = (
image::ImageBuffer<image::Luma<u8>, Vec<u8>>, image::ImageBuffer<image::Luma<u8>, Vec<u8>>,
@ -590,7 +591,7 @@ impl<P: RTreeParams> NearestNeighbor for RTree<ColorPoint, P> {
pub struct PaletteEncoding<'a, NN: NearestNeighbor, const N: u32>(&'a HashMap<BlockKind, NN>); pub struct PaletteEncoding<'a, NN: NearestNeighbor, const N: u32>(&'a HashMap<BlockKind, NN>);
impl<'a, NN: NearestNeighbor, const N: u32> VoxelImageEncoding for PaletteEncoding<'a, NN, N> { impl<'a, NN: NearestNeighbor, const N: u32> VoxelImageEncoding for PaletteEncoding<'a, NN, N> {
type Output = CompressedData<(Vec<u8>, [usize; 4])>; type Output = CompressedData<'a, (Vec<u8>, [usize; 4])>;
type Workspace = ( type Workspace = (
ImageBuffer<image::Luma<u8>, Vec<u8>>, ImageBuffer<image::Luma<u8>, Vec<u8>>,
ImageBuffer<image::Luma<u8>, Vec<u8>>, ImageBuffer<image::Luma<u8>, Vec<u8>>,
@ -1017,7 +1018,7 @@ fn main() {
let quadpngfull_pre = Instant::now(); let quadpngfull_pre = Instant::now();
let quadpngfull = image_terrain_chonk( let quadpngfull = image_terrain_chonk(
&QuadPngEncoding::<1>(), &QuadPngEncoding::<1>(PhantomData),
TallPacking { flip_y: true }, TallPacking { flip_y: true },
&chunk, &chunk,
) )
@ -1026,7 +1027,7 @@ fn main() {
let quadpnghalf_pre = Instant::now(); let quadpnghalf_pre = Instant::now();
let quadpnghalf = image_terrain_chonk( let quadpnghalf = image_terrain_chonk(
&QuadPngEncoding::<2>(), &QuadPngEncoding::<2>(PhantomData),
TallPacking { flip_y: true }, TallPacking { flip_y: true },
&chunk, &chunk,
) )
@ -1035,7 +1036,7 @@ fn main() {
let quadpngquarttall_pre = Instant::now(); let quadpngquarttall_pre = Instant::now();
let quadpngquarttall = image_terrain_chonk( let quadpngquarttall = image_terrain_chonk(
&QuadPngEncoding::<4>(), &QuadPngEncoding::<4>(PhantomData),
TallPacking { flip_y: true }, TallPacking { flip_y: true },
&chunk, &chunk,
) )
@ -1044,19 +1045,19 @@ fn main() {
let quadpngquartwide_pre = Instant::now(); let quadpngquartwide_pre = Instant::now();
let quadpngquartwide = let quadpngquartwide =
image_terrain_chonk(&QuadPngEncoding::<4>(), WidePacking::<true>(), &chunk) image_terrain_chonk(&QuadPngEncoding::<4>(PhantomData), WidePacking::<true>(), &chunk)
.unwrap(); .unwrap();
let quadpngquartwide_post = Instant::now(); let quadpngquartwide_post = Instant::now();
let tripngaverage_pre = Instant::now(); let tripngaverage_pre = Instant::now();
let tripngaverage = let tripngaverage =
image_terrain_chonk(&TriPngEncoding::<true>(), WidePacking::<true>(), &chunk) image_terrain_chonk(&TriPngEncoding::<true>(PhantomData), WidePacking::<true>(), &chunk)
.unwrap(); .unwrap();
let tripngaverage_post = Instant::now(); let tripngaverage_post = Instant::now();
let tripngconst_pre = Instant::now(); let tripngconst_pre = Instant::now();
let tripngconst = let tripngconst =
image_terrain_chonk(&TriPngEncoding::<false>(), WidePacking::<true>(), &chunk) image_terrain_chonk(&TriPngEncoding::<false>(PhantomData), WidePacking::<true>(), &chunk)
.unwrap(); .unwrap();
let tripngconst_post = Instant::now(); let tripngconst_post = Instant::now();