mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
world/layer: replace iproduct!() with nested loops
iproduct!() is slow for more than 2 parameters.
This commit is contained in:
parent
ed5fb9a6cf
commit
1d4c7a86ff
1 changed files with 21 additions and 22 deletions
|
@ -1,5 +1,4 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use itertools::iproduct;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::chunk::Chunk;
|
use super::chunk::Chunk;
|
||||||
|
@ -98,30 +97,30 @@ pub fn top_layer(chunk: &Chunk) -> Result<Box<BlockInfoArray>> {
|
||||||
let mut done = 0;
|
let mut done = 0;
|
||||||
let mut ret = Box::<BlockInfoArray>::default();
|
let mut ret = Box::<BlockInfoArray>::default();
|
||||||
|
|
||||||
for ((section_y, section), y, xz) in iproduct!(
|
for (section_y, section) in chunk.sections().rev() {
|
||||||
chunk.sections().rev(),
|
for y in BlockY::iter().rev() {
|
||||||
BlockY::iter().rev(),
|
for xz in BlockInfoArray::keys() {
|
||||||
BlockInfoArray::keys()
|
let entry = &mut ret[xz];
|
||||||
) {
|
if entry.done() {
|
||||||
let entry = &mut ret[xz];
|
continue;
|
||||||
if entry.done() {
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let coords = SectionBlockCoords { xz, y };
|
let coords = SectionBlockCoords { xz, y };
|
||||||
let Some(block_type) = section.block_at(coords)? else {
|
let Some(block_type) = section.block_at(coords)? else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let height = BlockHeight::new(section_y, y)?;
|
let height = BlockHeight::new(section_y, y)?;
|
||||||
if !entry.fill(height, block_type) {
|
if !entry.fill(height, block_type) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert!(entry.done());
|
assert!(entry.done());
|
||||||
|
|
||||||
done += 1;
|
done += 1;
|
||||||
if done == N * N {
|
if done == N * N {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue