mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Switched to UnitChooser
This commit is contained in:
parent
f08d8bb00a
commit
f14674ee9a
@ -2,7 +2,7 @@ use super::{BlockGen, StructureInfo, StructureMeta, ZCache};
|
||||
use crate::{
|
||||
all::ForestKind,
|
||||
column::{ColumnGen, ColumnSample},
|
||||
util::{HashCache, RandomPerm, Sampler},
|
||||
util::{HashCache, RandomPerm, Sampler, UnitChooser},
|
||||
CONFIG,
|
||||
};
|
||||
use common::{assets, terrain::Structure};
|
||||
@ -11,7 +11,7 @@ use std::sync::Arc;
|
||||
use vek::*;
|
||||
|
||||
static VOLUME_RAND: RandomPerm = RandomPerm::new(0xDB21C052);
|
||||
static UNIT_RAND: RandomPerm = RandomPerm::new(0x700F4EC7);
|
||||
static UNIT_CHOOSER: UnitChooser = UnitChooser::new(0x700F4EC7);
|
||||
static QUIRKY_RAND: RandomPerm = RandomPerm::new(0xA634460F);
|
||||
|
||||
pub fn structure_gen<'a>(
|
||||
@ -61,22 +61,11 @@ pub fn structure_gen<'a>(
|
||||
}
|
||||
};
|
||||
|
||||
const UNIT_CHOICES: [(Vec2<i32>, Vec2<i32>); 8] = [
|
||||
(Vec2 { x: 1, y: 0 }, Vec2 { x: 0, y: 1 }),
|
||||
(Vec2 { x: 1, y: 0 }, Vec2 { x: 0, y: -1 }),
|
||||
(Vec2 { x: -1, y: 0 }, Vec2 { x: 0, y: 1 }),
|
||||
(Vec2 { x: -1, y: 0 }, Vec2 { x: 0, y: -1 }),
|
||||
(Vec2 { x: 0, y: 1 }, Vec2 { x: 1, y: 0 }),
|
||||
(Vec2 { x: 0, y: 1 }, Vec2 { x: -1, y: 0 }),
|
||||
(Vec2 { x: 0, y: -1 }, Vec2 { x: 1, y: 0 }),
|
||||
(Vec2 { x: 0, y: -1 }, Vec2 { x: -1, y: 0 }),
|
||||
];
|
||||
|
||||
Some(StructureInfo {
|
||||
pos: st_pos3d,
|
||||
seed: st_seed,
|
||||
meta: StructureMeta::Volume {
|
||||
units: UNIT_CHOICES[UNIT_RAND.get(st_seed) as usize % UNIT_CHOICES.len()],
|
||||
units: UNIT_CHOOSER.get(st_seed),
|
||||
volume: &volumes[(VOLUME_RAND.get(st_seed) / 13) as usize % volumes.len()],
|
||||
},
|
||||
})
|
||||
|
@ -2,7 +2,7 @@ use crate::{
|
||||
all::ForestKind,
|
||||
block::StructureMeta,
|
||||
sim::{LocationInfo, SimChunk},
|
||||
util::Sampler,
|
||||
util::{Sampler, UnitChooser},
|
||||
World, CONFIG,
|
||||
};
|
||||
use common::{
|
||||
@ -23,6 +23,8 @@ pub struct ColumnGen<'a> {
|
||||
world: &'a World,
|
||||
}
|
||||
|
||||
static UNIT_CHOOSER: UnitChooser = UnitChooser::new(0x700F4EC7);
|
||||
|
||||
lazy_static! {
|
||||
pub static ref DUNGEONS: Vec<Arc<Structure>> = vec![
|
||||
// green oaks
|
||||
@ -65,7 +67,7 @@ impl<'a> ColumnGen<'a> {
|
||||
pos,
|
||||
seed,
|
||||
meta: Some(StructureMeta::Volume {
|
||||
units: (Vec2::unit_x(), Vec2::unit_y()),
|
||||
units: UNIT_CHOOSER.get(seed),
|
||||
volume: &DUNGEONS[0],
|
||||
}),
|
||||
})
|
||||
|
@ -2,6 +2,7 @@ pub mod hash_cache;
|
||||
pub mod random;
|
||||
pub mod sampler;
|
||||
pub mod structure;
|
||||
pub mod unit_chooser;
|
||||
|
||||
// Reexports
|
||||
pub use self::{
|
||||
@ -9,4 +10,5 @@ pub use self::{
|
||||
random::{RandomField, RandomPerm},
|
||||
sampler::{Sampler, SamplerMut},
|
||||
structure::StructureGen2d,
|
||||
unit_chooser::UnitChooser,
|
||||
};
|
||||
|
34
world/src/util/unit_chooser.rs
Normal file
34
world/src/util/unit_chooser.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use super::{RandomPerm, Sampler};
|
||||
use vek::*;
|
||||
|
||||
const UNIT_CHOICES: [(Vec2<i32>, Vec2<i32>); 8] = [
|
||||
(Vec2 { x: 1, y: 0 }, Vec2 { x: 0, y: 1 }),
|
||||
(Vec2 { x: 1, y: 0 }, Vec2 { x: 0, y: -1 }),
|
||||
(Vec2 { x: -1, y: 0 }, Vec2 { x: 0, y: 1 }),
|
||||
(Vec2 { x: -1, y: 0 }, Vec2 { x: 0, y: -1 }),
|
||||
(Vec2 { x: 0, y: 1 }, Vec2 { x: 1, y: 0 }),
|
||||
(Vec2 { x: 0, y: 1 }, Vec2 { x: -1, y: 0 }),
|
||||
(Vec2 { x: 0, y: -1 }, Vec2 { x: 1, y: 0 }),
|
||||
(Vec2 { x: 0, y: -1 }, Vec2 { x: -1, y: 0 }),
|
||||
];
|
||||
|
||||
pub struct UnitChooser {
|
||||
perm: RandomPerm,
|
||||
}
|
||||
|
||||
impl UnitChooser {
|
||||
pub const fn new(seed: u32) -> Self {
|
||||
Self {
|
||||
perm: RandomPerm::new(seed),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Sampler for UnitChooser {
|
||||
type Index = u32;
|
||||
type Sample = (Vec2<i32>, Vec2<i32>);
|
||||
|
||||
fn get(&self, perm: Self::Index) -> Self::Sample {
|
||||
UNIT_CHOICES[self.perm.get(perm) as usize % UNIT_CHOICES.len()]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user