WORLD_Y_START_AT refactor
Renamed `WORLD_Y_START_AT` to `WORLD_LOWEST_Y`. Added `WORLD_Y_END_AT`. Changed the type to i16 for ergonomics. Moved the constants under the use statements for readability.
This commit is contained in:
1 parent
be98a730b0
commit
a0260acd8b
2 files changed
+12
-10
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use crate::{WORLD_HEIGHT, WORLD_Y_START_AT};
|
use crate::{WORLD_LOWEST_Y, WORLD_MAX_Y};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct Height {
|
pub struct Height {
|
||||||
@@ -9,20 +9,20 @@ pub struct Height {
|
|||||||
|
|
||||||
impl Height {
|
impl Height {
|
||||||
pub fn new(height: i16) -> Self {
|
pub fn new(height: i16) -> Self {
|
||||||
assert!(height <= (WORLD_HEIGHT as i16 - WORLD_Y_START_AT.abs() as i16));
|
assert!(height <= WORLD_MAX_Y);
|
||||||
assert!(height >= WORLD_Y_START_AT as i16);
|
assert!(height >= WORLD_LOWEST_Y);
|
||||||
|
|
||||||
Self { height }
|
Self { height }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_absolute(height: u16) -> Self {
|
pub fn from_absolute(height: u16) -> Self {
|
||||||
Self::new(height as i16 - WORLD_Y_START_AT.abs() as i16)
|
Self::new(height as i16 - WORLD_LOWEST_Y.abs())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Absolute height ranges from `0..WORLD_HEIGHT`
|
/// Absolute height ranges from `0..WORLD_HEIGHT`
|
||||||
/// instead of `WORLD_Y_START_AT..(WORLD_HEIGHT-WORLD_Y_START_AT)`
|
/// instead of `WORLD_LOWEST_Y..WORLD_MAX_Y`
|
||||||
pub fn get_absolute(&self) -> u16 {
|
pub fn get_absolute(&self) -> u16 {
|
||||||
(self.height + WORLD_Y_START_AT.abs() as i16) as u16
|
(self.height + WORLD_LOWEST_Y.abs()) as u16
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
use level::Level;
|
use level::Level;
|
||||||
|
|
||||||
|
pub mod block;
|
||||||
pub mod chunk;
|
pub mod chunk;
|
||||||
pub mod coordinates;
|
pub mod coordinates;
|
||||||
pub mod dimension;
|
pub mod dimension;
|
||||||
pub const WORLD_HEIGHT: usize = 384;
|
|
||||||
pub const WORLD_Y_START_AT: i32 = -64;
|
|
||||||
pub const DIRECT_PALETTE_BITS: u32 = 15;
|
|
||||||
pub mod block;
|
|
||||||
pub mod global_registry;
|
pub mod global_registry;
|
||||||
pub mod item;
|
pub mod item;
|
||||||
mod level;
|
mod level;
|
||||||
pub mod radial_chunk_iterator;
|
pub mod radial_chunk_iterator;
|
||||||
pub mod vector3;
|
pub mod vector3;
|
||||||
|
|
||||||
|
pub const WORLD_HEIGHT: usize = 384;
|
||||||
|
pub const WORLD_LOWEST_Y: i16 = -64;
|
||||||
|
pub const WORLD_MAX_Y: i16 = WORLD_HEIGHT as i16 - WORLD_LOWEST_Y.abs();
|
||||||
|
pub const DIRECT_PALETTE_BITS: u32 = 15;
|
||||||
|
|
||||||
pub struct World {
|
pub struct World {
|
||||||
pub level: Level,
|
pub level: Level,
|
||||||
// entities, players...
|
// entities, players...
|
||||||
|
|||||||
Reference in new issue
Block a user