bevy_render/view/visibility/
mod.rs1use core::any::TypeId;
2
3use bevy_ecs::{component::Component, entity::Entity, prelude::ReflectComponent};
4use bevy_reflect::{prelude::ReflectDefault, Reflect};
5use bevy_utils::TypeIdMap;
6
7use crate::sync_world::MainEntity;
8
9mod range;
10use bevy_camera::visibility::*;
11pub use range::*;
12
13#[derive(Clone, Component, Default, Debug, Reflect)]
17#[reflect(Component, Default, Debug, Clone)]
18pub struct RenderVisibleEntities {
19 #[reflect(ignore, clone)]
20 pub entities: TypeIdMap<Vec<(Entity, MainEntity)>>,
21}
22
23impl RenderVisibleEntities {
24 pub fn get<QF>(&self) -> &[(Entity, MainEntity)]
25 where
26 QF: 'static,
27 {
28 match self.entities.get(&TypeId::of::<QF>()) {
29 Some(entities) => &entities[..],
30 None => &[],
31 }
32 }
33
34 pub fn iter<QF>(&self) -> impl DoubleEndedIterator<Item = &(Entity, MainEntity)>
35 where
36 QF: 'static,
37 {
38 self.get::<QF>().iter()
39 }
40
41 pub fn len<QF>(&self) -> usize
42 where
43 QF: 'static,
44 {
45 self.get::<QF>().len()
46 }
47
48 pub fn is_empty<QF>(&self) -> bool
49 where
50 QF: 'static,
51 {
52 self.get::<QF>().is_empty()
53 }
54}