PRNG experiments

This commit is contained in:
Christof Petig 2023-12-15 17:27:15 +01:00
parent 9c9c8e6873
commit 611b55b279
2 changed files with 33 additions and 10 deletions

View File

@ -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.

View File

@ -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,
),