use std::collections::HashSet;

pub type EntityHandle = u64;

pub struct EntityManager
{
    next_id: EntityHandle,
    alive: HashSet<EntityHandle>,
}

impl EntityManager
{
    pub fn new() -> Self
    {
        Self {
            next_id: 0,
            alive: HashSet::new(),
        }
    }

    pub fn spawn(&mut self) -> EntityHandle
    {
        let id = self.next_id;
        self.next_id += 1;
        self.alive.insert(id);
        id
    }

    pub fn despawn(&mut self, entity: EntityHandle)
    {
        self.alive.remove(&entity);
    }

    pub fn is_alive(&self, entity: EntityHandle) -> bool
    {
        self.alive.contains(&entity)
    }

    pub fn all_entities(&self) -> Vec<EntityHandle>
    {
        self.alive.iter().copied().collect()
    }
}
