Skip to content

C API: Making avatars in code

Seeded random avatars, dressing one avatar like another, and the outfit rules the editor follows: Making avatars in code.

sona_maker_create

sona_result sona_maker_create(sona_ctx *ctx, const sona_catalogue *cat,
                              sona_maker **out);
Parameter and type Meaning
ctx
sona_ctx *
The context (NULL allowed (below))
cat
const sona_catalogue *
The catalogue (required)
out
sona_maker **
Receives the new maker (required)

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

Example (also in Making avatars in code):

sona_result sona_maker_create(sona_ctx *ctx, const sona_catalogue *cat,
                              sona_maker **out);
void sona_maker_free(sona_maker *mk);

Indexes a catalogue's outfit rules once: candidate items per body and section, gender variants and matched sets (Making avatars in code). The maker never changes after this, so every call on it is safe from any number of threads at once. It reads the catalogue: free it before the catalogue. ctx may be NULL (malloc, codes only).

sona_maker_free

void sona_maker_free(sona_maker *mk);
Parameter and type Meaning
mk
sona_maker *
The maker (required)

Returns Nothing.

Example (also in Making avatars in code):

sona_result sona_maker_create(sona_ctx *ctx, const sona_catalogue *cat,
                              sona_maker **out);
void sona_maker_free(sona_maker *mk);

Frees the maker.

sona_random_defaults

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

Returns Nothing.

Example (also in Making avatars in code):

void sona_random_defaults(sona_random_options *o);
sona_result sona_make_random(const sona_maker *mk, uint32_t seed,
                             const sona_random_options *o,
                             uint8_t out[SONA_MANIFEST_BYTES],
                             sona_random_report *report);

size set and everything else zero: the seed picks the body, any game, a new avatar, the palette's colours and every item available.

sona_make_random

sona_result sona_make_random(const sona_maker *mk, uint32_t seed,
                             const sona_random_options *o,
                             uint8_t out[SONA_MANIFEST_BYTES],
                             sona_random_report *report);
Parameter and type Meaning
mk
const sona_maker *
The maker (required)
seed
uint32_t
The seed: the same seed gives the same result
o
const sona_random_options *
The options, a sona_random_options (required)
out
uint8_t [SONA_MANIFEST_BYTES]
Receives the manifest's 1,000 bytes (required)
report
sona_random_report *
Receives what the call did; may be NULL (NULL: not written)

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

Example (also in Making avatars in code):

void sona_random_defaults(sona_random_options *o);
sona_result sona_make_random(const sona_maker *mk, uint32_t seed,
                             const sona_random_options *o,
                             uint8_t out[SONA_MANIFEST_BYTES],
                             sona_random_report *report);

A new avatar from a seed: body, shape, colours, face, hair and an outfit with no clashes. The same seed, options and library give the same bytes. Picks are rendezvous hashes of (seed, section, item id): a newer catalogue moves a pick only where that item is gone or a new item outscores it, so most avatars survive a catalogue update. o may be NULL; report may be NULL. SONA_E_ARGUMENT: a body over 2, a style or palette out of range, or a base that does not parse or has no body while body is 0.

sona_like_defaults

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

Returns Nothing.

Example (also in Making avatars in code):

void sona_like_defaults(sona_like_options *o);
sona_result sona_make_dress_like(const sona_maker *mk,
                                 const uint8_t body[SONA_MANIFEST_BYTES],
                                 const uint8_t like[SONA_MANIFEST_BYTES],
                                 const sona_like_options *o,
                                 uint8_t out[SONA_MANIFEST_BYTES],
                                 sona_like_report *report);
uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item,
                           uint32_t body, uint32_t match, sona_guid *out);

size set; parts clothes and props, match SIMILAR.

sona_make_dress_like

sona_result sona_make_dress_like(const sona_maker *mk,
                                 const uint8_t body[SONA_MANIFEST_BYTES],
                                 const uint8_t like[SONA_MANIFEST_BYTES],
                                 const sona_like_options *o,
                                 uint8_t out[SONA_MANIFEST_BYTES],
                                 sona_like_report *report);
Parameter and type Meaning
mk
const sona_maker *
The maker (required)
body
const uint8_t [SONA_MANIFEST_BYTES]
The manifest whose body is kept (required)
like
const uint8_t [SONA_MANIFEST_BYTES]
The manifest whose look is copied (required)
o
const sona_like_options *
The options, a sona_like_options (required)
out
uint8_t [SONA_MANIFEST_BYTES]
Receives the manifest's 1,000 bytes (required)
report
sona_like_report *
Receives what the call did; may be NULL (NULL: not written)

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

Example (also in Making avatars in code):

void sona_like_defaults(sona_like_options *o);
sona_result sona_make_dress_like(const sona_maker *mk,
                                 const uint8_t body[SONA_MANIFEST_BYTES],
                                 const uint8_t like[SONA_MANIFEST_BYTES],
                                 const sona_like_options *o,
                                 uint8_t out[SONA_MANIFEST_BYTES],
                                 sona_like_report *report);
uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item,
                           uint32_t body, uint32_t match, sona_guid *out);

out = body wearing like's parts, each item resolved for body's gender (sona_make_variant). out may be body. mk may be NULL: then only items both bodies wear, and custom items' pairs, come across. SONA_E_ARGUMENT when body has no known body; SONA_E_MANIFEST when either does not parse.

sona_make_variant

uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item,
                           uint32_t body, uint32_t match, sona_guid *out);
Parameter and type Meaning
mk
const sona_maker *
The maker (required)
item
const sona_guid *
A sona_guid (required)
body
uint32_t
The body a clip or item is for: 1 male, 2 female
match
uint32_t
What the variant must match
out
sona_guid *
Receives the sona_guid (required)

Returns uint32_t.

Example (also in Making avatars in code):

void sona_like_defaults(sona_like_options *o);
sona_result sona_make_dress_like(const sona_maker *mk,
                                 const uint8_t body[SONA_MANIFEST_BYTES],
                                 const uint8_t like[SONA_MANIFEST_BYTES],
                                 const sona_like_options *o,
                                 uint8_t out[SONA_MANIFEST_BYTES],
                                 sona_like_report *report);
uint32_t sona_make_variant(const sona_maker *mk, const sona_guid *item,
                           uint32_t body, uint32_t match, sona_guid *out);

The item body (1 or 2) wears for item: itself when it fits (KEPT), else its variant within match. Returns SONA_RESOLVED_*; DROPPED (out zeroed) when nothing fits.

sona_outfit_clash

uint32_t sona_outfit_clash(const sona_maker *mk, const sona_guid *a,
                           const sona_guid *b, uint32_t *slots);
Parameter and type Meaning
mk
const sona_maker *
The maker (required)
a
const sona_guid *
One item id (required)
b
const sona_guid *
The other item id (required)
slots
uint32_t *
Receives the slots the two items share (required)

Returns uint32_t.

Example (also in Making avatars in code):

uint32_t sona_outfit_clash(const sona_maker *mk, const sona_guid *a,
                           const sona_guid *b, uint32_t *slots);
uint32_t sona_outfit_conflicts(const sona_maker *mk,
                               const uint8_t manifest[SONA_MANIFEST_BYTES],
                               const sona_guid *item, sona_guid *out,
                               uint32_t cap);

SONA_CLASH_* bits (0: they go together); slots (may be NULL) gets the slots they share. mk may be NULL (ids only). Two props share the prop slot: they stack only with SONA_EDIT_STACK_PROPS, up to four.

sona_outfit_conflicts

uint32_t sona_outfit_conflicts(const sona_maker *mk,
                               const uint8_t manifest[SONA_MANIFEST_BYTES],
                               const sona_guid *item, sona_guid *out,
                               uint32_t cap);
Parameter and type Meaning
mk
const sona_maker *
The maker (required)
manifest
const uint8_t [SONA_MANIFEST_BYTES]
The manifest's 1,000 bytes (required)
item
const sona_guid *
A sona_guid (required)
out
sona_guid *
Receives the sona_guid (required)
cap
uint32_t
How many entries out holds

Returns uint32_t.

Example (also in Making avatars in code):

uint32_t sona_outfit_clash(const sona_maker *mk, const sona_guid *a,
                           const sona_guid *b, uint32_t *slots);
uint32_t sona_outfit_conflicts(const sona_maker *mk,
                               const uint8_t manifest[SONA_MANIFEST_BYTES],
                               const sona_guid *item, sona_guid *out,
                               uint32_t cap);

What wearing item would take off manifest: up to cap ids into out; returns how many.

sona_outfit_set_count

uint32_t sona_outfit_set_count(const sona_maker *mk);
Parameter and type Meaning
mk
const sona_maker *
The maker (required)

Returns uint32_t.

Example (also in Making avatars in code):

uint32_t sona_outfit_set_count(const sona_maker *mk);
sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set,
                                sona_outfit_set *out);
int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item);
uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set,
                               uint32_t body, uint32_t *indexes,
                               uint32_t cap);

How many matched sets (outfits sold as one) the maker knows.

sona_outfit_set_get

sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set,
                                sona_outfit_set *out);
Parameter and type Meaning
mk
const sona_maker *
The maker (required)
set
uint32_t
A matched set's index
out
sona_outfit_set *
Receives the sona_outfit_set (required)

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

Example (also in Making avatars in code):

uint32_t sona_outfit_set_count(const sona_maker *mk);
sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set,
                                sona_outfit_set *out);
int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item);
uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set,
                               uint32_t body, uint32_t *indexes,
                               uint32_t cap);

Set set: its item count, which bodies wear it, the sections it has items in and the slots it covers.

sona_outfit_set_of

int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item);
Parameter and type Meaning
mk
const sona_maker *
The maker (required)
item
const sona_guid *
A sona_guid (required)

Returns int32_t.

Example (also in Making avatars in code):

uint32_t sona_outfit_set_count(const sona_maker *mk);
sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set,
                                sona_outfit_set *out);
int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item);
uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set,
                               uint32_t body, uint32_t *indexes,
                               uint32_t cap);

The matched set an item belongs to, or -1 when it is in none.

sona_outfit_set_items

uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set,
                               uint32_t body, uint32_t *indexes,
                               uint32_t cap);
Parameter and type Meaning
mk
const sona_maker *
The maker (required)
set
uint32_t
A matched set's index
body
uint32_t
The body whose items to list: 1 male, 2 female; 0: every item (0: every item)
indexes
uint32_t *
Receives catalogue indexes (required)
cap
uint32_t
How many entries out holds

Returns uint32_t.

Example (also in Making avatars in code):

uint32_t sona_outfit_set_count(const sona_maker *mk);
sona_result sona_outfit_set_get(const sona_maker *mk, uint32_t set,
                                sona_outfit_set *out);
int32_t sona_outfit_set_of(const sona_maker *mk, const sona_guid *item);
uint32_t sona_outfit_set_items(const sona_maker *mk, uint32_t set,
                               uint32_t body, uint32_t *indexes,
                               uint32_t cap);

The set's items a body wears (0: every item), catalogue indexes in id order: up to cap; returns how many.

sona_outfit_check

sona_result sona_outfit_check(const sona_maker *mk,
                              const uint8_t manifest[SONA_MANIFEST_BYTES],
                              sona_outfit_report *report,
                              sona_outfit_issue *issues, uint32_t cap);
Parameter and type Meaning
mk
const sona_maker *
The maker (required)
manifest
const uint8_t [SONA_MANIFEST_BYTES]
The manifest's 1,000 bytes (required)
report
sona_outfit_report *
Receives what the call did; may be NULL (NULL: not written)
issues
sona_outfit_issue *
Receives the issues found, up to max (required)
cap
uint32_t
How many entries out holds

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

Example (also in Making avatars in code):

sona_result sona_outfit_check(const sona_maker *mk,
                              const uint8_t manifest[SONA_MANIFEST_BYTES],
                              sona_outfit_report *report,
                              sona_outfit_issue *issues, uint32_t cap);
sona_result sona_outfit_fix(const sona_maker *mk,
                            uint8_t manifest[SONA_MANIFEST_BYTES],
                            sona_outfit_report *after);
const char *sona_outfit_issue_name(uint32_t kind);

Every issue of a manifest, up to cap into issues (may be NULL with cap 0), errors first. mk may be NULL: the catalogue's checks (UNKNOWN, NOT_OFFERED, bodies by the catalogue) are left out. SONA_E_MANIFEST: it does not parse.

sona_outfit_fix

sona_result sona_outfit_fix(const sona_maker *mk,
                            uint8_t manifest[SONA_MANIFEST_BYTES],
                            sona_outfit_report *after);
Parameter and type Meaning
mk
const sona_maker *
The maker (required)
manifest
uint8_t [SONA_MANIFEST_BYTES]
The manifest's 1,000 bytes, changed in place (required)
after
sona_outfit_report *
Receives the report of the manifest as fixed (required)

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

Example (also in Making avatars in code):

sona_result sona_outfit_check(const sona_maker *mk,
                              const uint8_t manifest[SONA_MANIFEST_BYTES],
                              sona_outfit_report *report,
                              sona_outfit_issue *issues, uint32_t cap);
sona_result sona_outfit_fix(const sona_maker *mk,
                            uint8_t manifest[SONA_MANIFEST_BYTES],
                            sona_outfit_report *after);
const char *sona_outfit_issue_name(uint32_t kind);

Fixes every error but NO_BODY in place: clashes go to the item worn last (as the editor), other-body items to their variants, duplicates and misplaced items out (a misplaced item that routes is worn where it belongs), missing slots to the body's defaults, a stale cache to the body's own; after (may be NULL) is the check after. SONA_E_ARGUMENT when the body is not known.

sona_outfit_issue_name

const char * sona_outfit_issue_name(uint32_t kind);
Parameter and type Meaning
kind
uint32_t
Which kind, one of the header's constants for it

Returns const char *.

Example (also in Making avatars in code):

sona_result sona_outfit_check(const sona_maker *mk,
                              const uint8_t manifest[SONA_MANIFEST_BYTES],
                              sona_outfit_report *report,
                              sona_outfit_issue *issues, uint32_t cap);
sona_result sona_outfit_fix(const sona_maker *mk,
                            uint8_t manifest[SONA_MANIFEST_BYTES],
                            sona_outfit_report *after);
const char *sona_outfit_issue_name(uint32_t kind);

The name of a SONA_OUTFIT_* issue kind ("clash", ...); NULL past the last.

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