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
//! The identities a `Scene` issues for its content. Each holds the index of
//! the content's records and a generation no other content of any scene
//! shares, so an identity of removed content, or one another scene issued,
//! names nothing. Only a scene issues them.
/// Crate access to an identity's parts, for the scene that issues it.
pub(crate) trait Identity: Copy {
fn issue(index: usize, generation: u64) -> Self;
fn index(self) -> usize;
fn generation(self) -> u64;
}
macro_rules! identity {
($(#[$doc:meta])* $name:ident) => {
$(#[$doc])*
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct $name {
index: u32,
generation: u64,
}
impl Identity for $name {
fn issue(index: usize, generation: u64) -> Self {
Self {
index: u32::try_from(index).expect("content indices fit in u32"),
generation,
}
}
fn index(self) -> usize {
self.index as usize
}
fn generation(self) -> u64 {
self.generation
}
}
};
}
identity!(
/// A material of a scene: its surface values and the textures they sample.
MaterialId
);
identity!(
/// A model of a scene: an ordered list of meshes, each with one material.
ModelId
);
identity!(
/// An instance of a scene: a model placed in the world.
InstanceId
);
identity!(
/// A point or spot light of a scene.
LightId
);
identity!(
/// An environment map of a scene.
EnvironmentId
);
identity!(
/// An image a scene's decals project.
DecalImageId
);
identity!(
/// A decal of a scene: a box that projects images onto surfaces.
DecalId
);
identity!(
/// A shader of a scene: a game's WGSL module its materials name.
ShaderId
);