all_is_cubes_render/flaws.rs
1use core::fmt;
2
3bitflags::bitflags! {
4 /// Deficiencies of a rendering.
5 ///
6 /// This type describes the ways in which a rendered image could fail to accurately
7 /// represent the scene, or fail to comply with requested [`GraphicsOptions`].
8 ///
9 /// It is a [`bitflags`] generated bit-flag type. *Note: We make no guarantees that
10 /// the numeric value of flags will stay the same across versions*; please treat this
11 /// as a set of named values only.
12 ///
13 /// The [empty](Self::empty) set means no flaws are present.
14 ///
15 /// [`GraphicsOptions`]: super::GraphicsOptions
16 #[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
17 pub struct Flaws: u16 {
18 /// The rendering is incomplete due to the renderer not having had enough
19 /// time to finish initialization or catch up to changes.
20 const UNFINISHED = 1 << 0;
21
22 /// The rendering has a flaw not otherwise classified.
23 const OTHER = 1 << 1;
24
25 /// Antialiasing has not been used,
26 /// despite being requested by the graphics options.
27 const NO_ANTIALIASING = 1 << 2;
28
29 /// Bloom has not been rendered,
30 /// despite being requested by the graphics options.
31 const NO_BLOOM = 1 << 3;
32
33 /// A cursor has not been rendered, despite one being given.
34 const NO_CURSOR = 1 << 4;
35
36 /// View-distance fog has not been rendered, despite being requested by the
37 /// graphics options.
38 ///
39 /// This does not refer to explicitly semitransparent objects within the scene.
40 const NO_FOG = 1 << 5;
41
42 /// Surfaces that should have textures rather than a solid color don't.
43 // TODO: Should this just be one of the things TOO_MUCH means?
44 const MISSING_TEXTURES = 1 << 6;
45
46 // TODO:
47 // /// The rendering is incomplete due to insufficient resources to
48 // /// support the full complexity of the scene.
49 // const TOO_MUCH = 1 << ;
50
51 }
52}
53
54impl Default for Flaws {
55 /// Equivalent to [`Self::empty()`].
56 fn default() -> Self {
57 Self::empty()
58 }
59}
60
61impl fmt::Display for Flaws {
62 /// Displays the flags as text like “`UNFINISHED | NO_FOG`".
63 ///
64 /// TODO: Change this to “English” text like “unfinished, no fog”?
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 fmt::Display::fmt(&self.0, f)
67 }
68}
69
70#[cfg(test)]
71mod tests {
72 use super::*;
73 use alloc::string::ToString;
74
75 #[test]
76 fn display() {
77 // TODO: Add something other than the empty string when empty?
78 assert_eq!(Flaws::default().to_string(), "");
79
80 assert_eq!(Flaws::UNFINISHED.to_string(), "UNFINISHED");
81 assert_eq!(
82 (Flaws::UNFINISHED | Flaws::NO_FOG).to_string(),
83 "UNFINISHED | NO_FOG"
84 );
85 }
86}