Skip to main content

SSPack

Struct SSPack 

Source
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

Source

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).

Source

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).

Source

pub fn name(&self) -> &str

The name instance references resolve against.

Source

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.

Source

pub fn has_embedded_textures(&self) -> bool

Whether the atlases ride inside the .ssab (embedded mode). false means the host supplies them (reference mode).

Source

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.

Source

pub fn animation_names(&self) -> Vec<String>

Names of every animation in the pack.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for SSPack

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,