Skip to main content

Crate ssruntime

Crate ssruntime 

Source
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:

FaceEntry pointConsumer
Rust (rlib)Context, AnimationResourceRust-native Players, this crate’s own tests
C ABI (staticlib / cdylib, emitted by ssruntime-ffi)ffi — ss_runtime_*, header generated by cbindgenUnity, 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

§Feature flags

FeaturePurpose
ffiC-API exports. For ssruntime-ffi, not for Rust dependents — see below.
libc_alloclibc::malloc/free-backed #[global_allocator] for no_std FFI builds (mobile / desktop).
wasm_allocdlmalloc-backed #[global_allocator] for no_std WASM builds.
emscripten_allocEmscripten libc-backed #[global_allocator] for Emscripten no_std builds.
custom_allocRoutes 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-handlerProvides #[panic_handler] for no_std FFI builds.
webwasm-bindgen bindings for JS/TS interop. Same caveat as ffi.
stdOpt-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, .ssab is 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 .ssab is undefined behaviour; that precondition is why AnimationResource::new and SsabResource::new are unsafe fn.
  • Borrowed buffers are not owned. One AnimationResource may back several Contexts, 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 .ssab byte buffer behind ss_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_copy trades memory for not having to.

§Further reading

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 .ssab data 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.fbs and fbs/effect_draw_plan.fbs. cbindgen:ignore
types
POD return types shared across the runtime API surface.
web
Wasm bindings for ssruntime.

Structs§

AnimationMetadata
One animation of a pack: its name hash, frame range, rate and canvas, and the tables playing it reads.
AnimationResource
A parsed .ssab. It is read-only, and can back any number of Contexts.
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_resource and select an animation with Self::setup_animation before playing.
EffectContext
EffectSlot
High-level effect slot: wraps EffectContext with the per-slot lifecycle state. Callers resolve the active effect event externally (via Context::get_active_effect_event) and feed it to step() along with frame timing — step owns transition detection, accumulator, dead-effect skip, simulator update, and draw-plan build in one call.
InstanceSlot
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-side play() event sink and the redraw call to the caller.
SsabData
The bytes of an .ssab, owned or borrowed from the caller.
SsabResource
A thread-safe, shared resource containing SSAB data and its parsed metadata.

Enums§

TrackBlend
How a track folds onto the pose the tracks below it produced.
TrackSync
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.0 at the section start towards 1.0 at 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 .ssab stores for a name and the _by_hash calls take.