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
use core::sync::atomic::{AtomicBool, Ordering};

use specs::{Entity, VecStorage, Component};


pub struct Child {
    parent: Entity,
    dirty: AtomicBool,
}

impl Component for Child {
    type Storage = VecStorage<Child>;
}

impl Child {

    #[inline(always)]
    pub fn new(entity: Entity) -> Child {
        Child {
            parent: entity,
            dirty: AtomicBool::new(true),
        }
    }

    #[inline(always)]
    pub fn parent(&self) -> Entity {
        self.parent
    }

    #[inline]
    pub fn set_parent(&mut self, entity: Entity) {
        self.parent = entity;
        self.flag(true);
    }

    #[inline(always)]
    pub fn flag(&self, dirty: bool) {
        self.dirty.store(dirty, Ordering::SeqCst);
    }

    #[inline(always)]
    pub fn is_dirty(&self) -> bool {
        self.dirty.load(Ordering::SeqCst)
    }
}