naia_shared/world/
shared_global_world_manager.rs1use std::hash::Hash;
2use std::marker::PhantomData;
3
4use crate::{EntityEvent, GlobalWorldManagerType, WorldMutType};
5
6pub struct SharedGlobalWorldManager<E: Copy + Eq + Hash + Send + Sync> {
7 phantom_e: PhantomData<E>,
8}
9
10impl<E: Copy + Eq + Hash + Send + Sync> SharedGlobalWorldManager<E> {
11 pub fn despawn_all_entities<W: WorldMutType<E>>(
12 world: &mut W,
13 global_world_manager: &dyn GlobalWorldManagerType<E>,
14 entities: Vec<E>,
15 ) -> Vec<EntityEvent<E>> {
16 let mut output = Vec::new();
17
18 for entity in entities {
19 if let Some(component_kinds) = global_world_manager.component_kinds(&entity) {
22 for component_kind in component_kinds {
23 if let Some(component) =
24 world.remove_component_of_kind(&entity, &component_kind)
25 {
26 output.push(EntityEvent::<E>::RemoveComponent(entity, component));
27 } else {
28 panic!("Global World Manager must not have an accurate component list");
29 }
30 }
31 }
32
33 output.push(EntityEvent::DespawnEntity(entity));
35
36 world.despawn_entity(&entity);
38 }
39
40 output
41 }
42}