pub struct Cache<T, K: Tiled = Key> { /* private fields */ }Expand description
Painted tiles, keyed by theme, level, column and row, holding at most
cap of cost — bytes of pixels, or a count — the least recently used
dropped first. Damage marks the tiles it overlaps stale; a stale tile is
still there, and says so, until it is painted again. What a tile holds is
the cache’s user’s: pixels in the server, a texture on the GPU.
Implementations§
Source§impl<T, K: Tiled> Cache<T, K>
impl<T, K: Tiled> Cache<T, K>
pub fn new(cap: usize) -> Cache<T, K>
Sourcepub fn get(&mut self, key: &K) -> Option<(&T, bool)>
pub fn get(&mut self, key: &K) -> Option<(&T, bool)>
The tile at key, and whether it is stale; it counts as used.
Sourcepub fn peek(&self, key: &K) -> Option<(&T, bool)>
pub fn peek(&self, key: &K) -> Option<(&T, bool)>
The tile at key and whether it is stale, without counting a use.
Sourcepub fn insert(&mut self, key: K, value: T, cost: usize) -> Vec<(K, T)>
pub fn insert(&mut self, key: K, value: T, cost: usize) -> Vec<(K, T)>
Keeps value as the current tile at key, costing cost, and drops
the least recently used others until the cache is within its cap.
Returns what was dropped.
Sourcepub fn damage(&mut self, theme: Theme, origin: (f64, f64), rects: &[KRect])
pub fn damage(&mut self, theme: Theme, origin: (f64, f64), rects: &[KRect])
Marks stale every tile of theme that overlaps one of rects — in
the design’s coordinates, the drawing’s top-left at origin — at
every level.
Sourcepub fn damage_where(
&mut self,
which: impl Fn(&K) -> bool,
origin: (f64, f64),
rects: &[KRect],
)
pub fn damage_where( &mut self, which: impl Fn(&K) -> bool, origin: (f64, f64), rects: &[KRect], )
Marks stale every tile which picks that overlaps one of rects, as
Cache::damage does.
Sourcepub fn damage_all(&mut self, theme: Theme)
pub fn damage_all(&mut self, theme: Theme)
Marks every tile of theme stale.
Sourcepub fn damage_all_where(&mut self, which: impl Fn(&K) -> bool)
pub fn damage_all_where(&mut self, which: impl Fn(&K) -> bool)
Marks every tile which picks stale.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&K, &T, bool)>
pub fn iter(&self) -> impl Iterator<Item = (&K, &T, bool)>
Every tile, with whether it is stale.