mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
world/section: perform palette lookups early
Look up block types for all palette entries once during section construction, rather than on block_at(), reducing the number of HashMap lookups by ~1000.
This commit is contained in:
parent
5c82b80924
commit
04bc3e5d53
1 changed files with 15 additions and 12 deletions
|
@ -67,8 +67,7 @@ impl<'a> BiomesV18<'a> {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SectionV1_13<'a> {
|
pub struct SectionV1_13<'a> {
|
||||||
block_states: Option<&'a fastnbt::LongArray>,
|
block_states: Option<&'a fastnbt::LongArray>,
|
||||||
palette: &'a Vec<de::BlockStatePaletteEntry>,
|
palette: Vec<Option<BlockType>>,
|
||||||
block_types: &'a BlockTypes,
|
|
||||||
bits: u8,
|
bits: u8,
|
||||||
aligned_blocks: bool,
|
aligned_blocks: bool,
|
||||||
}
|
}
|
||||||
|
@ -97,10 +96,20 @@ impl<'a> SectionV1_13<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let palette_types = palette
|
||||||
|
.iter()
|
||||||
|
.map(|entry| {
|
||||||
|
let block_type = block_types.get(&entry.name);
|
||||||
|
if block_type.is_none() {
|
||||||
|
eprintln!("Unknown block type: {}", entry.name);
|
||||||
|
}
|
||||||
|
block_type
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
block_states,
|
block_states,
|
||||||
palette,
|
palette: palette_types,
|
||||||
block_types,
|
|
||||||
bits,
|
bits,
|
||||||
aligned_blocks,
|
aligned_blocks,
|
||||||
})
|
})
|
||||||
|
@ -139,16 +148,10 @@ impl<'a> SectionV1_13<'a> {
|
||||||
impl<'a> Section for SectionV1_13<'a> {
|
impl<'a> Section for SectionV1_13<'a> {
|
||||||
fn block_at(&self, coords: SectionBlockCoords) -> Result<Option<BlockType>> {
|
fn block_at(&self, coords: SectionBlockCoords) -> Result<Option<BlockType>> {
|
||||||
let index = self.palette_index_at(coords);
|
let index = self.palette_index_at(coords);
|
||||||
let entry = self
|
Ok(*self
|
||||||
.palette
|
.palette
|
||||||
.get(index)
|
.get(index)
|
||||||
.context("Palette index out of bounds")?;
|
.context("Palette index out of bounds")?)
|
||||||
|
|
||||||
let block_type = self.block_types.get(&entry.name);
|
|
||||||
if block_type.is_none() {
|
|
||||||
eprintln!("Unknown block type: {}", entry.name);
|
|
||||||
}
|
|
||||||
Ok(block_type)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue