Skip to content

Commit 826f951

Browse files
committed
tweaks
1 parent 1e3bd7b commit 826f951

File tree

3 files changed

+42
-45
lines changed

3 files changed

+42
-45
lines changed

pumpkin-world/src/generation/aquifer_sampler.rs

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -201,31 +201,26 @@ impl WorldAquiferSampler {
201201
// y values are contiguous in packed array:
202202
// ($local_x * $dim_z + $local_z) * $dim_y + $local_y
203203

204-
// (x, y - 1, z)
205-
let x_0_z_0 = self.packed_position_index(x, y - 1, z);
206-
207-
// (x, y - 1, z + 1)
208-
let x_0_z_1 = x_0_z_0 + self.size_y;
209-
210-
// (x + 1, y - 1, z)
211-
let x_1_z_0 = x_0_z_0 + self.size_y * self.size_z;
212-
213-
// (x + 1, y - 1, z + 1)
214-
let x_1_z_1 = x_1_z_0 + self.size_y;
204+
let x0z0_index = self.packed_position_index(x, y - 1, z);
205+
let x0z1_index = x0z0_index + self.size_y;
206+
let x1z0_index = x0z0_index + self.size_y * self.size_z;
207+
let x1z1_index = x1z0_index + self.size_y;
208+
// Remove bounds checks on subsequent indexs
209+
assert!(x1z1_index + 2 < self.packed_positions.len());
215210

216211
[
217-
self.packed_positions[x_0_z_0],
218-
self.packed_positions[x_0_z_1],
219-
self.packed_positions[x_1_z_0],
220-
self.packed_positions[x_1_z_1],
221-
self.packed_positions[x_0_z_0 + 1],
222-
self.packed_positions[x_0_z_1 + 1],
223-
self.packed_positions[x_1_z_0 + 1],
224-
self.packed_positions[x_1_z_1 + 1],
225-
self.packed_positions[x_0_z_0 + 2],
226-
self.packed_positions[x_0_z_1 + 2],
227-
self.packed_positions[x_1_z_0 + 2],
228-
self.packed_positions[x_1_z_1 + 2],
212+
self.packed_positions[x1z1_index + 2],
213+
self.packed_positions[x1z0_index + 2],
214+
self.packed_positions[x0z1_index + 2],
215+
self.packed_positions[x0z0_index + 2],
216+
self.packed_positions[x1z1_index + 1],
217+
self.packed_positions[x1z0_index + 1],
218+
self.packed_positions[x0z1_index + 1],
219+
self.packed_positions[x0z0_index + 1],
220+
self.packed_positions[x1z1_index],
221+
self.packed_positions[x1z0_index],
222+
self.packed_positions[x0z1_index],
223+
self.packed_positions[x0z0_index],
229224
]
230225
}
231226

@@ -500,8 +495,7 @@ impl WorldAquiferSampler {
500495
let scaled_y = local_y!(sample_y + 1);
501496
let scaled_z = local_xz!(sample_z - 5);
502497

503-
// The 3 closest positions, closest to furthest
504-
let mut packed_block_and_hypots = [(0, i32::MAX); 3];
498+
let mut random_positions_and_hypot = [(0, i32::MAX); 3];
505499
for packed_random in self.random_positions_for_pos(scaled_x, scaled_y, scaled_z) {
506500
let unpacked_x = block_pos::unpack_x(packed_random);
507501
let unpacked_y = block_pos::unpack_y(packed_random);
@@ -513,29 +507,31 @@ impl WorldAquiferSampler {
513507

514508
let hypot_squared = local_x * local_x + local_y * local_y + local_z * local_z;
515509

516-
if packed_block_and_hypots[2].1 >= hypot_squared {
517-
packed_block_and_hypots[2] = (packed_random, hypot_squared);
510+
if random_positions_and_hypot[2].1 > hypot_squared {
511+
random_positions_and_hypot[2] = (packed_random, hypot_squared);
518512
}
519513

520-
if packed_block_and_hypots[1].1 >= hypot_squared {
521-
packed_block_and_hypots[2] = packed_block_and_hypots[1];
522-
packed_block_and_hypots[1] = (packed_random, hypot_squared);
514+
if random_positions_and_hypot[1].1 > hypot_squared {
515+
random_positions_and_hypot[2] = random_positions_and_hypot[1];
516+
random_positions_and_hypot[1] = (packed_random, hypot_squared);
523517
}
524518

525-
if packed_block_and_hypots[0].1 >= hypot_squared {
526-
packed_block_and_hypots[1] = packed_block_and_hypots[0];
527-
packed_block_and_hypots[0] = (packed_random, hypot_squared);
519+
if random_positions_and_hypot[0].1 > hypot_squared {
520+
random_positions_and_hypot[1] = random_positions_and_hypot[0];
521+
random_positions_and_hypot[0] = (packed_random, hypot_squared);
528522
}
529523
}
530524

531525
let fluid_level2 = self.get_water_level(
532-
packed_block_and_hypots[0].0,
526+
random_positions_and_hypot[0].0,
533527
router,
534528
height_estimator,
535529
sample_options,
536530
);
537-
let d =
538-
Self::max_distance(packed_block_and_hypots[0].1, packed_block_and_hypots[1].1);
531+
let d = Self::max_distance(
532+
random_positions_and_hypot[0].1,
533+
random_positions_and_hypot[1].1,
534+
);
539535
let block_state = fluid_level2.get_block(sample_y);
540536

541537
if d <= 0f64 {
@@ -553,7 +549,7 @@ impl WorldAquiferSampler {
553549
} else {
554550
let mut barrier_sample = None;
555551
let fluid_level3 = self.get_water_level(
556-
packed_block_and_hypots[1].0,
552+
random_positions_and_hypot[1].0,
557553
router,
558554
height_estimator,
559555
sample_options,
@@ -571,14 +567,14 @@ impl WorldAquiferSampler {
571567
None
572568
} else {
573569
let fluid_level4 = self.get_water_level(
574-
packed_block_and_hypots[2].0,
570+
random_positions_and_hypot[2].0,
575571
router,
576572
height_estimator,
577573
sample_options,
578574
);
579575
let f = Self::max_distance(
580-
packed_block_and_hypots[0].1,
581-
packed_block_and_hypots[2].1,
576+
random_positions_and_hypot[0].1,
577+
random_positions_and_hypot[2].1,
582578
);
583579
if f > 0f64 {
584580
let g = d
@@ -597,8 +593,8 @@ impl WorldAquiferSampler {
597593
}
598594

599595
let g = Self::max_distance(
600-
packed_block_and_hypots[1].1,
601-
packed_block_and_hypots[2].1,
596+
random_positions_and_hypot[1].1,
597+
random_positions_and_hypot[2].1,
602598
);
603599
if g > 0f64 {
604600
let h = d
@@ -685,7 +681,7 @@ pub trait AquiferSamplerImpl {
685681
}
686682

687683
#[cfg(test)]
688-
mod test {
684+
mod random_positions_and_hypot {
689685
use std::{mem, sync::LazyLock};
690686

691687
use pumpkin_data::noise_router::OVERWORLD_BASE_NOISE_ROUTER;

pumpkin-world/src/generation/biome.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn score_permutation(
134134

135135
#[inline]
136136
fn scale_mix(l: i64) -> f64 {
137-
let d = floor_mod(l >> 24, 1024i32 as i64) as i32 as f64 / 1024.0;
137+
let d = floor_mod(l >> 24, 1024i64) as i32 as f64 / 1024.0;
138138

139139
(d - 0.5) * 0.9
140140
}

pumpkin-world/src/generation/proto_chunk.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ impl<'a> ProtoChunk<'a> {
579579
}
580580

581581
pub fn get_biome_for_terrain_gen(&self, global_block_pos: &Vector3<i32>) -> &'static Biome {
582+
// TODO: See if we can cache this value
582583
let seed_biome_pos = biome::get_biome_blend(
583584
self.bottom_y(),
584585
self.height(),
@@ -628,8 +629,8 @@ impl<'a> ProtoChunk<'a> {
628629
self.terrain_cache
629630
.terrain_builder
630631
.place_badlands_pillar(self, x, z, top_block);
631-
// Get the top block again if we placed a pillar!
632632

633+
// Get the top block again if we placed a pillar!
633634
top_block = self.top_block_height_exclusive(&Vector2::new(local_x, local_z));
634635
}
635636

0 commit comments

Comments
 (0)