Skip to content

C API: Avatar state, network sync and replays

An avatar's whole state as a blob put back exactly; a stream that carries one avatar to a receiver in a few bytes a tick, shown on a puppet with the same pose bits on every receiver fed the same packets; and recordings played at any time, forwards or back. The guide, with what a state holds, the formats and the measured sizes, is State, network sync, replays. All of it runs on the owner thread.

Structs (no pointers: one layout for 4- and 8-byte pointers): sona_state_info (56 bytes) {size, version, has_look, parts, clock, reserved[8]}; sona_state_status (40) {size, mode, pending, missing, applied, reserved[5]}; sona_net_options (48) {size, tick_hz, history, full_after, reserved[8]}; sona_net_look (1092) {size, version, kind, manifest[1000], id[64], reserved[4]}; sona_net_stats (64) {size, packets, bytes, full, newest, oldest, last_bytes, acked, reserved[8]}; sona_record_options (48) {size, tick_hz, keyframe_ticks, keep_seconds, reserved[8]}; sona_replay_info (60) {size, tracks, tick_hz, first_tick, last_tick, frames, seconds, reserved[8]}. sona_net_sender, sona_net_receiver, sona_recorder and sona_replay are opaque. Flags and codes: SONA_STATE_NO_LOOK; SONA_STATE_PART_FADE, _LAYERS, _OVERRIDES, _IK, _IDLE, _QUEUE; SONA_STATE_MISSING_CLIP, _BLEND, _MACHINE, _GROUND, _POSE, _LOOK; SONA_STATE_LIVE, _WAITING, _PUPPET; SONA_NET_LOOK_NONE, _MANIFEST, _ID.

sona_avatar_save_state

sona_result sona_avatar_save_state(sona_avatar *a, uint32_t flags,
                                   uint8_t **out, size_t *out_len);
Parameter and type Meaning
a
sona_avatar *
The avatar (required)
flags
uint32_t
Option bits for the call; 0: none (0: none)
out
uint8_t **
Receives the bytes; free them with sona_free (required)
out_len
size_t *
Receives how many bytes *out holds (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED, SONA_E_NOT_READY, SONA_E_MEMORY (what each means).

Example (also in Avatar state, network sync and replays):

uint8_t *blob; size_t n;
/* 0.4 to 2 KB with the manifest; sona_free */
sona_avatar_save_state(a, 0, &blob, &n);

sona_avatar *b;
/* a new avatar with the blob's look and state */
sona_avatar_add_state(other_ctx, blob, n, NULL, &b);
/* or, into an avatar that already has the look:
   sona_avatar_load_state(b, blob, n); */

The blob of a READY avatar's state, freed with sona_free; SONA_STATE_NO_LOOK leaves the manifest out. SONA_E_NOT_READY before READY, SONA_E_ARGUMENT for an unknown flag.

sona_avatar_load_state

sona_result sona_avatar_load_state(sona_avatar *a, const void *blob,
                                   size_t len);
Parameter and type Meaning
a
sona_avatar *
The avatar (required)
blob
const void *
The bytes of a saved state (required)
len
size_t
How many bytes there are

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED, SONA_E_UNSUPPORTED, SONA_E_MEMORY, SONA_E_CORRUPT (what each means).

Example (also in Avatar state, network sync and replays):

uint8_t *blob; size_t n;
/* 0.4 to 2 KB with the manifest; sona_free */
sona_avatar_save_state(a, 0, &blob, &n);

sona_avatar *b;
/* a new avatar with the blob's look and state */
sona_avatar_add_state(other_ctx, blob, n, NULL, &b);
/* or, into an avatar that already has the look:
   sona_avatar_load_state(b, blob, n); */

Puts a saved state on a at the next sona_update once it is READY and the clips the state needs are loaded; until then the avatar holds still (SONA_STATE_WAITING). Afterwards the same updates give the same pose bits as the saved avatar would have. A look that differs is reported (SONA_STATE_MISSING_LOOK), not refused. SONA_E_CORRUPT, SONA_E_UNSUPPORTED for a newer format. Ends puppet mode.

sona_avatar_add_state

sona_result sona_avatar_add_state(sona_ctx *ctx, const void *blob,
                                  size_t len, const sona_add_options *opts,
                                  sona_avatar **out);
Parameter and type Meaning
ctx
sona_ctx *
The context (required)
blob
const void *
The bytes of a saved state (required)
len
size_t
How many bytes there are
opts
const sona_add_options *
The options, a sona_add_options (required)
out
sona_avatar **
Receives the new avatar (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED, SONA_E_UNSUPPORTED, SONA_E_MEMORY, SONA_E_CORRUPT (what each means).

Example (also in Avatar state, network sync and replays):

uint8_t *blob; size_t n;
/* 0.4 to 2 KB with the manifest; sona_free */
sona_avatar_save_state(a, 0, &blob, &n);

sona_avatar *b;
/* a new avatar with the blob's look and state */
sona_avatar_add_state(other_ctx, blob, n, NULL, &b);
/* or, into an avatar that already has the look:
   sona_avatar_load_state(b, blob, n); */

A new avatar with the blob's look, then sona_avatar_load_state. opts gives the visibility and priority (its clip is ignored). SONA_E_ARGUMENT for a blob without a look.

sona_state_info_get

sona_result sona_state_info_get(const void *blob, size_t len,
                                sona_state_info *out,
                                uint8_t manifest[SONA_MANIFEST_BYTES]);
Parameter and type Meaning
blob
const void *
The bytes of a saved state (required)
len
size_t
How many bytes there are
out
sona_state_info *
Receives the sona_state_info (required)
manifest
uint8_t [SONA_MANIFEST_BYTES]
The manifest's 1,000 bytes, changed in place (NULL allowed (below))

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_UNSUPPORTED, SONA_E_MEMORY, SONA_E_CORRUPT (what each means).

What a blob holds, without a ctx; manifest (may be NULL) gets the look when there is one.

sona_avatar_state_status

sona_result sona_avatar_state_status(const sona_avatar *a,
                                     sona_state_status *out);
Parameter and type Meaning
a
const sona_avatar *
The avatar (required)
out
sona_state_status *
Receives the sona_state_status (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED (what each means).

Example:

sona_state_status x_state_status;
memset(&x_state_status, 0, sizeof x_state_status);
x_state_status.size = sizeof x_state_status;
sona_result result = sona_avatar_state_status(avatar, &x_state_status);
if (result != SONA_OK) printf("sona_avatar_state_status: %s\n",
    sona_result_name(result));

mode (SONA_STATE_LIVE, _WAITING, _PUPPET), pending (a clip of the last state is still loading), missing (SONA_STATE_MISSING_* of the last state put on) and how many states were put on. All zero for an avatar the module never touched.

sona_avatar_puppet

sona_result sona_avatar_puppet(sona_avatar *a, int on);
Parameter and type Meaning
a
sona_avatar *
The avatar (required)
on
int
1 on, 0 off

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED, SONA_E_MEMORY (what each means).

Example:

sona_result result = sona_avatar_puppet(avatar, 1);
if (result != SONA_OK) printf("sona_avatar_puppet: %s\n",
    sona_result_name(result));

A puppet's clocks stand still: its clip, layers, fades, moves, IK smoothing and idle change only when a state is put on it. sona_net_drive and sona_replay_drive make an avatar a puppet; off, it plays on from the last state.

sona_net_defaults

void sona_net_defaults(sona_net_options *o);
Parameter and type Meaning
o
sona_net_options *
The sona_net_options to fill with the defaults (required)

Returns Nothing.

Example:

sona_net_options x_net_options;
memset(&x_net_options, 0, sizeof x_net_options);
x_net_options.size = sizeof x_net_options;
sona_net_defaults(&x_net_options);

A rate of 30 ticks a second, 64 ticks of history, a full state after 30 ticks without an acknowledgement.

sona_net_sender_create

sona_result sona_net_sender_create(sona_ctx *ctx, const sona_net_options *o,
                                   sona_net_sender **out);
Parameter and type Meaning
ctx
sona_ctx *
The context (required)
o
const sona_net_options *
The options, a sona_net_options (NULL allowed (below))
out
sona_net_sender **
Receives the new sender (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY (what each means).

One stream's sending end. o may be NULL. SONA_E_ARGUMENT for a tick_hz of 0 or over 1000, or a history outside 8..1024.

sona_net_sender_destroy

void sona_net_sender_destroy(sona_net_sender *s);
Parameter and type Meaning
s
sona_net_sender *
The sender (required)

Returns Nothing.

Frees the sender.

sona_net_sender_look

sona_result sona_net_sender_look(sona_net_sender *s, const char *id);
Parameter and type Meaning
s
sona_net_sender *
The sender (required)
id
const char *
An id as text (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).

NULL (the default): the stream sends the avatar's manifest, and again whenever it changes. An id of 1 to 63 bytes sends that instead. Either goes along until a packet carrying it is acknowledged.

sona_net_write

sona_result sona_net_write(sona_net_sender *s, sona_avatar *a,
                           uint32_t tick, uint8_t *out, size_t cap,
                           size_t *len);
Parameter and type Meaning
s
sona_net_sender *
The sender (required)
a
sona_avatar *
The avatar (required)
tick
uint32_t
The tick's number
out
uint8_t *
Receives the bytes (required)
cap
size_t
How many bytes out holds
len
size_t *
Receives how many bytes were written (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED, SONA_E_NOT_READY, SONA_E_LIMIT, SONA_E_MEMORY (what each means).

One packet of a's state at tick, coded against the newest acknowledged tick (or full). Ticks rise (SONA_E_ARGUMENT otherwise). SONA_E_LIMIT when cap is too small, with *len the size needed; SONA_E_NOT_READY before READY.

sona_net_ack

void sona_net_ack(sona_net_sender *s, uint32_t tick);
Parameter and type Meaning
s
sona_net_sender *
The sender (required)
tick
uint32_t
The tick's number

Returns Nothing.

The receiver holds tick. Ticks the sender no longer keeps are ignored.

sona_net_receiver_create

sona_result sona_net_receiver_create(sona_ctx *ctx,
                                     const sona_net_options *o,
                                     sona_net_receiver **out);
Parameter and type Meaning
ctx
sona_ctx *
The context (required)
o
const sona_net_options *
The options, a sona_net_options (NULL allowed (below))
out
sona_net_receiver **
Receives the new receiver (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY (what each means).

One stream's receiving end. o may be NULL (the defaults).

sona_net_receiver_destroy

void sona_net_receiver_destroy(sona_net_receiver *r);
Parameter and type Meaning
r
sona_net_receiver *
The receiver (required)

Returns Nothing.

Frees the receiver.

sona_net_read

sona_result sona_net_read(sona_net_receiver *r, const void *packet,
                          size_t len, uint32_t *ack);
Parameter and type Meaning
r
sona_net_receiver *
The receiver (required)
packet
const void *
One packet as it arrived (required)
len
size_t
How many bytes there are
ack
uint32_t *
Receives the newest tick the sender has seen acknowledged (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND, SONA_E_UNSUPPORTED, SONA_E_MEMORY, SONA_E_CORRUPT (what each means).

Decodes and keeps one packet; *ack is the tick to send back. Late and repeated packets are fine. SONA_E_NOT_FOUND when its baseline is no longer held, SONA_E_CORRUPT, SONA_E_UNSUPPORTED.

sona_net_receiver_look

sona_result sona_net_receiver_look(const sona_net_receiver *r,
                                   sona_net_look *out);
Parameter and type Meaning
r
const sona_net_receiver *
The receiver (required)
out
sona_net_look *
Receives the sona_net_look (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).

The newest look the stream carried: kind SONA_NET_LOOK_MANIFEST with manifest, SONA_NET_LOOK_ID with id, or SONA_NET_LOOK_NONE before one arrives; version rises with each change.

sona_net_drive

sona_result sona_net_drive(sona_net_receiver *r, sona_avatar *a,
                           double tick);
Parameter and type Meaning
r
sona_net_receiver *
The receiver (required)
a
sona_avatar *
The avatar (required)
tick
double
The tick to show, fractions between two

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED, SONA_E_NOT_READY (what each means).

Shows tick on a, which becomes a puppet: a held tick as it is, a fraction between two held ticks as their blend, before the oldest the oldest, past the newest the newest. SONA_E_NOT_READY before any state arrived.

sona_net_sender_stats

sona_result sona_net_sender_stats(const sona_net_sender *s,
                                  sona_net_stats *out);
Parameter and type Meaning
s
const sona_net_sender *
The sender (required)
out
sona_net_stats *
Receives the sona_net_stats (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).

Packets and bytes written, those without a baseline (full), the last packet's size and the newest acknowledged tick.

sona_net_receiver_stats

sona_result sona_net_receiver_stats(const sona_net_receiver *r,
                                    sona_net_stats *out);
Parameter and type Meaning
r
const sona_net_receiver *
The receiver (required)
out
sona_net_stats *
Receives the sona_net_stats (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).

Packets and bytes read, packets refused for want of a baseline (full), the newest and oldest ticks held.

sona_record_defaults

void sona_record_defaults(sona_record_options *o);
Parameter and type Meaning
o
sona_record_options *
The sona_record_options to fill with the defaults (required)

Returns Nothing.

Example:

sona_record_options x_record_options;
memset(&x_record_options, 0, sizeof x_record_options);
x_record_options.size = sizeof x_record_options;
sona_record_defaults(&x_record_options);

A rate of 30 ticks a second, a keyframe every 30 ticks, everything kept.

sona_recorder_create

sona_result sona_recorder_create(sona_ctx *ctx,
                                 const sona_record_options *o,
                                 sona_recorder **out);
Parameter and type Meaning
ctx
sona_ctx *
The context (required)
o
const sona_record_options *
The options, a sona_record_options (required)
out
sona_recorder **
Receives the new recorder (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY (what each means).

keep_seconds above 0 keeps only about the last that many seconds (whole keyframe spans), for kill-cams.

sona_recorder_destroy

void sona_recorder_destroy(sona_recorder *r);
Parameter and type Meaning
r
sona_recorder *
The recorder (required)

Returns Nothing.

Frees the recorder and what it captured.

sona_recorder_track

sona_result sona_recorder_track(sona_recorder *r, sona_avatar *a,
                                const char *name, uint32_t *track);
Parameter and type Meaning
r
sona_recorder *
The recorder (required)
a
sona_avatar *
The avatar (required)
name
const char *
The track's name, at most 63 bytes; may be NULL (NULL: none)
track
uint32_t *
Receives the track's index (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_LIMIT, SONA_E_MEMORY (what each means).

Records a from the next capture on, as track *track. At most 256 tracks; name at most 63 bytes.

sona_recorder_capture

sona_result sona_recorder_capture(sona_recorder *r, uint32_t tick);
Parameter and type Meaning
r
sona_recorder *
The recorder (required)
tick
uint32_t
The tick's number

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY (what each means).

Every track's state at tick (rising). A track whose avatar is not READY or was removed is left out of that capture.

sona_recorder_save

sona_result sona_recorder_save(sona_recorder *r, uint8_t **out,
                               size_t *out_len);
Parameter and type Meaning
r
sona_recorder *
The recorder (required)
out
uint8_t **
Receives the bytes; free them with sona_free (required)
out_len
size_t *
Receives how many bytes *out holds (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY (what each means).

The file's bytes, freed with sona_free. Recording can go on after.

sona_replay_open

sona_result sona_replay_open(sona_ctx *ctx, const void *bytes, size_t len,
                             sona_replay **out);
Parameter and type Meaning
ctx
sona_ctx *
The context (required)
bytes
const void *
The file's bytes (required)
len
size_t
How many bytes there are
out
sona_replay **
Receives the new replay (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_UNSUPPORTED, SONA_E_MEMORY, SONA_E_CORRUPT (what each means).

Keeps a copy of the bytes. SONA_E_CORRUPT, SONA_E_UNSUPPORTED for a newer format.

sona_replay_close

void sona_replay_close(sona_replay *p);
Parameter and type Meaning
p
sona_replay *
The replay (required)

Returns Nothing.

Frees the replay.

sona_replay_info_get

sona_result sona_replay_info_get(const sona_replay *p,
                                 sona_replay_info *out);
Parameter and type Meaning
p
const sona_replay *
The replay (required)
out
sona_replay_info *
Receives the sona_replay_info (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).

The replay's tracks, tick rate, first and last tick, the captures it holds and its length in seconds.

sona_replay_track

sona_result sona_replay_track(const sona_replay *p, uint32_t track,
                              uint8_t manifest[SONA_MANIFEST_BYTES],
                              char name[64], float *from, float *to);
Parameter and type Meaning
p
const sona_replay *
The replay (required)
track
uint32_t
A track's index
manifest
uint8_t [SONA_MANIFEST_BYTES]
The manifest's 1,000 bytes, changed in place (required)
name
char [64]
Receives the track's name (required)
from
float *
Receives the track's first time, seconds (required)
to
float *
Receives the track's last time, seconds (required)

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND (what each means).

A track's look, name and span in seconds from the replay's start; each output may be NULL.

sona_replay_drive

sona_result sona_replay_drive(sona_replay *p, uint32_t track,
                              sona_avatar *a, double seconds);
Parameter and type Meaning
p
sona_replay *
The replay (required)
track
uint32_t
A track's index
a
sona_avatar *
The avatar (required)
seconds
double
The time to sample, seconds

Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED, SONA_E_NOT_READY (what each means).

Shows the track at seconds from the replay's start on a, which becomes a puppet, blending the two frames around it. Any order: the same time always shows the same pose bits.

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