Skip to content

Commit

Permalink
Density Function Re-Work (#525)
Browse files Browse the repository at this point in the history
* add density function parser, re-write functionality, and add initial tests

* add more tests and fix typo

* re-work density interpolator

* re-work flat cache

* re-work the rest of the chunk specific density functions

* re-work fill functions

* tweak sample logic and do some refactoring

* convert chunk noise to use new density functions

* work on porting proto chunk

* port proto chunk

* add cell cache test

* fix wrapper functions

* remove test print

* update benchmark

* rework again

* rework again pt 2

* classic off by one

* reduce components on the stack by 60x

* aquifer tweaks

* add multi noise sampler for biome sampling
  • Loading branch information
kralverde authored Feb 10, 2025
1 parent 45f5c27 commit 8d2ca8e
Show file tree
Hide file tree
Showing 52 changed files with 5,693 additions and 26,886 deletions.
1 change: 1 addition & 0 deletions assets/density_function.json

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion pumpkin-data/build/noise_parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ pub(crate) fn build() -> TokenStream {
serde_json::from_str(include_str!("../../assets/noise_parameters.json"))
.expect("Failed to parse noise_parameters.json");
let mut variants = TokenStream::new();
let mut match_variants = TokenStream::new();

for (name, parameter) in json.iter() {
let raw_name = format!("minecraft:{name}");
let simple_id = name;
let name = format_ident!("{}", name.to_uppercase());
let first_octave = parameter.first_octave;
let amplitudes = &parameter.amplitudes;
variants.extend([quote! {
pub const #name: DoublePerlinNoiseParameters = DoublePerlinNoiseParameters::new(#first_octave, &[#(#amplitudes),*], #raw_name);
}]);
match_variants.extend([quote! {
#simple_id => &#name,
}]);
}

quote! {
Expand All @@ -46,7 +51,14 @@ pub(crate) fn build() -> TokenStream {
}

pub const fn id(&self) -> &'static str {
self.id
self.id
}

pub fn id_to_parameters(id: &str) -> Option<&DoublePerlinNoiseParameters> {
Some(match id {
#match_variants
_ => return None,
})
}
}

Expand Down
12 changes: 6 additions & 6 deletions pumpkin-util/src/math/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use num_traits::PrimInt;
use num_traits::{One, PrimInt, Zero};

pub mod boundingbox;
pub mod experience;
Expand Down Expand Up @@ -68,11 +68,11 @@ pub const fn smallest_encompassing_power_of_two(value: u32) -> u32 {
#[inline]
pub fn floor_div<T>(x: T, y: T) -> T
where
T: PrimInt + From<i8>,
T: PrimInt + Zero + One,
{
let div = x / y;
if (x ^ y) < 0.into() && div * y != x {
div - 1.into()
if (x ^ y) < T::zero() && div * y != x {
div - T::one()
} else {
div
}
Expand All @@ -81,10 +81,10 @@ where
#[inline]
pub fn floor_mod<T>(x: T, y: T) -> T
where
T: PrimInt + From<i8>,
T: PrimInt + Zero,
{
let rem = x % y;
if (x ^ y) < 0.into() && rem != 0.into() {
if (x ^ y) < T::zero() && rem != T::zero() {
rem + y
} else {
rem
Expand Down
10 changes: 5 additions & 5 deletions pumpkin-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dashmap = "6.1"

num-traits = "0.2"

# Compression
# Compression
flate2 = "1.0"
lz4 = "1.28"
zstd = "0.13.2"
Expand All @@ -43,13 +43,13 @@ fastnbt = { git = "https://github.com/owengage/fastnbt.git" }
noise = "0.9"
rand = "0.8"

# Had to use custom, because google's is broken, I made a PR.
serde_json5 = { git = "https://github.com/kralverde/serde_json5.git" }

derive-getters = "0.5.0"
[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }

[[bench]]
name = "chunk_noise"
harness = false

[[bench]]
name = "chunk_noise_populate"
harness = false
1 change: 1 addition & 0 deletions pumpkin-world/assets/density_function_tests.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pumpkin-world/assets/no_blend_no_beard_0_0.chunk

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pumpkin-world/assets/no_blend_no_beard_7_4.chunk

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions pumpkin-world/benches/chunk_noise.rs

This file was deleted.

13 changes: 10 additions & 3 deletions pumpkin-world/benches/chunk_noise_populate.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
use criterion::{criterion_group, criterion_main, Criterion};
use pumpkin_world::bench_create_and_populate_noise;
use pumpkin_world::{
bench_create_and_populate_noise, GlobalRandomConfig, ProtoChunkNoiseRouter, NOISE_ROUTER_ASTS,
};

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("overworld convert + noise", |b| {
b.iter(bench_create_and_populate_noise)
let seed = 0;
let random_config = GlobalRandomConfig::new(seed);
let base_router =
ProtoChunkNoiseRouter::generate(NOISE_ROUTER_ASTS.overworld(), &random_config);

c.bench_function("overworld noise", |b| {
b.iter(|| bench_create_and_populate_noise(&base_router, &random_config));
});
}

Expand Down
Loading

0 comments on commit 8d2ca8e

Please sign in to comment.