diff options
| author | mat <git@matdoes.dev> | 2023-09-17 21:44:17 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-09-17 21:44:17 -0500 |
| commit | 856a3252f693421df519cbc4d9bc03cfc0f0c212 (patch) | |
| tree | 310cffa9d9c09a4651ab1707899ae20416713fc0 /azalea-core | |
| parent | 61e63c08968f7b0f451c4c3b07ea8d4927b14a2f (diff) | |
| download | azalea-drasl-856a3252f693421df519cbc4d9bc03cfc0f0c212.tar.xz | |
heightmaps
Diffstat (limited to 'azalea-core')
| -rw-r--r-- | azalea-core/src/math.rs | 20 | ||||
| -rwxr-xr-x | azalea-core/src/position.rs | 11 |
2 files changed, 23 insertions, 8 deletions
diff --git a/azalea-core/src/math.rs b/azalea-core/src/math.rs index 6683dd10..01695a0a 100644 --- a/azalea-core/src/math.rs +++ b/azalea-core/src/math.rs @@ -9,17 +9,17 @@ pub static SIN: LazyLock<[f32; 65536]> = LazyLock::new(|| { }); /// A sine function that uses a lookup table. -pub fn sin(var0: f32) -> f32 { - let var0 = var0 * 10430.378; - let var0 = var0 as usize; - SIN[var0 & 65535] +pub fn sin(x: f32) -> f32 { + let x = x * 10430.378; + let x = x as usize; + SIN[x & 65535] } /// A cosine function that uses a lookup table. -pub fn cos(var0: f32) -> f32 { - let var0 = var0 * 10430.378 + 16384.0; - let var0 = var0 as usize; - SIN[var0 & 65535] +pub fn cos(x: f32) -> f32 { + let x = x * 10430.378 + 16384.0; + let x = x as usize; + SIN[x & 65535] } // TODO: make this generic @@ -56,6 +56,10 @@ pub fn lerp<T: num_traits::Float>(amount: T, a: T, b: T) -> T { a + amount * (b - a) } +pub fn ceil_log2(x: u32) -> u32 { + u32::BITS - x.leading_zeros() +} + #[cfg(test)] mod tests { use super::*; diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index eb6bcd89..f8072fa4 100755 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -346,6 +346,17 @@ impl From<Vec3> for ChunkPos { } } +impl From<&Vec3> for ChunkBlockPos { + fn from(pos: &Vec3) -> Self { + ChunkBlockPos::from(&BlockPos::from(pos)) + } +} +impl From<Vec3> for ChunkBlockPos { + fn from(pos: Vec3) -> Self { + ChunkBlockPos::from(&pos) + } +} + const PACKED_X_LENGTH: u64 = 1 + 25; // minecraft does something a bit more complicated to get this 25 const PACKED_Z_LENGTH: u64 = PACKED_X_LENGTH; const PACKED_Y_LENGTH: u64 = 64 - PACKED_X_LENGTH - PACKED_Z_LENGTH; |
