Expand description
The playback Brain of the SpriteStudio SDK.
ssruntime loads .ssab animation binaries produced by ssconverter and computes,
for every frame, everything a renderer needs: part transforms, mesh deformations,
colors, and a cross-engine DrawBatch plan. It performs no rendering of its own —
each Player (engine integration) consumes the emitted state and draws with its
native API. That split is what keeps playback identical across engines.
.sspj (XML) .ssab (FlatBuffers) FrameData + DrawBatch pixels
│ │ │ │
└──── ssconverter ──────┴────── ssruntime ────────┴────── Player ─────────┘
(Brain) (Body)§API faces
The same core is exposed three ways; pick the one that matches your host:
| Face | Entry point | Consumer |
|---|---|---|
Rust (rlib) | Context, AnimationResource | Rust-native Players, this crate’s own tests |
C ABI (staticlib / cdylib, emitted by ssruntime-ffi) | ffi — ss_runtime_*, header generated by cbindgen | Unity, Godot, Ren’Py, Flutter, C/C++ engines |
JS / WASM (emitted by ssruntime-ffi) | the web module (feature web, wasm-bindgen) | the browser Player collection |
§Quick start (Rust)
use ssruntime::{AnimationResource, Context};
// 1. Parse the .ssab once. A resource is read-only and can back many contexts.
// SAFETY: a pack the converter wrote, so a valid .ssab (see Limitations below).
let resource = unsafe { AnimationResource::new(ssab_bytes) }?;
// 2. A context holds the playback state of one animated object.
let mut ctx = Context::new();
ctx.bind_resource(&resource);
ctx.setup_animation("Wait")?;
ctx.set_loop_count(-1); // -1 = loop forever
ctx.play();
// 3. Each tick: advance time, then ask for that frame's data.
// `update` takes **milliseconds**, matching the animation's fps.
while ctx.is_playing() {
let frame_no = ctx.update(1000.0 / 60.0);
let framedata: &[u8] = ctx.get_frame_data(frame_no)?;
// `framedata` is a FlatBuffer: the FrameData schema says how to read it.
}Transport, loop count, ping-pong, playback range and FPS all live on the context and
are backed by eval::playback_controller::PlaybackController.
Frame numbers are f32: the runtime interpolates between source keyframes, so
playback stays smooth above and below the authored framerate.
§Module map
eval— the evaluation core: interpolation, matrices, geometry,eval::playback_controller(transport, loop, ping-pong, seek),eval::framedata(the per-frame FlatBuffer),eval::override_layer(per-part color / cell / visibility overrides),eval::effect(particles).types—#[repr(C)]POD structs returned by value across API boundaries.error—error::SSRuntimeErrorand its stable integer codes.ffi— the C ABI surface (featureffi).web— thewasm-bindgensurface (featureweb).
§Feature flags
| Feature | Purpose |
|---|---|
ffi | C-API exports. For ssruntime-ffi, not for Rust dependents — see below. |
libc_alloc | libc::malloc/free-backed #[global_allocator] for no_std FFI builds (mobile / desktop). |
wasm_alloc | dlmalloc-backed #[global_allocator] for no_std WASM builds. |
emscripten_alloc | Emscripten libc-backed #[global_allocator] for Emscripten no_std builds. |
custom_alloc | Routes allocation and abort to host-provided ss_custom_alloc / ss_custom_free / ss_custom_abort symbols, for console and engine allocators. Build as staticlib. |
panic-handler | Provides #[panic_handler] for no_std FFI builds. |
web | wasm-bindgen bindings for JS/TS interop. Same caveat as ffi. |
std | Opt-in developer ergonomics only; never used by release scripts. |
Nothing is on by default: a Rust dependent wants the rlib and nothing else.
ffi and web exist for ssruntime-ffi, the sibling crate that emits this one as
a staticlib / cdylib. Enabling either from a Rust dependency compiles
#[no_mangle] extern "C" symbols into your binary, and those collide if the same
binary also links a prebuilt libssruntime. The allocator and panic-handler
features are for the same builds, and are inert in an rlib that std backs.
The allocator features are mutually exclusive — pairing custom_alloc with another
trips a compile_error! rather than the compiler’s opaque “multiple global allocators”.
§no_std
This crate is no_std-first and every release deliverable is built that way;
std exists for local developer convenience. An allocator is still required
(alloc is used for animation state and metadata), which is what the
*_alloc features above provide.
A Rust dependent takes the crate as it comes:
ssruntime = "7.0.0-beta.1"The binary deliverables are built from ssruntime-ffi, which passes these through:
# Mobile / desktop, C-API
cargo build -p ssruntime-ffi --no-default-features --features ffi,libc_alloc,panic-handler
# Browser, wasm-bindgen
cargo build -p ssruntime-ffi --target wasm32-unknown-unknown --no-default-features --features web
# Pure WASM (WASI or a custom engine)
cargo build -p ssruntime-ffi --target wasm32-unknown-unknown --no-default-features --features ffi,wasm_alloc,panic-handler§Limitations to design around
- Input is not validated. To keep the binary small and playback allocation-free,
.ssabis read zero-copy with no structural checks. Malformed or hostile input can cause out-of-bounds reads. Verifying asset integrity is the Player’s job — do it before loading anything that came from a network or an end user. The FlatBuffers accessors do not bounds-check in release builds, so reading anything but a valid.ssabis undefined behaviour; that precondition is whyAnimationResource::newandSsabResource::newareunsafe fn. - Borrowed buffers are not owned. One
AnimationResourcemay back severalContexts, and across the C ABI resources are reference-counted — destroying a resource handle that contexts are still bound to is safe. What is not managed for you is the.ssabbyte buffer behindss_resource_create_borrow: it is never copied, so the caller must keep it alive and unmodified for as long as the resource exists.ss_resource_create_copytrades memory for not having to.
§Further reading
- Player Porting Guide — how to build a Player on this crate, start to finish.
- FrameData schema
— the layout of what
Context::get_frame_datareturns. - Limitations — supported scope and spec constraints. Read before making Player design decisions.
Re-exports§
pub use crate::eval::SsCoordinateSystem;
Modules§
- error
- The runtime’s error type and its stable integer codes.
- eval
- The evaluation core — everything that turns
.ssabdata plus a time into drawable state. - ffi
- The C ABI — how every non-Rust Player talks to the runtime.
- interpolate
- Interpolation math for SpriteStudio animation curves.
- runtime
- The generated bindings of
fbs/framedata.fbsandfbs/effect_draw_plan.fbs. cbindgen:ignore - types
- POD return types shared across the runtime API surface.
- web
- Wasm bindings for ssruntime.
Structs§
- Animation
Metadata - One animation of a pack: its name hash, frame range, rate and canvas, and the tables playing it reads.
- Animation
Resource - A parsed
.ssab. It is read-only, and can back any number ofContexts. - Context
- The playback state of one animated object: a stack of tracks, each playing an
animation of the bound resource, layered onto the setup pose. Bind a resource
with
Self::bind_resourceand select an animation withSelf::setup_animationbefore playing. - Effect
Context - Effect
Slot - High-level effect slot: wraps
EffectContextwith the per-slot lifecycle state. Callers resolve the active effect event externally (viaContext::get_active_effect_event) and feed it tostep()along with frame timing —stepowns transition detection, accumulator, dead-effect skip, simulator update, and draw-plan build in one call. - Instance
Slot - High-level instance-child slot: tracks the per-slot transition state.
step()resolves labels against the child runtime context, configures the child’s playback (animation section, loop, direction), and advances the child’s frame — leaving only the C++/host-sideplay()event sink and the redraw call to the caller. - Ssab
Data - The bytes of an
.ssab, owned or borrowed from the caller. - Ssab
Resource - A thread-safe, shared resource containing SSAB data and its parsed metadata.
Enums§
- Track
Blend - How a track folds onto the pose the tracks below it produced.
- Track
Sync - How the animation laid on a track keeps time with track 0. Sync means the
normalised phase: how far through its section an animation stands, from
0.0at the section start towards1.0at its end, so animations of different lengths line up by proportion rather than by frame.
Functions§
- fnv1a_
hash_ str - The FNV-1a hash of
text, which is what the.ssabstores for a name and the_by_hashcalls take.