Skip to content

The quick creator and the wardrobe picker

Two ready-made screens a game opens and gets an avatar back from. The quick creator is the fast path: eight generated looks in a line-up, pick one, change one thing (hair, hair colour, skin, top), done. The wardrobe picker dresses the player's own avatar for this match, from their wardrobe or from the catalogue under the game's content filter, with a live try-on of whatever has focus. The calls are in the C reference: player screens. C++ calls them as they are and Rust through its raw layer (sona_sys). The screens draw their avatar views through a renderer of your device, which C# keeps to itself and Python does not have, so those two cannot show them.

Gamepad first; keyboard, mouse and touch drive the same actions. Every focusable thing on screen has a role, a state and a spoken label, and the screen keeps a queue of what a screen reader should say.

The sample below draws both screens and writes their pictures: quick-looks.png, quick-looks-tall.png, quick-tweak.png, quick-wardrobe.png and quick-wardrobe-tall.png.

Which one to use

There are two forms of the quick creator and the wardrobe picker, on purpose:

  • The editor module (sona_editor, Player editor, SONA_EDITOR_MODE_QUICK and _WARDROBE) draws everything itself in 360sona's look, input to finished avatar. Use it when the game has no UI toolkit of its own to spare, or wants the screens to look like 360sona.
  • The core screens (this page; C reference: player screens) draw nothing: they hand the host a list of nodes (role, rect, label, state) and take actions back, so an engine draws them in its own UI (Unity UI Toolkit, Unreal UMG, Godot Controls) and they look like the game. The engine components are built on these.

Both give the same looks for the same seed and the same manifest back (the quick_editor test holds them together).

How a screen works

A screen does not draw itself. It lays itself out in the host's pixels and lists what to draw as nodes: the background, titles, text, buttons, look tiles, item tiles, colour swatches, setting rows, tabs, the live avatar view, button prompts and a status line, in paint order. A host with its own UI (an engine's canvas, Dear ImGui, a web overlay) draws those nodes with its own widgets. The avatars in the tiles and the live view are avatars of the host's ctx that sona_draw never draws: sona_screen_view_draw (into a target) or sona_screen_view_snapshot (into pixels) draws one alone, framed for the node's size.

sona_quick_options qo;
sona_screen *s;
sona_quick_defaults(&qo);
qo.catalogue = cat;                 /* sona_catalogue_load */
qo.filter = my_content_filter;      /* optional: 0 leaves an item out */
sona_quick_open(ctx, &qo, &s);
sona_screen_layout(s, 1920, 1080);

for (;;) {                          /* each frame */
  /* the host's input, as actions: */
  sona_screen_event e = { sizeof e, SONA_INPUT_PRESS, SONA_ACT_ACCEPT,
      SONA_INPUT_FROM_GAMEPAD };
  /* and SONA_INPUT_RELEASE when the button comes up */
  sona_screen_input(s, &e);
  sona_update(ctx, dt, &game_view, NULL);
  if (sona_screen_update(s, dt) != SONA_SCREEN_RUNNING) break;
  n = sona_screen_nodes(s, nodes, 256);
  for (i = 0; i < n; i++) {
    draw_node(&nodes[i]);           /* the host's UI */
    if (nodes[i].view >= 0) sona_screen_view_draw(renderer, s,
        nodes[i].view, target_for(&nodes[i]), &opts);
  }
  while (sona_screen_announcement(s, line, sizeof line)) speak(line);
}
/* the player's avatar: save it, send it, add it */
sona_screen_result(s, manifest);
sona_screen_destroy(s);             /* before sona_close */
sona_quick_options qo;
sona_quick_defaults(&qo);
qo.catalogue = cat.raw();            // sona::Catalogue
qo.filter = my_content_filter;       // optional: 0 leaves an item out
sona_screen *s = nullptr;
sona_quick_open(ctx.raw(), &qo, &s);
sona_screen_layout(s, 1920, 1080);

std::vector<sona_screen_node> nodes(256);
char line[256];
for (;;) {                           // each frame
  // the host's input, as actions:
  sona_screen_event e = { sizeof e, SONA_INPUT_PRESS, SONA_ACT_ACCEPT,
      SONA_INPUT_FROM_GAMEPAD };
  // and SONA_INPUT_RELEASE when the button comes up
  sona_screen_input(s, &e);
  ctx.update(dt, &game_view);
  if (sona_screen_update(s, dt) != SONA_SCREEN_RUNNING) break;
  uint32_t n = sona_screen_nodes(s, nodes.data(), (uint32_t)nodes.size());
  for (uint32_t k = 0; k < n; k++) {
    draw_node(nodes[k]);             // the host's UI
    if (nodes[k].view >= 0) sona_screen_view_draw(r.raw(), s, nodes[k].view,
        target_for(nodes[k]), &opts);
  }
  while (sona_screen_announcement(s, line, sizeof line)) speak(line);
}
uint8_t result[SONA_MANIFEST_BYTES];
// the player's avatar: save it, send it, add it
sona_screen_result(s, result);
sona_screen_destroy(s);              // before the context closes
// Not in C#: the screens draw their avatar views through the renderer
// (sona_screen_view_draw),
// and SonaRenderer keeps its native handle to itself. Use C++ or Rust for
// these screens, or the
// full editor (SonaEditor), which gives its UI and result to C#.
use sona::sona_sys::*;

let mut qo: sona_quick_options = unsafe { std::mem::zeroed() };
unsafe { sona_quick_defaults(&mut qo) };
qo.catalogue = cat.raw();
qo.filter = Some(my_content_filter);  // optional: None leaves nothing out
let mut s = std::ptr::null_mut();
let mut nodes: Vec<sona_screen_node> = vec![unsafe { std::mem::zeroed() }; 256];
let mut line = [0 as std::os::raw::c_char; 256];
let mut result = [0u8; 1000];
unsafe {
    sona_quick_open(ctx.raw(), &qo, &mut s);
    sona_screen_layout(s, 1920, 1080);
    loop {                                                     // each frame
        // the host's input, as actions
        let mut e: sona_screen_event = std::mem::zeroed();
        e.size = std::mem::size_of::<sona_screen_event>() as u32;
        // and SONA_INPUT_RELEASE when it comes up
        e.type_ = SONA_INPUT_PRESS;
        e.action = SONA_ACT_ACCEPT;
        e.from = SONA_INPUT_FROM_GAMEPAD;
        sona_screen_input(s, &e);
        ctx.frame()?.update(dt, Some(view))?;
        if sona_screen_update(s, dt) != SONA_SCREEN_RUNNING { break; }
        let n = sona_screen_nodes(s, nodes.as_mut_ptr(),
            nodes.len() as u32) as usize;
        for node in &nodes[..n] {
            // the host's UI
            draw_node(node);
            if node.view >= 0 { sona_screen_view_draw(r.raw(), s, node.view,
                target_for(node), std::ptr::null()); }
        }
        while sona_screen_announcement(s, line.as_mut_ptr(),
            line.len()) != 0 { speak(&line); }
    }
    // the player's avatar: save it, send it, add it
    sona_screen_result(s, result.as_mut_ptr());
    // before the context closes
    sona_screen_destroy(s);
}
# Not in Python: the screens draw their avatar views through a renderer of
# your device
# (sona_screen_view_draw), and the package draws headless pictures only. Use
# C, C++ or Rust.

sona_screen_update answers SONA_SCREEN_RUNNING, _DONE, _CANCELLED (B on the line-up, or the wardrobe's B: the result is then the avatar it started with) or _FINE_TUNE (Y: open the full editor on the result).

The quick creator

The looks. Each set of eight is diverse by construction, not by luck: every look has its own style (casual, smart, sporty, outdoor, summer, street, dressy, cosy), its own colour story (three colours its colourable clothes take), its own skin tone (the ten tones are cut into one band per look, light to deep, and each look takes a tone from its own band, so a set always runs from the lightest band to the deepest), its own hair colour (eight of sixteen) and its own body shape (eight weights and eight heights), and men and women alternate (four each in a set of eight, one apart in an odd set; or all one body with body). Clothes come from what the catalogue's editor offers that body, chosen by the item's type for the style (a hoodie and cargo trousers for street, a dress or a suit for dressy), under the host's filter; hair and the face (eyes, brows, mouth, nose, chin, ears) are drawn from the same offer. Faces stay clean on every skin: the starter's stubble, eye shadow and face paint come off, eyes and brows are the tinted ones (no blank eyes, no "no eyebrows"), the ears are rounded ones (no fantasy, elven or spiked ears), and the lips take a natural colour from the skin tone (dressier looks for women sometimes wear lipstick); changing the skin on the next screen moves natural lips with it. The same seed and catalogue always give the same looks, X makes the next set (sona_quick_look(&o, shuffle, index, manifest) gives any of them without a screen), and a look whose items turn out to be missing from the sources is re-rolled up to four times (then the screen shows a look sona_quick_look does not give; a filter that keeps only what the sources hold, as the sample's does, leaves nothing to re-roll).

The flow. The line-up shows the eight as full figures; the one with focus performs (wave, cheer, clap...). A picks it and moves to one screen of four rows: Hair (every hair style offered that body), Hair colour (sixteen swatches), Skin (ten swatches), Top (every top offered that body). Up and down choose the row, left and right change it, and the live avatar rebuilds (at most every 0.12 s while a direction is held, the old figure staying up until the new one is ready) and checks its new hat or top. A is done.

Action Gamepad; keyboard In the line-up; changing one thing
SONA_ACT_LEFT, _RIGHT d-pad, left stick; arrows move between looks; change the row's value
SONA_ACT_UP, _DOWN d-pad; arrows rows of looks (tall layout); choose the row
SONA_ACT_ACCEPT A; Enter, Space pick this look; done
SONA_ACT_X X; F2 shuffle: eight new looks; surprise me: a random value for the row
SONA_ACT_Y Y; F3 fine-tune this look in the full editor; fine-tune
SONA_ACT_BACK B; Esc cancel (unless SONA_QUICK_NO_BACK); back to the line-up
SONA_ACT_MENU Start; F10 pick this look and finish; done
SONA_ACT_PREV_TAB, _NEXT_TAB LB, RB; Page Up, Page Down move between looks; choose the row

Mouse and touch: hovering a look gives it focus; a click or tap picks it. On the second screen a click on a row selects it, the arrows step it, a swatch sets it, Done finishes, the wheel steps the row, and dragging the avatar turns it (the right stick does too: SONA_INPUT_TURN). The button prompts are buttons as well.

The shortest path is two presses (A, A: the first look as it comes). The sample's scripted path, pick the third look and change its top, is eight.

The wardrobe picker

sona_wardrobe_options wo;
sona_wardrobe_defaults(&wo);
/* the player's own, SONA_MANIFEST_BYTES; only clothes change */
wo.manifest = my_avatar;
wo.catalogue = cat;
/* the player's wardrobe; NULL: the catalogue's items for this body */
wo.owned = owned; wo.owned_count = n;
/* saved outfits, first tab */
wo.outfits = saved_outfits; wo.outfit_count = 3; wo.outfit_names = names;
wo.filter = my_content_filter;
wo.title = "Dress for the match";
sona_wardrobe_open(ctx, &wo, &s);
sona_wardrobe_options wo;
sona_wardrobe_defaults(&wo);
// the player's own, SONA_MANIFEST_BYTES; only clothes change
wo.manifest = my_avatar;
wo.catalogue = cat.raw();
// the player's wardrobe
wo.owned = owned.data(); wo.owned_count = (uint32_t)owned.size();
// saved outfits, first tab
wo.outfits = saved_outfits; wo.outfit_count = 3; wo.outfit_names = names;
wo.filter = my_content_filter;
wo.title = "Dress for the match";
sona_screen *s = nullptr;
sona_wardrobe_open(ctx.raw(), &wo, &s);
// Not in C#: as the quick creator above, the wardrobe draws its avatar
// views through the renderer.
use sona::sona_sys::*;

let mut wo: sona_wardrobe_options = unsafe { std::mem::zeroed() };
unsafe { sona_wardrobe_defaults(&mut wo) };
// the player's own, 1000 bytes
wo.manifest = my_avatar.as_ptr();
wo.catalogue = cat.raw();
wo.owned = owned.as_ptr(); wo.owned_count = owned.len() as u32;
// the player's wardrobe
// saved outfits
wo.outfits = saved_outfits.as_ptr(); wo.outfit_count = 3;
wo.outfit_names = names.as_ptr();
wo.filter = Some(my_content_filter);
wo.title = b"Dress for the match\0".as_ptr() as *const std::os::raw::c_char;
let mut s = std::ptr::null_mut();
unsafe { sona_wardrobe_open(ctx.raw(), &wo, &mut s) };
# Not in Python: as the quick creator above, the wardrobe draws its avatar
# views through a renderer.

Tabs: Outfits (when there are any), Tops, Bottoms, Shoes, Hats, Costumes (unless SONA_WARDROBE_NO_COSTUMES) and Extras (glasses, gloves, wristwear, rings, earrings); a tab with nothing in it is left out. With an owned list the stock items come too (SONA_WARDROBE_STOCK, on by default). Each tab lists stock items first, then by name. Every tile on screen, and the row after, shows the item alone on the grey stand-in (sona_item_preview_add), made while it is near the screen and dropped when the cache of 56 needs room.

The live avatar is the player's own, turnable. The focused item goes on it after a fixed 0.18 s (the try-on), so moving through a row shows each one worn; A keeps it (the avatar checks it: shirt, trousers, shoes or hat), Y takes it off, X puts back what the screen opened with, Start is done and B cancels. A saved outfit puts its clothes on the player: their own clothes come off first, and body, face, hair and colours stay. A tile whose preview drew nothing (its file is in no source) is marked not available and is never tried on.

Action Gamepad; keyboard Wardrobe
directions d-pad, left stick; arrows move in the grid (it scrolls)
SONA_ACT_PREV_TAB, _NEXT_TAB LB, RB; Page Up, Page Down tabs
SONA_ACT_ACCEPT A; Enter wear it
SONA_ACT_Y Y; F3 take it off
SONA_ACT_X X; F2 back to what it opened with
SONA_ACT_MENU Start; F10 done
SONA_ACT_BACK B; Esc cancel

Mouse and touch: hover tries on, a click wears (or takes off what is worn), the wheel scrolls, tabs are clickable.

Drawing the nodes

sona_screen_nodes returns, in paint order:

Role What to draw Fields
SCREEN the background over the whole target label: the screen's name
TITLE, TEXT, STATUS text text, text_size; STATUS is a live region
LOOK a look tile: draw view into it, text as its caption index, count; value 1 for the focused one
ITEM an item tile: view in the box above a caption of text_size x 1.9 WORN, DISABLED (not available)
VIEW the live avatar LOADING while a change builds
ROW a setting: text its name, detail its value index of count options
SWATCH a colour, child of its row colour; SELECTED
BUTTON a button (Done, the row arrows) action
TAB a tab SELECTED
HINT a button prompt: detail the glyph ("A", "Enter"; NULL for mouse and touch), text what it does action
SCROLLBAR the grid's position value 0..1

States: FOCUSED (draw the focus ring unless HIDDEN_RING, set while the pointer drives), SELECTED, DISABLED, HOVERED, LOADING (no picture, or a newer one on its way: draw a placeholder or keep the old picture), PRESSED, FOCUSABLE, WORN. Boxes are in the host's pixels from sona_screen_layout: the layout is designed on 1280 x 720 (or 720 x 1280 when the target is taller than wide), scaled to fit and centred, so a 4:3 or 21:9 target gets bars of background. theme.scale scales on top, and SONA_THEME_LARGE_TEXT scales text by 1.3.

The tiles' cameras: a look or the live view frames the whole figure to the node's height from its bounding sphere (narrow tiles let a performing arm leave the picture); an item tile uses sona_item_preview_view. sona_screen_view_camera gives the camera for hosts that draw through the data API.

Accessibility

  • Every focusable node has a label ("Look 3 of 8. Street. Woman, deep brown skin, black hair. Grey hoodie, Cargo trousers, Trainers"; "Hair: Raised front, 26 of 90"; "Blue full-zip hoodie, worn, 3 of 312"), a role and its place (index, count). Exactly one focusable node has focus at any time.
  • sona_screen_announcement queues what changed for a screen reader: the screen's purpose and keys on open, every focus move, every value change, what was worn or taken off, done and cancelled. A host passes the lines to the platform's speech or accessibility API.
  • SONA_THEME_CONTRAST and SONA_THEME_HIGH_CONTRAST: black, white and yellow, a 5-pixel focus ring, outlines on every control. SONA_THEME_REDUCE_MOTION: no performances on focus and no checks after a change. SONA_THEME_LARGE_TEXT.
  • The prompts follow the last device used: gamepad glyphs, key names, or plain buttons for mouse and touch.

Theming

sona_screen_theme_defaults(&t, SONA_THEME_DARK | _LIGHT | _CONTRAST), then any field: background, panel, panel_raised, text, text_dim, accent, accent_text, focus, warning (0xAARRGGBB), scale, corner, and a font name for the host's own drawer. The dark and light palettes are the editor module's, so the screens look the same inside it and alone. The layout uses only scale, corner and the flags; the colours are for the drawer.

With the editor module

The full editor (include/sona_editor.h, the player editor) is an optional module that draws its own UI, and it has a quick mode and a wardrobe mode of its own: two drawn implementations of the same two flows. These screens are the core library's, for hosts that draw with their own UI or use no editor module; they do not run inside the editor. Where the two meet:

  • Looks. The editor's look hook takes the quick creator's generator, so its line-up shows the quick creator's looks: the editor's first seed is the creator's seed, and each X adds one to the editor's seed where the creator counts a shuffle.

    /* catalogue, filter, seed set */
    typedef struct quick_hook {
      sona_quick_options o;
      uint64_t first;
    } quick_hook;
    static int quick_looks(void *user, uint64_t seed, uint32_t index,
        uint8_t manifest[SONA_MANIFEST_BYTES]) {
      quick_hook *h = (quick_hook *)user;
      return sona_quick_look(&h->o, (uint32_t)(seed - h->first), index,
          manifest) == SONA_OK;
    }
    /* sona_editor_options: .seed = h.first = h.o.seed, .look =
       quick_looks, .look_user = &h, the same .filter */
    

    Each call builds the generator's lists from the catalogue again, so every call is a pass over the catalogue. - Filters. sona_item_filter_fn and sona_editor_filter_fn have one signature: the same function and user pointer serve both, and the content filter module plugs into either. - Fine-tune. SONA_SCREEN_FINE_TUNE hands the look to the full editor: open it with start set to sona_screen_result. - Input. The editor's buttons map to these actions one to one: PAD_A ACCEPT, PAD_B BACK, PAD_X X, PAD_Y Y, PAD_LB and PAD_RB the tabs, PAD_START MENU, the d-pad and the left stick the directions, the right stick's x SONA_INPUT_TURN; its keys the same (Enter, Escape, F2, F3, Page Up and Down, F10). - Theme. sona_editor_theme to sona_screen_theme: background, panel, raised to panel_raised, text, text_dim, accent, accent_text, focus, corner_radius to corner, scale. - Accessibility. The editor's sona_editor_control (role, flags, rect, index and count, label) and these nodes carry the same facts; the announcement queues say the same kind of line.

The sample

The quick_creator sample makes an avatar and dresses it, end to end, on the library's headless device: a scripted gamepad goes through the quick creator (pick the third look, change its top, done) and then the wardrobe picker on the avatar it made (RB to tops, try on two, wear one, RB, wear a bottom, Start), at a player's pace of one press every 0.45 s. It prints the presses, the time from open to done and what the screens cost a frame, writes screenshots with the avatars from sona_screen_view_snapshot and the credit badge once, and prints the base64 the game gets back. Given --dir, its filter keeps the items whose files are in that folder, as a host's filter would.

quick_creator --catalogue sona-catalogue.bin --out shots/quick- [--check]
              [--device auto|gpu|software] [--seed N] [--theme
                  dark|light|contrast] [--pace 0.45]
              [--script "RRADDDRA"] [--minimal]

Measured

The sample's scripted gamepad over the full corpus with the full catalogue, at the sample's pace (--pace 0.45). Open to done leaves out the sample's screenshot pauses, and the shortest path waits for the looks to be ready. Each run also plays the wardrobe picker's script (RB R R A RB R A Start). On an RTX 4090 machine, the median of three runs each:

Path Presses; open to done Avatars ready after; the screen, ms a frame
Quick creator, shortest (A, A: the first look as it comes) 2; 1.54 s 0.62 s; 0.009 ms
Quick creator, pick the third look and change its top (R R A D D D R A) 8; 4.25 s 0.62 s; 0.011 ms
Wardrobe picker, try on two tops, wear one and a bottom 8; 5.74 s 0.12 s; 0.035 ms

So a player who knows what they want makes an avatar in a few seconds of input. A game draws the screen's avatars into its own frame with sona_screen_view_draw; the screens do not touch the frame of the game's own avatars.

Limits

  • There are two drawn quick creators and wardrobe pickers: these screens and the editor module's own modes (the player editor). They share the look generator; each draws its own screens.

  • Strings are English only; a host that needs other languages draws its own text from the nodes' roles and values.

  • No sounds: the host can play its own on the announcements or on sona_screen_stats changes.
  • The look generator's styles are chosen by item type, so a style can show a branded or novelty item that fits the type; a content filter is the host's control over that.
  • No engine component (Unity, Unreal, Godot) draws the nodes with the engine's UI; the sample's CPU drawer and the editor module draw them.

This page as Markdown · All the docs as one file (llms-full.txt)