use std::any::Any;
use crate::engine::component::Bundle;
use crate::engine::component::Signature;
use crate::engine::entity::Entity;
use crate::engine::types::{AgentTemplateId, ComponentID};
pub struct BatchColumn {
pub component_id: ComponentID,
pub values: Box<dyn Any + Send>,
pub len: usize,
}
pub struct SpawnBatch {
pub count: usize,
pub signature: Signature,
pub columns: Vec<BatchColumn>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SpawnEvent {
pub entity: Entity,
pub tag: Option<String>,
pub template_id: Option<AgentTemplateId>,
}
impl SpawnEvent {
#[inline]
pub fn untagged(entity: Entity) -> Self {
Self {
entity,
tag: None,
template_id: None,
}
}
#[inline]
pub fn tagged(entity: Entity, tag: String) -> Self {
Self {
entity,
tag: Some(tag),
template_id: None,
}
}
#[inline]
pub fn template_tagged(entity: Entity, template_id: AgentTemplateId) -> Self {
Self {
entity,
tag: None,
template_id: Some(template_id),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DespawnEvent {
pub entity: Entity,
pub tag: Option<String>,
pub template_id: Option<AgentTemplateId>,
}
impl DespawnEvent {
#[inline]
pub fn untagged(entity: Entity) -> Self {
Self {
entity,
tag: None,
template_id: None,
}
}
#[inline]
pub fn tagged(entity: Entity, tag: String) -> Self {
Self {
entity,
tag: Some(tag),
template_id: None,
}
}
#[inline]
pub fn template_tagged(entity: Entity, template_id: AgentTemplateId) -> Self {
Self {
entity,
tag: None,
template_id: Some(template_id),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TemplateLifecycleBatch {
pub template_id: AgentTemplateId,
pub entities: Vec<Entity>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct CommandEvents {
pub spawned: Vec<SpawnEvent>,
pub despawned: Vec<DespawnEvent>,
pub spawned_batches: Vec<TemplateLifecycleBatch>,
pub despawned_batches: Vec<TemplateLifecycleBatch>,
}
impl CommandEvents {
#[inline]
pub fn is_empty(&self) -> bool {
self.spawned.is_empty()
&& self.despawned.is_empty()
&& self.spawned_batches.is_empty()
&& self.despawned_batches.is_empty()
}
}
pub enum Command {
Spawn {
bundle: Bundle,
},
SpawnTagged {
bundle: Bundle,
tag: String,
},
SpawnBatchTagged {
batch: SpawnBatch,
template_id: AgentTemplateId,
},
Despawn {
entity: Entity,
},
DespawnTagged {
entity: Entity,
tag: String,
},
DespawnBatchTagged {
entities: Vec<Entity>,
template_id: AgentTemplateId,
},
Add {
entity: Entity,
component_id: ComponentID,
value: Box<dyn Any + Send>,
},
Remove {
entity: Entity,
component_id: ComponentID,
},
AddComponentBatch {
entities: Vec<Entity>,
component_id: ComponentID,
values: Box<dyn Any + Send>,
len: usize,
},
RemoveComponentBatch {
entities: Vec<Entity>,
component_id: ComponentID,
},
Set {
entity: Entity,
component_id: ComponentID,
value: Box<dyn Any + Send>,
},
}