use std::ops::Deref;
use ghast_data::modern::EntityTypeData;
pub(crate) mod st {
pub const HAS_PREV: u8 = 1;
pub const SCALE_DIRTY: u8 = 2;
pub const SETTLED: u8 = 4;
pub const SLEEPING: u8 = 8;
pub const BABY: u8 = 16;
pub const HAS_DIMS: u8 = 32;
}
#[derive(Clone, Debug)]
pub(crate) struct State {
pub(crate) td: Option<&'static EntityTypeData>,
pub(crate) target: [f64; 3],
pub(crate) prev: [f64; 3],
pub(crate) target_rot: [f32; 2],
pub(crate) prev_rot: [f32; 2],
pub(crate) dims: ghast_data::EntityDimensions,
pub(crate) head_target: f32,
pub(crate) body_yaw: f32,
pub(crate) last_stable_head: f32,
pub(crate) scale: f32,
pub(crate) slime_size: i32,
pub(crate) item_count: i32,
pub(crate) info_gen: u32,
pub(crate) frozen_game_mode: i8,
pub(crate) steps: u8,
pub(crate) head_steps: u8,
pub(crate) head_stable_time: u8,
pub(crate) pose: u8,
pub(crate) stand_flags: u8,
pub(crate) fox_flags: u8,
pub(crate) flags: u8,
}
impl State {
pub(crate) const EMPTY: State = State {
td: None,
target: [0.0; 3],
prev: [0.0; 3],
target_rot: [0.0; 2],
prev_rot: [0.0; 2],
dims: ghast_data::EntityDimensions {
width: 0.0,
height: 0.0,
eye_height: 0.0,
},
head_target: 0.0,
body_yaw: 0.0,
last_stable_head: 0.0,
scale: 1.0,
slime_size: 1,
item_count: 0,
info_gen: 0,
frozen_game_mode: 0,
steps: 0,
head_steps: 0,
head_stable_time: 0,
pose: 0,
stand_flags: 0,
fox_flags: 0,
flags: 0,
};
#[inline]
pub(crate) fn flag(&self, f: u8) -> bool {
self.flags & f != 0
}
#[inline]
pub(crate) fn set_flag(&mut self, f: u8, on: bool) {
if on {
self.flags |= f;
} else {
self.flags &= !f;
}
}
#[inline]
pub(crate) fn dims(&self) -> Option<ghast_data::EntityDimensions> {
self.flag(st::HAS_DIMS).then_some(self.dims)
}
#[inline]
pub(crate) fn set_dims(&mut self, d: Option<ghast_data::EntityDimensions>) {
self.set_flag(st::HAS_DIMS, d.is_some());
if let Some(d) = d {
self.dims = d;
}
}
}
#[derive(Clone, Debug, Default)]
pub(crate) struct Ext(pub(crate) Option<Box<State>>);
static EMPTY_STATE: State = State::EMPTY;
impl Deref for Ext {
type Target = State;
#[inline]
fn deref(&self) -> &State {
self.0.as_deref().unwrap_or(&EMPTY_STATE)
}
}
impl std::ops::DerefMut for Ext {
#[inline]
fn deref_mut(&mut self) -> &mut State {
self.0.get_or_insert_with(|| Box::new(State::EMPTY))
}
}