mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-21 14:28:43 -06:00
use single seeder instance
This commit is contained in:
parent
048e45628a
commit
8f606b77c0
|
@ -48,7 +48,7 @@ impl SeedThingy {
|
|||
}
|
||||
}
|
||||
trait WorldGenStep {
|
||||
fn initialize(generator: &WorldGenerator) -> Self;
|
||||
fn initialize(generator: &WorldGenerator, seeder: &mut SeedThingy) -> Self;
|
||||
fn generate(&mut self, generator: &mut WorldGenerator);
|
||||
}
|
||||
|
||||
|
@ -67,11 +67,12 @@ macro_rules! run_steps {
|
|||
|
||||
if _chkabt() { return false }
|
||||
|
||||
let mut _seeder = $crate::worldgen::SeedThingy::new($gen.seed);
|
||||
$({
|
||||
let _ensure_ref: &mut $crate::worldgen::WorldGenerator = $gen;
|
||||
struct _Ensure0<T: $crate::worldgen::WorldGenStep>(T);
|
||||
type _Ensure1 = _Ensure0<$step>;
|
||||
let mut step: _Ensure1 = _Ensure0(<$step>::initialize(&*_ensure_ref));
|
||||
let mut step: _Ensure1 = _Ensure0(<$step>::initialize(&*_ensure_ref, &mut _seeder));
|
||||
if _chkabt() { return false }
|
||||
step.0.generate(_ensure_ref);
|
||||
if _chkabt() { return false }
|
||||
|
|
|
@ -8,8 +8,7 @@ pub struct TerrainStep {
|
|||
}
|
||||
|
||||
impl WorldGenStep for TerrainStep {
|
||||
fn initialize(generator: &WorldGenerator) -> Self {
|
||||
let mut seeder = SeedThingy::new(generator.seed);
|
||||
fn initialize(_: &WorldGenerator, seeder: &mut SeedThingy) -> Self {
|
||||
let mut noise = FastNoiseLite::with_seed(seeder.next_seed());
|
||||
noise.set_fractal_type(Some(FractalType::FBm));
|
||||
noise.set_fractal_octaves(Some(4));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use glam::ivec3;
|
||||
use crate::{block::Block, chunk::CHUNK_SIZE};
|
||||
use crate::{block::Block, chunk::CHUNK_SIZE, worldgen::SeedThingy};
|
||||
use super::super::{WorldGenerator, WorldGenStep};
|
||||
|
||||
pub const WATER_LEVEL: i32 = 0;
|
||||
|
@ -7,7 +7,7 @@ pub const WATER_LEVEL: i32 = 0;
|
|||
pub struct WaterStep;
|
||||
|
||||
impl WorldGenStep for WaterStep {
|
||||
fn initialize(_: &WorldGenerator) -> Self { Self }
|
||||
fn initialize(_: &WorldGenerator, _: &mut SeedThingy) -> Self { Self }
|
||||
fn generate(&mut self, gen: &mut WorldGenerator) {
|
||||
for x in 0..CHUNK_SIZE as i32 {
|
||||
for z in 0..CHUNK_SIZE as i32 {
|
||||
|
|
|
@ -9,9 +9,7 @@ pub struct CaveStep {
|
|||
}
|
||||
|
||||
impl WorldGenStep for CaveStep {
|
||||
fn initialize(gen: &WorldGenerator) -> Self {
|
||||
let mut seeder = SeedThingy::new(gen.seed);
|
||||
|
||||
fn initialize(_: &WorldGenerator, seeder: &mut SeedThingy) -> Self {
|
||||
let mut a = FastNoiseLite::with_seed(seeder.next_seed());
|
||||
a.set_fractal_type(Some(FractalType::FBm));
|
||||
a.set_fractal_octaves(Some(2));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use fastnoise_lite::FastNoiseLite;
|
||||
use glam::ivec3;
|
||||
use crate::{block::Block, chunk::CHUNK_SIZE};
|
||||
use crate::{block::Block, chunk::CHUNK_SIZE, worldgen::SeedThingy};
|
||||
use super::{
|
||||
_02_water::WATER_LEVEL,
|
||||
super::{WorldGenStep, WorldGenerator}
|
||||
|
@ -8,7 +9,7 @@ use super::{
|
|||
pub struct LayersStep;
|
||||
|
||||
impl WorldGenStep for LayersStep {
|
||||
fn initialize(_: &WorldGenerator) -> Self { Self }
|
||||
fn initialize(_: &WorldGenerator, _: &mut SeedThingy) -> Self { Self }
|
||||
|
||||
fn generate(&mut self, gen: &mut WorldGenerator) {
|
||||
for x in 0..CHUNK_SIZE as i32 {
|
||||
|
@ -17,7 +18,7 @@ impl WorldGenStep for LayersStep {
|
|||
|
||||
// Dirt layer height, naturally gets thinner as height gets deeper
|
||||
let mut dirt_layer_height = (((terrain_height as f32 + 15.) / 20.).clamp(0., 1.) * 8.).round() as i32;
|
||||
dirt_layer_height -= (gen.seeded_hash((x, z, 1)) & 1) as i32; //+ (gen.seeded_hash((x, z, 0xbau8)) & 1) as i32;
|
||||
dirt_layer_height -= (gen.seeded_hash((x, z, 0x040)) & 1) as i32; //+ (gen.seeded_hash((x, z, 0x041)) & 1) as i32;
|
||||
|
||||
// Place dirt layer
|
||||
for y in gen.local_height(terrain_height - dirt_layer_height)..gen.local_height(terrain_height) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use glam::ivec3;
|
||||
use crate::{block::Block, chunk::CHUNK_SIZE};
|
||||
use crate::{block::Block, chunk::CHUNK_SIZE, worldgen::SeedThingy};
|
||||
use super::{
|
||||
_02_water::WATER_LEVEL,
|
||||
super::{WorldGenStep, WorldGenerator},
|
||||
|
@ -8,7 +8,7 @@ use super::{
|
|||
pub struct DecorateStep;
|
||||
|
||||
impl WorldGenStep for DecorateStep {
|
||||
fn initialize(_: &WorldGenerator) -> Self { Self }
|
||||
fn initialize(_: &WorldGenerator, _: &mut SeedThingy) -> Self { Self }
|
||||
|
||||
fn generate(&mut self, gen: &mut WorldGenerator) {
|
||||
for x in 0..CHUNK_SIZE as i32 {
|
||||
|
@ -20,7 +20,7 @@ impl WorldGenStep for DecorateStep {
|
|||
//Place tall grass
|
||||
if terrain_height >= WATER_LEVEL {
|
||||
if let Some(local_y) = gen.local_y_position(terrain_height) {
|
||||
if (gen.seeded_hash((global_xz.x, global_xz.z)) & 0xf) == 0xf {
|
||||
if (gen.seeded_hash((global_xz.x, global_xz.z, 0x050)) & 0xf) == 0xf {
|
||||
gen.place_if_empty(ivec3(x, local_y, z), Block::TallGrass);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,7 @@ pub struct TreesStep {
|
|||
}
|
||||
|
||||
impl WorldGenStep for TreesStep {
|
||||
fn initialize(gen: &WorldGenerator) -> Self {
|
||||
let mut seeder = SeedThingy::new(gen.seed.rotate_left(5));
|
||||
fn initialize(_: &WorldGenerator, seeder: &mut SeedThingy) -> Self {
|
||||
let mut density_noise = FastNoiseLite::with_seed(seeder.next_seed());
|
||||
density_noise.set_noise_type(Some(NoiseType::OpenSimplex2));
|
||||
density_noise.set_frequency(Some(0.008));
|
||||
|
@ -30,7 +29,7 @@ impl WorldGenStep for TreesStep {
|
|||
let global_xz = gen.global_position(ivec3(x, 0, z));
|
||||
let mut density = self.density_noise.get_noise_2d(global_xz.x as f64, global_xz.z as f64) * 0.5 + 0.5;
|
||||
density = density.powi(3);
|
||||
if gen.seeded_hash((global_xz.x, global_xz.z, 0xfef)) & 0xff >= (density * 7.).round() as u64 {
|
||||
if gen.seeded_hash((global_xz.x, global_xz.z, 0x060)) & 0xff >= (density * 7.).round() as u64 {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue