use super::*;
#[derive(Debug)]
pub struct Offspring<'e, K, C> {
entities: Vec<Box<EntityTrait<'e, K, C>>>,
}
impl<'e, K, C> Default for Offspring<'e, K, C> {
fn default() -> Self {
Self {
entities: Vec::default(),
}
}
}
impl<'e, K, C> Offspring<'e, K, C> {
pub fn with_capacity(capacity: usize) -> Self {
Self {
entities: Vec::with_capacity(capacity),
}
}
#[cfg(not(feature = "parallel"))]
pub fn insert<E>(&mut self, entity: E)
where
E: Entity<'e, Kind = K, Context = C> + 'e,
{
self.entities.push(Box::new(entity));
}
#[cfg(feature = "parallel")]
pub fn insert<E>(&mut self, entity: E)
where
E: Entity<'e, Kind = K, Context = C> + 'e + Send + Sync,
{
self.entities.push(Box::new(entity));
}
pub fn count(&self) -> usize {
self.entities.len()
}
pub fn is_empty(&self) -> bool {
self.count() == 0
}
pub fn drain(&mut self) -> Self {
Self {
entities: self.entities.drain(..).collect(),
}
}
pub(crate) fn take_entities(self) -> Vec<Box<EntityTrait<'e, K, C>>> {
self.entities
}
}