1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// TODO Frustum culling!!!
#![allow(unused)]
use bevy::{
ecs::system::{Res, Resource},
prelude::{Query, ResMut},
render::view::ViewVisibility,
};
use crate::{
math::CameraAabb2d,
render::{
chunk::RenderChunkStorage,
extract::{ExtractedView, TilemapInstances},
},
tilemap::map::TilemapAabbs,
};
#[derive(Resource)]
pub struct FrustumCulling(pub bool);
impl Default for FrustumCulling {
fn default() -> Self {
Self(true)
}
}
pub fn cull_tilemaps(
mut tilemaps: Query<(&TilemapAabbs, &mut ViewVisibility)>,
cameras: Query<&CameraAabb2d>,
culling: Res<FrustumCulling>,
) {
if !culling.0 {
return;
}
// cameras.iter().for_each(|camera| {
// tilemaps.par_iter_mut().for_each(|(aabbs, mut visibility)| {
// if !aabbs.world_aabb.intersect(camera.0).is_empty() {
// visibility.set();
// }
// });
// });
}
pub fn cull_chunks(
tilemaps: Res<TilemapInstances>,
mut render_chunk_storage: ResMut<RenderChunkStorage>,
cameras: Query<&ExtractedView>,
culling: Res<FrustumCulling>,
) {
if !culling.0 {
return;
}
// tilemaps.keys().for_each(|tilemap| {
// render_chunk_storage
// .get_or_insert_chunks(*tilemap)
// .value
// .values_mut()
// .for_each(|c| {
// c.visible = false;
// });
// });
// cameras.iter().for_each(|cam_aabb| {
// tilemaps.keys().for_each(|tilemap| {
// render_chunk_storage
// .get_or_insert_chunks(*tilemap)
// .value
// .values_mut()
// .for_each(|c| {
// if !c.aabb.intersect(cam_aabb.0).is_empty() {
// c.visible = true;
// }
// });
// });
// });
}