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

> [!TIP]
>
> **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.**

**Rust**

```rust
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);
```

**C**

```c
ss_scene_update(scene, delta_seconds);   /* every player this scene owns */
ss_scene_render(scene);                  /* one pass, then present */
```

**JavaScript**

```js
surface.frame(dt);   // updates every player on this canvas and draws them in one pass
```

**Bevy**

```rust
// 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](<https://github.com/cri-middleware/SSPlayerForWgpu/blob/main/ROADMAP.md>) lists what is planned.

|  | Rust | C | JavaScript | Bevy |
| --- | :---: | :---: | :---: | :---: |
| [Load, both export modes, sibling packs](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/loading/index.md>) | ✅ | ✅ | ✅ | ✅ |
| [Transport: play / pause / resume / stop / seek](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/playback/index.md>) | ✅ | ✅ | ✅ | ✅ |
| [Loop count, sections, direction, sub-frame](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/playback/index.md>) | ✅ | ✅ | ✅ | ✅ |
| [Events: user data, signal, audio](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/events/index.md>) | ✅ | ✅ | ✅ | ✅ |
| [Part overrides: visibility, cell, colour](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/part-overrides/index.md>) | ✅ | ✅ | ✅ | — |
| [Texture replacement: a whole cell map](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/texture-replacement/index.md>) | ✅ | ✅ | ✅ | ✅ |
| [Part transform lookup](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/part-overrides/index.md#reading-a-parts-transform>) | ✅ | ✅ | ✅ | — |
| [Group alpha: a fade as one layer](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/part-overrides/index.md#whole-character-tint-and-alpha>) | ✅ | ✅ | ✅ | ✅ |
| [Crowds: one character at many placements](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/crowds/index.md>) | ✅ | ✅ | ✅ | ✅ |
| [Motion blending: tracks, crossfade, sources](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/motion-blending/index.md>) | ✅ | ✅ | ✅ | ✅ |
| [Masks — stencil](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/masks/index.md>) | ✅ | ✅ | ✅ | — |
| [Masks — coverage bitmap](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/masks/index.md>) | ✅ | — | — | ✅ |
| [Supplying your own textures](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/loading/index.md#supplying-textures-yourself>) | ✅ | ✅ | ✅ | — |
| [Device-loss recovery](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/device-loss/index.md>) | ✅ | ✅ | ✅ | ✅ |
| [Frame statistics](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/performance/index.md>) | ✅ | ✅ | ✅ | — |
| Drawing into a render pass you own | ✅ | — | — | ✅ |

On Bevy, [motion blending](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/motion-blending/index.md>) 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**:

**Rust**

```rust
player.set_animation("attack")?;  // builds the instance tree — the allocating step
player.play();                    // allocation-free transport
```

**C**

```c
ss_player_set_animation(player, "attack");
ss_player_play(player);
```

**JavaScript**

```js
player.setAnimation('attack');
player.play();
```

**Bevy**

```rust
// 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](<https://cri-middleware.github.io/SSPlayerForWgpu/guide/playback/index.md>) for what each verb does — in particular why `play()` is **not** how you lift a `pause()`.
