/// Entity
/// Use this to get entity from engine.
/// The index of EntityRef may be changed due to reordering,
///  so it is suggest to only use id to build relation.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub struct Ent(u32);

impl Default for Ent {
    fn default() -> Self {
        Self(u32::MAX)
    }
}

impl From<Ent> for u32 {
    fn from(ent: Ent) -> Self {
        ent.0
    }
}

impl From<u32> for Ent {
    fn from(id: u32) -> Self {
        Self(id)
    }
}

#[derive(Default, Debug)]
pub struct EntAllocator {
    next: u32,
}

impl EntAllocator {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn alloc(&mut self) -> Ent {
        let ent = Ent(self.next);
        self.next += 1;
        ent
    }
}
