Skip to content

Commit d41e5b9

Browse files
committed
fix: structures
1 parent 3392aa1 commit d41e5b9

File tree

24 files changed

+365
-238
lines changed

24 files changed

+365
-238
lines changed

pumpkin-util/src/noise/perlin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ mod tests {
477477
use crate::{
478478
assert_eq_delta,
479479
noise::perlin::{OctavePerlinNoiseSampler, PerlinNoiseSampler},
480-
random::{RandomDeriverImpl, RandomImpl, legacy_rand::LegacyRand, xoroshiro128::Xoroshiro},
480+
random::{RandomImpl, legacy_rand::LegacyRand, xoroshiro128::Xoroshiro},
481481
read_data_from_file,
482482
};
483483

pumpkin-util/src/random/xoroshiro128.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ impl Xoroshiro {
126126
self.hi = m.rotate_left(28);
127127
n
128128
}
129+
130+
pub const fn next_splitter(&mut self) -> XoroshiroSplitter {
131+
XoroshiroSplitter {
132+
lo: self.next_random(),
133+
hi: self.next_random(),
134+
}
135+
}
129136
}
130137

131138
impl GaussianGenerator for Xoroshiro {
@@ -160,10 +167,7 @@ impl RandomImpl for Xoroshiro {
160167
}
161168

162169
fn next_splitter(&mut self) -> RandomDeriver {
163-
RandomDeriver::Xoroshiro(XoroshiroSplitter {
164-
lo: self.next_random(),
165-
hi: self.next_random(),
166-
})
170+
RandomDeriver::Xoroshiro(self.next_splitter())
167171
}
168172

169173
fn next_i32(&mut self) -> i32 {
@@ -220,25 +224,36 @@ pub struct XoroshiroSplitter {
220224
hi: u64,
221225
}
222226

223-
impl RandomDeriverImpl for XoroshiroSplitter {
224-
fn split_string(&self, seed: &str) -> RandomGenerator {
227+
impl XoroshiroSplitter {
228+
#[must_use]
229+
pub fn split_string(&self, seed: &str) -> Xoroshiro {
225230
let bytes = md5::compute(seed.as_bytes());
226231
let l = u64::from_be_bytes(bytes[0..8].try_into().expect("incorrect length"));
227232
let m = u64::from_be_bytes(bytes[8..16].try_into().expect("incorrect length"));
228233

229-
RandomGenerator::Xoroshiro(Xoroshiro::new(l ^ self.lo, m ^ self.hi))
234+
Xoroshiro::new(l ^ self.lo, m ^ self.hi)
235+
}
236+
237+
#[must_use]
238+
pub fn split_pos(&self, x: i32, y: i32, z: i32) -> Xoroshiro {
239+
let l = hash_block_pos(x, y, z) as u64;
240+
let m = l ^ self.lo;
241+
242+
Xoroshiro::new(m, self.hi)
243+
}
244+
}
245+
246+
impl RandomDeriverImpl for XoroshiroSplitter {
247+
fn split_string(&self, seed: &str) -> RandomGenerator {
248+
RandomGenerator::Xoroshiro(self.split_string(seed))
230249
}
231250

232251
fn split_u64(&self, seed: u64) -> RandomGenerator {
233252
RandomGenerator::Xoroshiro(Xoroshiro::new(seed ^ self.lo, seed ^ self.hi))
234253
}
235254

236-
#[expect(clippy::many_single_char_names)]
237255
fn split_pos(&self, x: i32, y: i32, z: i32) -> RandomGenerator {
238-
let l = hash_block_pos(x, y, z) as u64;
239-
let m = l ^ self.lo;
240-
241-
RandomGenerator::Xoroshiro(Xoroshiro::new(m, self.hi))
256+
RandomGenerator::Xoroshiro(self.split_pos(x, y, z))
242257
}
243258
}
244259

pumpkin-world/benches/chunk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use pumpkin_world::{
1111

1212
fn bench_terrain_gen(c: &mut Criterion) {
1313
let seed = 0;
14-
let random_config = GlobalRandomConfig::new(seed, false);
14+
let random_config = GlobalRandomConfig::new(seed);
1515
let base_router = ProtoNoiseRouters::generate(&OVERWORLD_BASE_NOISE_ROUTER, &random_config);
1616
let surface_config = GenerationSettings::from_dimension(&Dimension::OVERWORLD);
1717
let terrain_cache = TerrainCache::from_random(&random_config);

pumpkin-world/benches/noise_router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::hint::black_box;
1111

1212
fn bench_noise_router_creation(c: &mut Criterion) {
1313
let base_routers = &OVERWORLD_BASE_NOISE_ROUTER;
14-
let random_config = GlobalRandomConfig::new(0, false);
14+
let random_config = GlobalRandomConfig::new(0);
1515

1616
let proto_routers = ProtoNoiseRouters::generate(base_routers, &random_config);
1717
let proto_noise_router = proto_routers.noise;

pumpkin-world/src/biome/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ mod test {
7373
#[test]
7474
fn biome_desert() {
7575
let seed = 13579;
76-
let random_config = GlobalRandomConfig::new(seed, false);
76+
let random_config = GlobalRandomConfig::new(seed);
7777
let noise_router =
7878
ProtoNoiseRouters::generate(&OVERWORLD_BASE_NOISE_ROUTER, &random_config);
7979
let multi_noise_config = MultiNoiseSamplerBuilderOptions::new(1, 1, 1);
@@ -101,7 +101,7 @@ mod test {
101101
read_data_from_file!("../../assets/biome_no_blend_no_beard_0.json");
102102

103103
let seed = 0;
104-
let random_config = GlobalRandomConfig::new(seed, false);
104+
let random_config = GlobalRandomConfig::new(seed);
105105
let noise_router =
106106
ProtoNoiseRouters::generate(&OVERWORLD_BASE_NOISE_ROUTER, &random_config);
107107
let surface_settings = GenerationSettings::from_dimension(&Dimension::OVERWORLD);

pumpkin-world/src/biome/multi_noise.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mod test {
6666
let chunk_x = 0;
6767
let chunk_z = 0;
6868

69-
let random_config = GlobalRandomConfig::new(seed, false);
69+
let random_config = GlobalRandomConfig::new(seed);
7070
let noise_router =
7171
ProtoNoiseRouters::generate(&OVERWORLD_BASE_NOISE_ROUTER, &random_config);
7272

@@ -112,7 +112,7 @@ mod test {
112112
read_data_from_file!("../../assets/multi_noise_biome_source_test.json");
113113

114114
let seed = 0;
115-
let random_config = GlobalRandomConfig::new(seed, false);
115+
let random_config = GlobalRandomConfig::new(seed);
116116
let noise_router =
117117
ProtoNoiseRouters::generate(&OVERWORLD_BASE_NOISE_ROUTER, &random_config);
118118

pumpkin-world/src/chunk_system/chunk_holder.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ use slotmap::Key;
44

55
pub struct ChunkHolder {
66
pub target_stage: StagedChunkEnum,
7+
/// Minimum stage required by generation dependencies (e.g. StructureReferences neighbors).
8+
/// May exceed `target_stage` when this chunk is needed by a neighbor's generation task
9+
/// but isn't in the player's view radius. Tasks up to this stage are scheduled but the
10+
/// chunk is not made public and is unloaded once the dependency is satisfied.
11+
pub dependency_stage: StagedChunkEnum,
712
pub current_stage: StagedChunkEnum,
813
pub chunk: Option<Chunk>,
914
pub occupied: NodeKey,
@@ -16,6 +21,7 @@ impl Default for ChunkHolder {
1621
fn default() -> Self {
1722
Self {
1823
target_stage: StagedChunkEnum::None,
24+
dependency_stage: StagedChunkEnum::None,
1925
current_stage: StagedChunkEnum::None,
2026
chunk: None,
2127
occupied: NodeKey::null(),

pumpkin-world/src/chunk_system/chunk_state.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl StagedChunkEnum {
115115
match self {
116116
Self::Empty => 0,
117117
Self::StructureStart => 0,
118-
Self::StructureReferences => 0,
118+
Self::StructureReferences => 8,
119119
Self::Biomes => 0,
120120
Self::Noise => 0,
121121
Self::Surface => 0,
@@ -131,7 +131,7 @@ impl StagedChunkEnum {
131131
match self {
132132
Self::Empty => 0,
133133
Self::StructureStart => 0,
134-
Self::StructureReferences => 0,
134+
Self::StructureReferences => 8,
135135
Self::Biomes => 0,
136136
Self::Noise => 0,
137137
Self::Surface => 0,
@@ -148,7 +148,17 @@ impl StagedChunkEnum {
148148
// the Biome Step, this should be more efficient
149149
Self::Biomes => &[Self::Empty],
150150
Self::StructureStart => &[Self::Biomes],
151-
Self::StructureReferences => &[Self::StructureStart],
151+
Self::StructureReferences => &[
152+
Self::StructureStart,
153+
Self::StructureStart,
154+
Self::StructureStart,
155+
Self::StructureStart,
156+
Self::StructureStart,
157+
Self::StructureStart,
158+
Self::StructureStart,
159+
Self::StructureStart,
160+
Self::StructureStart,
161+
],
152162
Self::Noise => &[Self::StructureReferences],
153163
Self::Surface => &[Self::Noise],
154164
Self::Features => &[Self::Surface, Self::Surface],

0 commit comments

Comments
 (0)