switch libs

This commit is contained in:
griffi-gh 2024-05-02 18:15:18 +02:00
parent b6c314e8f3
commit 56fe70765f
6 changed files with 75 additions and 70 deletions

44
Cargo.lock generated
View file

@ -236,30 +236,6 @@ dependencies = [
"objc2", "objc2",
] ]
[[package]]
name = "bracket-noise"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0b7443d0990c69db7a83f376f0101d684c20a911698e5f932bffbda2c8b08dd"
dependencies = [
"bracket-random",
]
[[package]]
name = "bracket-random"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "437be61484077b1ddb57002ce3c96b7d03cbf500b5d15157ee7e67e22332c39b"
dependencies = [
"getrandom",
"js-sys",
"lazy_static",
"rand",
"rand_xorshift",
"regex",
"wasm-bindgen",
]
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.16.0" version = "3.16.0"
@ -633,6 +609,15 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "fastnoise-lite"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e5f3c3cc9081e5d0e18bcd50e80cd33cba47fc22f88a9da9c33ecd1c87ea5c0"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "fdeflate" name = "fdeflate"
version = "0.3.4" version = "0.3.4"
@ -1243,8 +1228,8 @@ dependencies = [
"anyhow", "anyhow",
"atomic", "atomic",
"bincode", "bincode",
"bracket-noise",
"bytemuck", "bytemuck",
"fastnoise-lite",
"glam", "glam",
"hashbrown 0.14.3", "hashbrown 0.14.3",
"nohash-hasher", "nohash-hasher",
@ -1688,15 +1673,6 @@ dependencies = [
"getrandom", "getrandom",
] ]
[[package]]
name = "rand_xorshift"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
dependencies = [
"rand_core",
]
[[package]] [[package]]
name = "rand_xoshiro" name = "rand_xoshiro"
version = "0.6.0" version = "0.6.0"

View file

@ -14,7 +14,7 @@ serde = { version = "1.0", default-features = false, features = ["alloc", "deriv
serde_with = "3.4" serde_with = "3.4"
bincode = "1.3" bincode = "1.3"
anyhow = "1.0" anyhow = "1.0"
bracket-noise = "0.8" fastnoise-lite = { version = "1.1", features = ["std", "f64"] }
rand = { version = "0.8", default_features = false, features = ["std", "min_const_gen"] } rand = { version = "0.8", default_features = false, features = ["std", "min_const_gen"] }
rand_xoshiro = "0.6" rand_xoshiro = "0.6"
hashbrown = { version = "0.14", features = ["serde"] } hashbrown = { version = "0.14", features = ["serde"] }

View file

@ -23,6 +23,31 @@ pub enum AbortState {
} }
const_assert!(Atomic::<AbortState>::is_lock_free()); const_assert!(Atomic::<AbortState>::is_lock_free());
pub struct SeedThingy {
pseed: u64,
iseed: i32,
iter: u8,
}
impl SeedThingy {
pub fn new(seed: u64) -> Self {
Self {
pseed: seed,
iseed: (seed & 0x7fffffffu64) as i32,
iter: 0,
}
}
pub fn next_seed(&mut self) -> i32 {
self.iter += 1;
self.iseed = (
self.pseed
.rotate_left((3 * self.iter) as _)
& 0x7fffffff
) as i32;
self.iseed
}
}
trait WorldGenStep { trait WorldGenStep {
fn initialize(generator: &WorldGenerator) -> Self; fn initialize(generator: &WorldGenerator) -> Self;
fn generate(&mut self, generator: &mut WorldGenerator); fn generate(&mut self, generator: &mut WorldGenerator);

View file

@ -1,18 +1,19 @@
use bracket_noise::prelude::{FastNoise, FractalType}; use fastnoise_lite::{FastNoiseLite, FractalType};
use glam::ivec3; use glam::ivec3;
use crate::{block::Block, chunk::CHUNK_SIZE}; use crate::{block::Block, chunk::CHUNK_SIZE};
use super::{WorldGenerator, WorldGenStep}; use super::{SeedThingy, WorldGenStep, WorldGenerator};
pub struct TerrainStep { pub struct TerrainStep {
noise: FastNoise, noise: FastNoiseLite,
} }
impl WorldGenStep for TerrainStep { impl WorldGenStep for TerrainStep {
fn initialize(generator: &WorldGenerator) -> Self { fn initialize(generator: &WorldGenerator) -> Self {
let mut noise = FastNoise::seeded(generator.seed); let mut seeder = SeedThingy::new(generator.seed);
noise.set_fractal_type(FractalType::RigidMulti); let mut noise = FastNoiseLite::with_seed(seeder.next_seed());
noise.set_fractal_octaves(5); noise.set_fractal_type(Some(FractalType::FBm));
noise.set_frequency(0.003); noise.set_fractal_octaves(Some(4));
noise.set_frequency(Some(0.003));
Self { noise } Self { noise }
} }
@ -20,7 +21,7 @@ impl WorldGenStep for TerrainStep {
for x in 0..CHUNK_SIZE as i32 { for x in 0..CHUNK_SIZE as i32 {
for z in 0..CHUNK_SIZE as i32 { for z in 0..CHUNK_SIZE as i32 {
let global_xz = gen.global_position(ivec3(x, 0, z)); let global_xz = gen.global_position(ivec3(x, 0, z));
let height = (self.noise.get_noise(global_xz.x as f32, global_xz.z as f32) * 32.0) as i32; let height = (self.noise.get_noise_2d(global_xz.x as f64, global_xz.z as f64) * 32.0) as i32;
for y in 0..gen.local_height(height) { for y in 0..gen.local_height(height) {
gen.place(ivec3(x, y, z), Block::Stone); gen.place(ivec3(x, y, z), Block::Stone);
} }

View file

@ -1,4 +1,3 @@
use bracket_noise::prelude::{FastNoise, FractalType};
use glam::ivec3; use glam::ivec3;
use crate::{block::Block, chunk::CHUNK_SIZE}; use crate::{block::Block, chunk::CHUNK_SIZE};
use super::{WorldGenerator, WorldGenStep}; use super::{WorldGenerator, WorldGenStep};

View file

@ -1,42 +1,46 @@
use bracket_noise::prelude::{FastNoise, FractalType};
use fastnoise_lite::{FastNoiseLite, FractalType};
use glam::{ivec3, IVec3}; use glam::{ivec3, IVec3};
use crate::{block::Block, chunk::CHUNK_SIZE}; use crate::{block::Block, chunk::CHUNK_SIZE};
use super::{WorldGenStep, WorldGenerator}; use super::{SeedThingy, WorldGenStep, WorldGenerator};
pub struct CaveStep { pub struct CaveStep {
a: FastNoise, a: FastNoiseLite,
b: FastNoise, b: FastNoiseLite,
} }
impl WorldGenStep for CaveStep { impl WorldGenStep for CaveStep {
fn initialize(gen: &WorldGenerator) -> Self { fn initialize(gen: &WorldGenerator) -> Self {
let mut a = FastNoise::seeded(gen.seed); let mut seeder = SeedThingy::new(gen.seed);
a.set_fractal_type(FractalType::FBM);
a.set_frequency(0.015);
let mut b = FastNoise::seeded(gen.seed.rotate_left(1) + 1); let mut a = FastNoiseLite::with_seed(seeder.next_seed());
b.set_fractal_type(FractalType::FBM); a.set_fractal_type(Some(FractalType::FBm));
b.set_frequency(0.015); a.set_fractal_octaves(Some(2));
let mut b = FastNoiseLite::with_seed(seeder.next_seed());
b.set_fractal_type(Some(FractalType::FBm));
b.set_fractal_octaves(Some(2));
Self { a, b } Self { a, b }
} }
fn generate(&mut self, gen: &mut WorldGenerator) { fn generate(&mut self, gen: &mut WorldGenerator) {
for x in 0..CHUNK_SIZE as i32 { //TODO
for z in 0..CHUNK_SIZE as i32 {
for y in 0..CHUNK_SIZE as i32 {
let pos: IVec3 = ivec3(x, y, z);
if gen.query(pos) != Block::Stone { continue }
let gpos = gen.global_position(pos); // for x in 0..CHUNK_SIZE as i32 {
let noise_a = self.a.get_noise3d(gpos.x as f32, gpos.y as f32, gpos.z as f32); // for y in 0..CHUNK_SIZE as i32 {
let noise_b = self.b.get_noise3d(gpos.x as f32, gpos.y as f32, gpos.z as f32); // for z in 0..CHUNK_SIZE as i32 {
let noise_min = noise_a.min(noise_b); // let pos = ivec3(x, y, z);
// if gen.query(pos) != Block::Stone { continue }
if noise_min > 0.5 { return } // let pos_global = gen.global_position(pos);
// let noise_a = self.a.get_noise_3d(pos_global.x as f64, pos_global.y as f64, pos_global.z as f64) * 0.5 + 0.5;
//gen.place(ivec3(x, y, z), Block::Air); // let noise_b = self.b.get_noise_3d(pos_global.x as f64, pos_global.y as f64, pos_global.z as f64) * 0.5 + 0.5;
} // if noise_a.min(noise_b) > (1. - (-y as f32 / 400.).clamp(0., 1.)) {
} // gen.place(pos, Block::Air);
} // }
// //TODO
// }
// }
// }
} }
} }