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
use std::sync::Mutex;
use alchemy_styles::lazy_static;
lazy_static! {
pub(crate) static ref INSTANCE_ALLOCATOR: Mutex<Allocator> = Mutex::new(Allocator::new());
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub(crate) struct Id {
id: u32
}
pub(crate) struct Allocator {
new_id: u32
}
impl Allocator {
pub fn new() -> Self {
Allocator { new_id: 1 }
}
pub fn allocate(&mut self) -> Id {
let id = self.new_id;
self.new_id += 1;
Id { id: id }
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct ComponentKey {
pub(crate) instance: Id,
pub(crate) local: Id,
}
impl ComponentKey {
pub fn placeholder() -> ComponentKey {
ComponentKey {
instance: Id { id: 0 },
local: Id { id: 0 }
}
}
}