pub struct SSPack { /* private fields */ }Expand description
A loaded .ssab, shareable between players.
Loading costs a parse, unless a live pack already holds the same bytes;
sharing costs an Arc clone. SSPlayer::set_pack
selects the pack to play from and SSPlayer::add_pack registers the extra
packs that external instance parts reference by name.
Implementations§
Source§impl SSPack
impl SSPack
Sourcepub fn load(bytes: &[u8]) -> Result<Self, SSRuntimeError>
pub fn load(bytes: &[u8]) -> Result<Self, SSRuntimeError>
Parse bytes, naming the pack after the .ssab itself.
The name matters because instance parts resolve their sub-animation by
pack name (ref_anime_pack), and the exporter writes that same
name into each pack — so the two agree without the host having to derive
one from a file path. Use SSPack::load_named when the host names packs
itself.
The bytes are not verified — not here, and not by the runtime — so a malformed or
crafted .ssab can cause out-of-bounds reads. Load only packs you trust (SECURITY.md).
Sourcepub fn load_named(name: &str, bytes: &[u8]) -> Result<Self, SSRuntimeError>
pub fn load_named(name: &str, bytes: &[u8]) -> Result<Self, SSRuntimeError>
Parse bytes under a name the caller chooses, overriding the one in the
.ssab. What add_ssab / load_ssab use.
The bytes are not verified — not here, and not by the runtime — so a malformed or
crafted .ssab can cause out-of-bounds reads. Load only packs you trust (SECURITY.md).
Sourcepub fn textures(&self) -> &[TextureRef]
pub fn textures(&self) -> &[TextureRef]
The atlases this pack’s draw batches will ask for: every cellmap’s image,
then every external_textures() entry.
A reference-mode host walks this to know what to load, and from where,
before playing (see TextureRef); combined with
crate::SSRenderer::texture_size it also answers “is this pack ready to
draw”.
Both tables, always. DrawBatch.texture_hash is a cellmap’s
name_hash for an ordinary part but a texture file name’s hash for one
the author gave a TextureChange (TCHG), and the two tables are the only
places those keys come from. An external texture can be a cellmap’s own
image under a second hash. Loading only the cellmaps leaves the changed
parts on the white fallback.
Sourcepub fn has_embedded_textures(&self) -> bool
pub fn has_embedded_textures(&self) -> bool
Whether the atlases ride inside the .ssab (embedded mode).
false means the host supplies them (reference mode).
Sourcepub fn instance_packs(&self) -> Vec<String>
pub fn instance_packs(&self) -> Vec<String>
The names of the packs this one’s instance parts play from,
deduplicated, in external_instances() order.
The counterpart of SSPack::textures for playback data rather than
images: a pack answers what else it needs, and the host — the only side
with a filesystem or a network — fetches it and hands it to
SSPlayer::add_pack. The exporter writes the referenced pack’s own name
here, which is both the file’s stem and the key ref_anime_pack resolves
against, so <the .ssab's directory>/<name>.ssab finds it.
Only genuinely external references appear: external_instances() is the
exporter’s own list, so a pack whose instance parts play its own
animations reports nothing.
Sourcepub fn animation_names(&self) -> Vec<String>
pub fn animation_names(&self) -> Vec<String>
Names of every animation in the pack.
Sourcepub fn embedded_images(&self) -> Vec<EmbeddedImage<'_>>
pub fn embedded_images(&self) -> Vec<EmbeddedImage<'_>>
The encoded atlases this pack carries, in cellmap order. Empty for a reference-mode pack.
Parsing only — no image decoder is involved, so this works in every build
and is the route a host with its own decoder takes (see EmbeddedImage).
On the web that host is the browser: createImageBitmap on these bytes
decodes off the main thread and premultiplies for free, which
SSPack::decode_embedded cannot do and pays for in wasm size.
The two hashes are different things and must not be swapped:
the blob is keyed by image_path_hash, and what comes back is keyed by
name_hash — the one a draw batch asks for.
Sourcepub fn decode_embedded(&self) -> Vec<EmbeddedTexture>
pub fn decode_embedded(&self) -> Vec<EmbeddedTexture>
Decode the atlases this pack carries. Empty for a
reference-mode pack, and empty without the embedded feature.
Decoding is not cached: the pixels are handed over so the caller can put
them wherever GPU memory is owned (upload_texture, or an engine’s asset
system). Call it once per pack, not once per player.
Sourcepub fn decode_embedded_where(
&self,
wanted: impl Fn(u32) -> bool,
) -> Vec<EmbeddedTexture>
pub fn decode_embedded_where( &self, wanted: impl Fn(u32) -> bool, ) -> Vec<EmbeddedTexture>
SSPack::decode_embedded, restricted to the hashes wanted accepts.
The filter runs before the PNG decode, which is the whole point: a player joining a scene where its atlas is already registered skips the decode entirely, so N players of one pack cost one decode and one upload. The decodes overlap where there is more than one image; the result stays in pack order, so an image that will not decode drops out without shifting the ones after it.