pub struct SpriteCache { /* private fields */ }tilesets only.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 load(&mut self, opts: &TilesetOptions) -> Result<(), TilesetError>
pub fn load(&mut self, opts: &TilesetOptions) -> Result<(), TilesetError>
Loads a tileset, decoding the PNG and inserting all sprites.
On codepoint collision, the new sprite replaces the old one and a
message is logged via log::warn.
§Errors
Returns TilesetError::PngDecode if the bytes are not a valid PNG,
TilesetError::ZeroTileSize if opts.tile_width or opts.tile_height
is 0, or TilesetError::InvalidDimensions if the decoded image
dimensions are not evenly divisible by the tile size.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.