mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
PRNG experiments
This commit is contained in:
parent
9c9c8e6873
commit
611b55b279
@ -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)
|
.overflowing_add((wpos.x as u64).overflowing_mul(wpos.y as u64).0)
|
||||||
.0; // Awful PRNG
|
.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() {
|
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);
|
let key = (sprite, variation);
|
||||||
|
|
||||||
// NOTE: Safe because we called sprite_config_for already.
|
// NOTE: Safe because we called sprite_config_for already.
|
||||||
|
@ -2225,32 +2225,43 @@ impl Structure for House {
|
|||||||
Fill::Block(Block::air(SpriteKind::Door).with_ori(door2_ori).unwrap()),
|
Fill::Block(Block::air(SpriteKind::Door).with_ori(door2_ori).unwrap()),
|
||||||
);
|
);
|
||||||
if self.christmas_decorations {
|
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 {
|
let (door_light_pos, door_light_ori) = match self.front {
|
||||||
0 => (
|
0 => (
|
||||||
Aabb {
|
Aabb {
|
||||||
min: Vec2::new(self.door_tile.x, self.bounds.max.y + 1).with_z(alt + 3),
|
min: Vec2::new(self.door_tile.x + right, self.bounds.max.y + 1)
|
||||||
max: Vec2::new(self.door_tile.x + 1, self.bounds.max.y + 2).with_z(alt + 4),
|
.with_z(alt + 3),
|
||||||
|
max: Vec2::new(self.door_tile.x + 1 + right, self.bounds.max.y + 2)
|
||||||
|
.with_z(alt + 4),
|
||||||
},
|
},
|
||||||
4,
|
4,
|
||||||
),
|
),
|
||||||
1 => (
|
1 => (
|
||||||
Aabb {
|
Aabb {
|
||||||
min: Vec2::new(self.bounds.max.x + 1, self.door_tile.y).with_z(alt + 3),
|
min: Vec2::new(self.bounds.max.x + 1, self.door_tile.y + right)
|
||||||
max: Vec2::new(self.bounds.max.x + 2, self.door_tile.y + 1).with_z(alt + 4),
|
.with_z(alt + 3),
|
||||||
|
max: Vec2::new(self.bounds.max.x + 2, self.door_tile.y + 1 + right)
|
||||||
|
.with_z(alt + 4),
|
||||||
},
|
},
|
||||||
2,
|
2,
|
||||||
),
|
),
|
||||||
2 => (
|
2 => (
|
||||||
Aabb {
|
Aabb {
|
||||||
min: Vec2::new(self.door_tile.x, self.bounds.min.y - 1).with_z(alt + 3),
|
min: Vec2::new(self.door_tile.x + right, self.bounds.min.y - 1)
|
||||||
max: Vec2::new(self.door_tile.x + 1, self.bounds.min.y).with_z(alt + 4),
|
.with_z(alt + 3),
|
||||||
|
max: Vec2::new(self.door_tile.x + 1 + right, self.bounds.min.y)
|
||||||
|
.with_z(alt + 4),
|
||||||
},
|
},
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
_ => (
|
_ => (
|
||||||
Aabb {
|
Aabb {
|
||||||
min: Vec2::new(self.bounds.min.x - 1, self.door_tile.y).with_z(alt + 3),
|
min: Vec2::new(self.bounds.min.x - 1, self.door_tile.y + right)
|
||||||
max: Vec2::new(self.bounds.min.x, self.door_tile.y + 1).with_z(alt + 4),
|
.with_z(alt + 3),
|
||||||
|
max: Vec2::new(self.bounds.min.x, self.door_tile.y + 1 + right)
|
||||||
|
.with_z(alt + 4),
|
||||||
},
|
},
|
||||||
6,
|
6,
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user