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
use crate::component::Component;
use crate::entity_id::EntityId;
use crate::seal::Sealed;
use crate::sparse_set::SparseSet;
use crate::track::Insertion;
use crate::tracking::{InsertionTracking, Tracking, TrackingTimestamp};

impl Sealed for Insertion {}

impl Tracking for Insertion {
    const VALUE: u32 = 0b0001;

    fn name() -> &'static str {
        "Insertion"
    }

    #[inline]
    fn is_inserted<T: Component>(
        sparse_set: &SparseSet<T>,
        entity: EntityId,
        last: TrackingTimestamp,
        current: TrackingTimestamp,
    ) -> bool {
        if let Some(dense) = sparse_set.index_of(entity) {
            sparse_set.insertion_data[dense].is_within(last, current)
        } else {
            false
        }
    }
}

impl InsertionTracking for Insertion {}