Files
a0_basic_app
a1_vehicle
a2_async_sim
ab_glyph
ab_glyph_rasterizer
adler
adler32
agents
aho_corasick
anyhow
approx
aquamarine
ash
atty
bitflags
bytemuck
byteorder
cache_padded
cfg_if
chrono
color_quant
crc32fast
crossbeam_channel
crossbeam_deque
crossbeam_epoch
crossbeam_utils
deflate
draw2d
either
flexi_logger
generic_array
gif
glfw
glfw_sys
glob
image
indoc
itertools
jpeg_decoder
lazy_static
libc
libloading
log
matrixmultiply
memchr
memoffset
miniz_oxide
nalgebra
base
geometry
linalg
third_party
num_complex
num_cpus
num_integer
num_iter
num_rational
num_traits
owned_ttf_parser
paste
png
proc_macro2
proc_macro_error
proc_macro_error_attr
quote
raw_window_handle
rawpointer
rayon
rayon_core
regex
regex_syntax
scoped_threadpool
scopeguard
semver
semver_parser
serde
serde_derive
simba
smawk
spin_sleep
syn
terminal_size
textwrap
thiserror
thiserror_impl
tiff
time
triple_buffer
ttf_parser
typenum
unicode_width
unicode_xid
unindent
vk_sys
weezl
yansi
 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
/// At atlas's version changes any time that the loaded textures are changed
/// in some way.
///
/// Typically this is used to detect when the atlas needs to update as shader's
/// descriptor sets.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct AtlasVersion {
    revision_count: u32,
}

impl AtlasVersion {
    /// A binding revision which will always be considered 'out_of_date'
    /// relative to the atlas.
    pub fn new_out_of_date() -> Self {
        Self { revision_count: 0 }
    }

    /// Compare a version with this one, returns true when the versions do not
    /// match.
    ///
    /// Always returns true if the version being compared against was created
    /// with `AtlasVersion::new_out_of_date`
    pub fn is_out_of_date(&self, version: &Self) -> bool {
        version.revision_count == 0
            || self.revision_count != version.revision_count
    }

    /// Create a new atlas version which is more up-to-date than the current.
    pub fn increment(&self) -> Self {
        AtlasVersion {
            revision_count: self.revision_count + 1,
        }
    }
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn same_versions_should_not_be_out_of_date() {
        let v1 = AtlasVersion { revision_count: 1 };
        let v2 = AtlasVersion { revision_count: 1 };

        assert!(!v1.is_out_of_date(&v2));
    }

    #[test]
    fn a_new_out_of_date_version_should_always_be_out_of_date() {
        let v1 = AtlasVersion { revision_count: 0 };
        let v2 = AtlasVersion::new_out_of_date();

        assert!(v1.is_out_of_date(&v2));
    }

    #[test]
    fn different_versions_should_be_out_of_date() {
        let v1 = AtlasVersion { revision_count: 1 };
        let v2 = AtlasVersion { revision_count: 2 };

        assert!(v1.is_out_of_date(&v2));
    }
}