Skip to content

Scopes and names

Everything from here on is one text for four faces. The vocabulary differs; the model does not. This page is the bridge โ€” read it once and every other Guide page reads in your language.

Pick your language once

Code below appears in tabs. The one you pick is remembered for every page on this site, so you never choose twice.

Three scopes

The player splits its state by how long the thing it holds stays useful, not by object hierarchy.

flowchart TD
    dev["Device scope<br/>pipelines ยท sampler ยท atlas textures"]
    tgt1["Target scope<br/>projection ยท this frame's geometry"]
    tgt2["Target scope"]
    p1["Character"]
    p2["Character"]
    p3["Character"]

    dev --> tgt1
    dev --> tgt2
    tgt1 --> p1
    tgt1 --> p2
    tgt2 --> p3
Scope Holds You keep one per
Device pipelines, bind group layouts, the sampler, atlas textures GPU device โ€” never one per window
Target the projection, the frame's geometry arena, the draw list thing you draw into: a window, a canvas, an offscreen texture
Character the playback tree, transform, draw order, visibility, alpha character on screen

The consequence that matters in practice: a character holds no GPU resource at all. Ten characters in one target share one atlas upload, one set of pipelines and one render pass. A second character on screen adds its playback tree and its own parts to the frame, and no pass, pipeline or atlas upload of its own.

The same three, named per face

Scope Rust C JavaScript Bevy
Device SSRenderer (inside ss_scene_t) SsContextWeb (inside the plugin)
Target SSScene ss_scene_t SsSurfaceWeb (the camera's view)
Character SSPlayer ss_player_t SsPlayerWeb an entity with SsPlayer

Two asymmetries change what is cheap:

  • C fuses the device and target scopes into ss_scene_t. That handle is a whole graphics stack built on the window you named โ€” so one window is one device. Two windows in one C++ application are two devices. Two characters in one window are one device, which is what the ss_scene_t / ss_player_t split is for.
  • JavaScript keeps them apart, so a page with eight <ss-player-webgpu> elements still builds exactly one GPUDevice: SsContextWeb is the page, SsSurfaceWeb is a canvas.

The frame, in each language

The shape is identical: advance everything, then draw everything, once.

scene.update(&mut renderer, &device, &queue, delta_secs, &mut [&mut a, &mut b]);
scene.encode_offscreen(&mut renderer, &device, &mut encoder); // coverage masks, group-alpha layers
let mut rpass = encoder.begin_render_pass(&descriptor);
scene.draw(&renderer, &mut rpass);
ss_scene_update(scene, delta_seconds);   /* every player this scene owns */
ss_scene_render(scene);                  /* one pass, then present */
surface.frame(dt);   // updates every player on this canvas and draws them in one pass
// Nothing. The plugin's systems run in Bevy's Core2d MainPass, after
// main_transparent_pass_2d, once per frame.

Pass every character of a target through one update. A second update on the same target starts a new frame and replaces what the first one built, so only the last call's characters are drawn; a character handed to two targets' updates in one frame advances twice.

Draw order inside a target is set_order, ascending. It is a plain integer, not a tree.

What each face can do

The library is one; the faces expose different amounts of it. A dash is not a promise. The coverage row is a boundary by design: the C and JavaScript faces own their render pass and its stencil, and coverage exists only for a pass with no stencil to lend. The ROADMAP lists what is planned.

Rust C JavaScript Bevy
Load, both export modes, sibling packs โœ… โœ… โœ… โœ…
Transport: play / pause / resume / stop / seek โœ… โœ… โœ… โœ…
Loop count, sections, direction, sub-frame โœ… โœ… โœ… โœ…
Events: user data, signal, audio โœ… โœ… โœ… โœ…
Part overrides: visibility, cell, colour โœ… โœ… โœ… โ€”
Texture replacement: a whole cell map โœ… โœ… โœ… โœ…
Part transform lookup โœ… โœ… โœ… โ€”
Group alpha: a fade as one layer โœ… โœ… โœ… โœ…
Crowds: one character at many placements โœ… โœ… โœ… โœ…
Motion blending: tracks, crossfade, sources โœ… โœ… โœ… โœ…
Masks โ€” stencil โœ… โœ… โœ… โ€”
Masks โ€” coverage bitmap โœ… โ€” โ€” โœ…
Supplying your own textures โœ… โœ… โœ… โ€”
Device-loss recovery โœ… โœ… โœ… โœ…
Frame statistics โœ… โœ… โœ… โ€”
Drawing into a render pass you own โœ… โ€” โ€” โœ…

On Bevy, motion blending is driven by the SsTrackCommand message and read back from the SsTrackState component, since the playback trees live in the render world.

Two calls, not one: selecting and starting

On Rust, C and JavaScript, choosing an animation and starting it are separate:

player.set_animation("attack")?;  // builds the instance tree โ€” the allocating step
player.play();                    // allocation-free transport
ss_player_set_animation(player, "attack");
ss_player_play(player);
player.setAnimation('attack');
player.play();
// Setting SsPlayer::animation rebuilds the tree and, while SsPlayback::playing is true
// (the default), plays it from the head; playing = false holds the first frame.

That split is deliberate: switching motions is frequent and must not carry an allocation you did not ask for, or a promise you have to await. See Playback and transport for what each verb does โ€” in particular why play() is not how you lift a pause().