Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_render/src/view/visibility/mod.rs
6598 views
1
use core::any::TypeId;
2
3
use bevy_ecs::{component::Component, entity::Entity, prelude::ReflectComponent};
4
use bevy_reflect::{prelude::ReflectDefault, Reflect};
5
use bevy_utils::TypeIdMap;
6
7
use crate::sync_world::MainEntity;
8
9
mod range;
10
use bevy_camera::visibility::*;
11
pub use range::*;
12
13
/// Collection of entities visible from the current view.
14
///
15
/// This component is extracted from [`VisibleEntities`].
16
#[derive(Clone, Component, Default, Debug, Reflect)]
17
#[reflect(Component, Default, Debug, Clone)]
18
pub struct RenderVisibleEntities {
19
#[reflect(ignore, clone)]
20
pub entities: TypeIdMap<Vec<(Entity, MainEntity)>>,
21
}
22
23
impl 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
}
55
56