pub struct SpriteCache { /* private fields */ }Expand description
Cache of decoded sprites, keyed by Unicode codepoint.
§Reload / hot-swap is not supported
load is append-only: it decodes a tileset and merges its sprites into the
existing map, with later registrations winning on codepoint collision (see load
docs). There is no unload or clear, and nothing observes or invalidates sprites already
handed out via get.
This is a deliberate scope decision, not an oversight: games generally don’t hot-swap tilesets
at runtime, and a SpriteCache is only ever populated once, when a backend is built. If you
need to iterate on a sprite sheet (e.g. during dev-mode asset editing) or otherwise want a
tileset change to take effect, rebuild the whole renderer from a fresh backend configuration
rather than mutating an existing cache in place.
Implementations§
Source§impl SpriteCache
impl SpriteCache
Sourcepub fn iter(&self) -> impl ExactSizeIterator<Item = (char, &Sprite)>
pub fn iter(&self) -> impl ExactSizeIterator<Item = (char, &Sprite)>
Iterates every registered (codepoint, sprite) in codepoint order.
Used by GPU backends to build a sprite atlas from the whole decoded set (the software
backend only ever needs per-glyph get at blit time).
Sourcepub fn from_tilesets(opts: &[TilesetOptions]) -> Result<Self, TilesetError>
pub fn from_tilesets(opts: &[TilesetOptions]) -> Result<Self, TilesetError>
Builds a cache by loading every tileset in opts, in order.
This is what both pixel backends call from their builder’s build/into_renderer
instead of each looping over their own configured tilesets by hand; later tilesets win
on codepoint collision, same as calling load directly in a loop.
§Errors
Returns the first TilesetError any tileset’s load call fails with; no
later tileset is loaded once one fails.
Sourcepub fn load(&mut self, opts: &TilesetOptions) -> Result<(), TilesetError>
pub fn load(&mut self, opts: &TilesetOptions) -> Result<(), TilesetError>
Loads a tileset, decoding the sprite sheet and inserting all sprites.
On codepoint collision, the new sprite replaces the old one and a
message is logged via log::warn. Unlike warn_sprite_needs_span and
warn_tint_needs_sprite, this warning is not gated behind
dev_only!: it fires at most once per tileset load rather
than once per frame, so it needs no seen dedup table and has no redraw-loop cost, and it
reports a tileset/codepage authoring mistake a consumer may want visible even in a shipped
build. See the “Load-time versus per-frame” section of retroglyph_core::dev’s module
docs.
§Errors
Returns TilesetError::ImageDecode if the bytes are not a valid image,
TilesetError::ZeroTileSize if opts.tile_width or opts.tile_height
is 0, TilesetError::InvalidDimensions if the decoded image
dimensions are not evenly divisible by the tile size, or
TilesetError::TooManyColumns if opts.columns declares more columns
than the image actually has at opts.tile_width.
Trait Implementations§
Source§impl Debug for SpriteCache
impl Debug for SpriteCache
Auto Trait Implementations§
impl Freeze for SpriteCache
impl RefUnwindSafe for SpriteCache
impl Send for SpriteCache
impl Sync for SpriteCache
impl Unpin for SpriteCache
impl UnsafeUnpin for SpriteCache
impl UnwindSafe for SpriteCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.