This commit is contained in:
Syniis 2024-03-04 00:47:35 +01:00
parent a07e270220
commit 87c847b108
5 changed files with 1 additions and 95 deletions

15
Cargo.lock generated
View File

@ -3166,22 +3166,8 @@ version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6acddbefae08bfba73e27f55513f491f35c365d84bf3002bf85ba9b916c5e5f"
dependencies = [
"inline_tweak_derive",
"lazy_static",
"proc-macro2 1.0.78",
"rustc-hash",
"syn 2.0.48",
]
[[package]]
name = "inline_tweak_derive"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46d62a0a3b6af04d4eee8e7251cd758ce74b0ed86253d3e4ac8a1b297a75f4a0"
dependencies = [
"proc-macro2 1.0.78",
"quote 1.0.35",
"syn 2.0.48",
]
[[package]]
@ -7456,7 +7442,6 @@ dependencies = [
"hashbrown 0.13.2",
"image",
"indicatif",
"inline_tweak",
"itertools 0.10.5",
"kiddo",
"lazy_static",

View File

@ -40,7 +40,7 @@ packed_simd = { version = "0.3.9", optional = true }
rayon = { workspace = true }
serde = { workspace = true }
ron = { workspace = true }
inline_tweak = { workspace = true, features = ["derive"] }
# inline_tweak = { workspace = true, features = ["derive"] }
kiddo = "0.2"
strum = { workspace = true }

View File

@ -1,6 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rayon::ThreadPoolBuilder;
use vek::Vec2;
use veloren_world::{
layer,
sim::{FileOpts, WorldOpts, DEFAULT_WORLD_MAP},
@ -37,30 +36,6 @@ fn cave(c: &mut Criterion) {
}
});
});
c.bench_function("generate_specific", |b| {
b.iter(|| {
let base_positions = vec![
Vec2::new(600, 650),
Vec2::new(630, 300),
Vec2::new(809, 141),
];
for base_pos in base_positions {
for i in 0..=4 {
for j in 0..=4 {
let pos = base_pos + Vec2::new(i as i32, j as i32) - 2;
_ = black_box(world.generate_chunk(
index.as_index_ref(),
pos,
None,
|| false,
None,
));
}
}
}
});
});
}
criterion_group!(benches, cave);

View File

@ -174,7 +174,6 @@ impl Tunnel {
}
}
#[inline_tweak::tweak_fn]
fn biome_at(&self, wpos: Vec3<i32>, info: &CanvasInfo) -> Biome {
let Some(col) = info.col_or_gen(wpos.xy()) else {
return Biome::default();
@ -542,7 +541,6 @@ struct Flower {
// rotation: Mat3<f32>,
}
#[inline_tweak::tweak_fn]
fn write_column<R: Rng>(
canvas: &mut Canvas,
col: &ColumnSample,

View File

@ -111,58 +111,6 @@ impl StructureGen2d {
)
})
}
/// Note: Generates all possible closest samples for elements in the range
/// of min to max, *exclusive.*
pub fn iter_with_wpos(
&self,
min: Vec2<i32>,
max: Vec2<i32>,
) -> impl Iterator<Item = (Vec2<i32>, StructureField)> {
let freq = self.freq;
let spread = self.spread;
let spread_mul = Self::spread_mul(spread);
assert!(spread * 2 == spread_mul);
assert!(spread_mul <= freq);
let spread = spread as i32;
let freq = freq as i32;
let freq_offset = Self::freq_offset(freq);
assert!(freq_offset * 2 == freq);
let min_index = Self::sample_to_index_internal(freq, min) - 1;
let max_index = Self::sample_to_index_internal(freq, max) + 1;
assert!(min_index.x < max_index.x);
// NOTE: xlen > 0
let xlen = (max_index.x - min_index.x) as u32;
assert!(min_index.y < max_index.y);
// NOTE: ylen > 0
let ylen = (max_index.y - min_index.y) as u32;
// NOTE: Cannot fail, since every product of u32s fits in a u64.
let len = ylen as u64 * xlen as u64;
// NOTE: since iteration is *exclusive* for the initial range, it's fine that we
// don't go up to the maximum value.
// NOTE: we convert to usize first, and then iterate, because we want to make
// sure we get a properly indexed parallel iterator that can deal with
// the whole range at once.
let x_field = self.x_field;
let y_field = self.y_field;
let seed_field = self.seed_field;
(0..len).map(move |xy| {
let index = min_index + Vec2::new((xy % xlen as u64) as i32, (xy / xlen as u64) as i32);
let index_wpos = min + Vec2::new((xy % xlen as u64) as i32, (xy / len as u64) as i32);
let field = Self::index_to_sample_internal(
freq,
freq_offset,
spread,
spread_mul,
x_field,
y_field,
seed_field,
index,
);
(index_wpos, field)
})
}
}
impl Sampler<'static> for StructureGen2d {