alex/beta-minecraft-rust
Minecraft Beta 1.7.3 Rewrite
BRANCH main
SNAPSHOT Draw terrain GPU-driven from packed per-section buffers with GPU occlusion culling, add a render distance slider (2-128) with a quad/disk shape, cut chunk bookkeeping at high render distances, and fix a light underflow at y=0
DOWNLOAD
root crates common src math.rs
//! Port of `MathHelper`, including its lookup-table trigonometry.
use std::sync::LazyLock;
static SIN_TABLE: LazyLock<Box<[f32]>> = LazyLock::new(|| {
(0..65536)
.map(|i| (f64::from(i) * std::f64::consts::PI * 2.0 / 65536.0).sin() as f32)
.collect()
});
pub fn sin(value: f32) -> f32 {
SIN_TABLE[((value * 10430.378) as i32 & 0xFFFF) as usize]
}
pub fn cos(value: f32) -> f32 {
SIN_TABLE[((value * 10430.378 + 16384.0) as i32 & 0xFFFF) as usize]
}
pub fn floor_f32(value: f32) -> i32 {
let truncated = value as i32;
if value < truncated as f32 {
truncated.wrapping_sub(1)
} else {
truncated
}
}
pub fn floor_f64(value: f64) -> i32 {
let truncated = value as i32;
if value < f64::from(truncated) {
truncated.wrapping_sub(1)
} else {
truncated
}
}