
# Objective Unlike for their helper typers, the import paths for `unique_array::UniqueEntityArray`, `unique_slice::UniqueEntitySlice`, `unique_vec::UniqueEntityVec`, `hash_set::EntityHashSet`, `hash_map::EntityHashMap`, `index_set::EntityIndexSet`, `index_map::EntityIndexMap` are quite redundant. When looking at the structure of `hashbrown`, we can also see that while both `HashSet` and `HashMap` have their own modules, the main types themselves are re-exported to the crate level. ## Solution Re-export the types in their shared `entity` parent module, and simplify the imports where they're used.
90 lines
2.9 KiB
Rust
90 lines
2.9 KiB
Rust
use bevy_derive::{Deref, DerefMut};
|
|
use bevy_ecs::component::Component;
|
|
use bevy_ecs::entity::{Entity, EntityHashMap};
|
|
use bevy_ecs::reflect::ReflectComponent;
|
|
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
|
use bevy_render::sync_world::MainEntity;
|
|
/// Collection of mesh entities visible for 3D lighting.
|
|
///
|
|
/// This component contains all mesh entities visible from the current light view.
|
|
/// The collection is updated automatically by [`crate::SimulationLightSystems`].
|
|
#[derive(Component, Clone, Debug, Default, Reflect, Deref, DerefMut)]
|
|
#[reflect(Component, Debug, Default, Clone)]
|
|
pub struct VisibleMeshEntities {
|
|
#[reflect(ignore, clone)]
|
|
pub entities: Vec<Entity>,
|
|
}
|
|
|
|
#[derive(Component, Clone, Debug, Default, Reflect, Deref, DerefMut)]
|
|
#[reflect(Component, Debug, Default, Clone)]
|
|
pub struct RenderVisibleMeshEntities {
|
|
#[reflect(ignore, clone)]
|
|
pub entities: Vec<(Entity, MainEntity)>,
|
|
}
|
|
|
|
#[derive(Component, Clone, Debug, Default, Reflect)]
|
|
#[reflect(Component, Debug, Default, Clone)]
|
|
pub struct CubemapVisibleEntities {
|
|
#[reflect(ignore, clone)]
|
|
data: [VisibleMeshEntities; 6],
|
|
}
|
|
|
|
impl CubemapVisibleEntities {
|
|
pub fn get(&self, i: usize) -> &VisibleMeshEntities {
|
|
&self.data[i]
|
|
}
|
|
|
|
pub fn get_mut(&mut self, i: usize) -> &mut VisibleMeshEntities {
|
|
&mut self.data[i]
|
|
}
|
|
|
|
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &VisibleMeshEntities> {
|
|
self.data.iter()
|
|
}
|
|
|
|
pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut VisibleMeshEntities> {
|
|
self.data.iter_mut()
|
|
}
|
|
}
|
|
|
|
#[derive(Component, Clone, Debug, Default, Reflect)]
|
|
#[reflect(Component, Debug, Default, Clone)]
|
|
pub struct RenderCubemapVisibleEntities {
|
|
#[reflect(ignore, clone)]
|
|
pub(crate) data: [RenderVisibleMeshEntities; 6],
|
|
}
|
|
|
|
impl RenderCubemapVisibleEntities {
|
|
pub fn get(&self, i: usize) -> &RenderVisibleMeshEntities {
|
|
&self.data[i]
|
|
}
|
|
|
|
pub fn get_mut(&mut self, i: usize) -> &mut RenderVisibleMeshEntities {
|
|
&mut self.data[i]
|
|
}
|
|
|
|
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &RenderVisibleMeshEntities> {
|
|
self.data.iter()
|
|
}
|
|
|
|
pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut RenderVisibleMeshEntities> {
|
|
self.data.iter_mut()
|
|
}
|
|
}
|
|
|
|
#[derive(Component, Clone, Debug, Default, Reflect)]
|
|
#[reflect(Component, Default, Clone)]
|
|
pub struct CascadesVisibleEntities {
|
|
/// Map of view entity to the visible entities for each cascade frustum.
|
|
#[reflect(ignore, clone)]
|
|
pub entities: EntityHashMap<Vec<VisibleMeshEntities>>,
|
|
}
|
|
|
|
#[derive(Component, Clone, Debug, Default, Reflect)]
|
|
#[reflect(Component, Default, Clone)]
|
|
pub struct RenderCascadesVisibleEntities {
|
|
/// Map of view entity to the visible entities for each cascade frustum.
|
|
#[reflect(ignore, clone)]
|
|
pub entities: EntityHashMap<Vec<RenderVisibleMeshEntities>>,
|
|
}
|