From 611b55b2790d75bf9c706c1f5dca577f6ada253f Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Fri, 15 Dec 2023 17:27:15 +0100 Subject: [PATCH] PRNG experiments --- voxygen/src/scene/terrain.rs | 16 ++++++++++++++-- world/src/site2/plot/house.rs | 27 +++++++++++++++++++-------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 7a7ebd0a00..720edd1686 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -270,9 +270,21 @@ pub fn get_sprite_instances<'a, I: 'a>( .overflowing_add((wpos.x as u64).overflowing_mul(wpos.y as u64).0) .0; // Awful PRNG - let ori = (block.get_ori().unwrap_or((seed % 4) as u8 * 2)) & 0b111; + // % 4 is non uniform, take 7 and combine two where >0 + let ori = (block.get_ori().unwrap_or((((seed % 7) + 1) / 2) as u8 * 2)) & 0b111; if !cfg.variations.is_empty() { - let variation = seed as usize % cfg.variations.len(); + let variation = match cfg.variations.len() { + // try to make the variation more uniform as the PRNG is unfair + 1 => 0, + 2 => (seed as usize % 4) / 3, + 3 => (seed as usize % 5) / 2, + 4 => ((seed as usize % 7) + 1) / 2, + _ => seed as usize % cfg.variations.len(), + }; + // let variation = seed as usize % cfg.variations.len(); + if sprite == SpriteKind::ChristmasOrnament { + println!("{sprite:?} {variation} {wpos:?} {seed}"); + } let key = (sprite, variation); // NOTE: Safe because we called sprite_config_for already. diff --git a/world/src/site2/plot/house.rs b/world/src/site2/plot/house.rs index cf6594bb0c..4d126cad2f 100644 --- a/world/src/site2/plot/house.rs +++ b/world/src/site2/plot/house.rs @@ -2225,32 +2225,43 @@ impl Structure for House { Fill::Block(Block::air(SpriteKind::Door).with_ori(door2_ori).unwrap()), ); if self.christmas_decorations { + // we need to randomize position to see both variants + let rng = RandomField::new(0).get(self.door_tile.with_z(alt + 3)); + let right = (rng % 2) as i32; let (door_light_pos, door_light_ori) = match self.front { 0 => ( Aabb { - min: Vec2::new(self.door_tile.x, self.bounds.max.y + 1).with_z(alt + 3), - max: Vec2::new(self.door_tile.x + 1, self.bounds.max.y + 2).with_z(alt + 4), + min: Vec2::new(self.door_tile.x + right, self.bounds.max.y + 1) + .with_z(alt + 3), + max: Vec2::new(self.door_tile.x + 1 + right, self.bounds.max.y + 2) + .with_z(alt + 4), }, 4, ), 1 => ( Aabb { - min: Vec2::new(self.bounds.max.x + 1, self.door_tile.y).with_z(alt + 3), - max: Vec2::new(self.bounds.max.x + 2, self.door_tile.y + 1).with_z(alt + 4), + min: Vec2::new(self.bounds.max.x + 1, self.door_tile.y + right) + .with_z(alt + 3), + max: Vec2::new(self.bounds.max.x + 2, self.door_tile.y + 1 + right) + .with_z(alt + 4), }, 2, ), 2 => ( Aabb { - min: Vec2::new(self.door_tile.x, self.bounds.min.y - 1).with_z(alt + 3), - max: Vec2::new(self.door_tile.x + 1, self.bounds.min.y).with_z(alt + 4), + min: Vec2::new(self.door_tile.x + right, self.bounds.min.y - 1) + .with_z(alt + 3), + max: Vec2::new(self.door_tile.x + 1 + right, self.bounds.min.y) + .with_z(alt + 4), }, 0, ), _ => ( Aabb { - min: Vec2::new(self.bounds.min.x - 1, self.door_tile.y).with_z(alt + 3), - max: Vec2::new(self.bounds.min.x, self.door_tile.y + 1).with_z(alt + 4), + min: Vec2::new(self.bounds.min.x - 1, self.door_tile.y + right) + .with_z(alt + 3), + max: Vec2::new(self.bounds.min.x, self.door_tile.y + 1 + right) + .with_z(alt + 4), }, 6, ),