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
use super::*;
use crate::nodes::RenderView;
use rafx_base::slab::DropSlab;

#[derive(Default)]
pub struct DynamicVisibilityNodeSet {
    dynamic_aabb: DropSlab<DynamicAabbVisibilityNode>,
}

impl DynamicVisibilityNodeSet {
    pub fn register_dynamic_aabb(
        &mut self,
        node: DynamicAabbVisibilityNode,
    ) -> DynamicAabbVisibilityNodeHandle {
        //TODO: Insert into spatial structure?
        DynamicAabbVisibilityNodeHandle(self.dynamic_aabb.allocate(node))
    }

    pub fn calculate_dynamic_visibility(
        &mut self,
        view: &RenderView,
    ) -> VisibilityResult {
        self.dynamic_aabb.process_drops();

        log::trace!("Calculate dynamic visibility for {}", view.debug_name());
        let mut result = VisibilityResult::default();

        for aabb in self.dynamic_aabb.iter_values() {
            log::trace!("push dynamic visibility object {:?}", aabb.handle);
            result.handles.push(aabb.handle);
        }

        //TODO: Could consider sorting lists of handles by type/key to get linear memory access
        result
    }
}