-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,55 @@ | ||
use std::sync::LazyLock; | ||
use std::{cell::RefCell, sync::LazyLock}; | ||
|
||
use enum_dispatch::enum_dispatch; | ||
use multi_noise::{BiomeEntries, SearchTree}; | ||
use multi_noise::{BiomeEntries, SearchTree, TreeLeafNode}; | ||
use pumpkin_data::chunk::Biome; | ||
mod multi_noise; | ||
|
||
use crate::{ | ||
coordinates::BlockCoordinates, generation::noise_router::multi_noise_sampler::MultiNoiseSampler, | ||
}; | ||
pub mod multi_noise; | ||
|
||
pub static BIOME_ENTRIES: LazyLock<SearchTree<Biome>> = LazyLock::new(|| { | ||
SearchTree::create( | ||
serde_json::from_str::<BiomeEntries>(include_str!("../../../assets/multi_noise.json")) | ||
.expect("Could not parse synced_registries.json registry.") | ||
.nodes, | ||
.expect("Could not parse multi_noise.json.") | ||
.nodes | ||
.into_iter() | ||
.flat_map(|(_, biome_map)| biome_map.into_iter()) | ||
.collect(), | ||
) | ||
.expect("entries cannot be empty") | ||
}); | ||
|
||
thread_local! { | ||
static LAST_RESULT_NODE: RefCell<Option<TreeLeafNode<Biome>>> = RefCell::new(None); | ||
} | ||
|
||
#[enum_dispatch] | ||
pub trait BiomeSupplier { | ||
fn biome(&self, x: i32, y: i32, z: i32, noise: &MultiNoiseSampler) -> Biome; | ||
fn biome(&mut self, at: BlockCoordinates) -> Biome; | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct DebugBiomeSupplier {} | ||
pub struct DebugBiomeSupplier; | ||
|
||
impl BiomeSupplier for DebugBiomeSupplier { | ||
fn biome(&self, _x: i32, _y: i32, _z: i32, _noise: &MultiNoiseSampler) -> Biome { | ||
fn biome(&mut self, _at: BlockCoordinates) -> Biome { | ||
Biome::Plains | ||
} | ||
} | ||
|
||
// TODO: Implement | ||
pub struct MultiNoiseSampler {} | ||
pub struct MultiNoiseBiomeSupplier<'a> { | ||
noise: MultiNoiseSampler<'a>, | ||
} | ||
|
||
impl BiomeSupplier for MultiNoiseBiomeSupplier<'_> { | ||
fn biome(&mut self, at: BlockCoordinates) -> Biome { | ||
let point = self.noise.sample(at.x, at.y.0 as i32, at.z); | ||
LAST_RESULT_NODE.with_borrow_mut(|last_result| { | ||
BIOME_ENTRIES | ||
.get(&point, last_result) | ||
.expect("failed to get biome entry") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters