# C API: Loading placeholders

A neutral figure in the avatar's place while it loads, and avatars added before their manifest is known: [Loading placeholders](../../guides/placeholder.md).

## sona_placeholder_defaults

```c
void sona_placeholder_defaults(sona_placeholder_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_placeholder_options *` | The [`sona_placeholder_options`](../fields.md#sona_placeholder_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_placeholder_options x_placeholder_options;
memset(&x_placeholder_options, 0, sizeof x_placeholder_options);
x_placeholder_options.size = sizeof x_placeholder_options;
sona_placeholder_defaults(&x_placeholder_options);
```

`size` set; `delay_seconds` 0 (never a hole), `appear_seconds` 0.2, `reveal_seconds` 0.4, `failed_seconds` 2, `tint` 0.16, 0.19, 0.25 (a cool grey), `failed_tint` 0.25, 0.15, 0.15 (a muted red), `glow` 0.5.

## sona_placeholder_set

```c
sona_result sona_placeholder_set(sona_ctx *ctx, const sona_placeholder_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_placeholder_options *` | The options, a [`sona_placeholder_options`](../fields.md#sona_placeholder_options) | `NULL`: the defaults |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY` ([what each means](../../troubleshooting.md#error-codes)).

**Example** (also in [Loading placeholders](../../guides/placeholder.md)):

```c
sona_open(&cfg, &ctx);
sona_placeholder_set(ctx, NULL);         /* on, with the defaults */
sona_lod_set(ctx, NULL);                 /* optional: far figures become sprites too */

/* ... add avatars as usual; they show figures until READY ... */

while (game_running()) {               /* your game's loop */
  sona_update(ctx, dt, &view, NULL);     /* phases, timers, posing */
  sona_draw(renderer, &view, &target, NULL);
}
```

NULL: the defaults. `SONA_E_ARGUMENT` for a size that is not the struct's, a negative or non-finite time (each has a limit of 60 s), a colour outside 0..1 or reserved words that are not zero. Takes effect at the next `sona_update`.

## sona_placeholder_get

```c
sona_result sona_placeholder_get(const sona_ctx *ctx, sona_placeholder_options *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `out` | `sona_placeholder_options *` | Receives the [`sona_placeholder_options`](../fields.md#sona_placeholder_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND` ([what each means](../../troubleshooting.md#error-codes)).

**Example**:

```c
sona_placeholder_options x_placeholder_options;
memset(&x_placeholder_options, 0, sizeof x_placeholder_options);
x_placeholder_options.size = sizeof x_placeholder_options;
sona_result result = sona_placeholder_get(ctx, &x_placeholder_options);
if (result != SONA_OK) printf("sona_placeholder_get: %s\n", sona_result_name(result));
```

`SONA_E_NOT_FOUND` while placeholders are off (out still gets the options last set, or the defaults).

## sona_placeholder_off

```c
sona_result sona_placeholder_off(sona_ctx *ctx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](../../troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_placeholder_off(ctx);
if (result != SONA_OK) printf("sona_placeholder_off: %s\n", sona_result_name(result));
```

Figures shown now fade out over appear_seconds.

## sona_avatar_placeholder

```c
sona_result sona_avatar_placeholder(sona_avatar *a, int32_t mode);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `mode` | `int32_t` | A `SONA_PLACEHOLDER_*` mode for this avatar | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED`, `SONA_E_MEMORY` ([what each means](../../troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_placeholder(avatar, 0);
if (result != SONA_OK) printf("sona_avatar_placeholder: %s\n", sona_result_name(result));
```

Per avatar: -1 follows the ctx (the default), 0 never, 1 always (with the ctx's options, or the defaults).

## sona_avatar_placeholder_info

```c
sona_result sona_avatar_placeholder_info(const sona_avatar *a, sona_placeholder_info *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `const sona_avatar *` | The avatar | required |
| `out` | `sona_placeholder_info *` | Receives the [`sona_placeholder_info`](../fields.md#sona_placeholder_info) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](../../troubleshooting.md#error-codes)).

**Example**:

```c
sona_placeholder_info x_placeholder_info;
memset(&x_placeholder_info, 0, sizeof x_placeholder_info);
x_placeholder_info.size = sizeof x_placeholder_info;
sona_result result = sona_avatar_placeholder_info(avatar, &x_placeholder_info);
if (result != SONA_OK) printf("sona_avatar_placeholder_info: %s\n", sona_result_name(result));
```

The avatar's figure at the last `sona_update`: its phase, opacity, height, which figure (male, female or neutral), whether it plays the avatar's clip, the seconds since the avatar was added and whether it is drawn as a sprite.

## sona_placeholder_stats_get

```c
void sona_placeholder_stats_get(const sona_ctx *ctx, sona_placeholder_stats *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `const sona_ctx *` | The context | required |
| `out` | `sona_placeholder_stats *` | Receives the [`sona_placeholder_stats`](../fields.md#sona_placeholder_stats) | required |

**Returns** Nothing.

**Example**:

```c
sona_placeholder_stats x_placeholder_stats;
memset(&x_placeholder_stats, 0, sizeof x_placeholder_stats);
x_placeholder_stats.size = sizeof x_placeholder_stats;
sona_placeholder_stats_get(ctx, &x_placeholder_stats);
```

Figures in view at the last `sona_update` (by phase, and how many as sprites), how many were posed and the time that took, and the figure draws of the last `sona_draw` or `sona_snapshot`.

## sona_avatar_add_waiting

```c
sona_result sona_avatar_add_waiting(sona_ctx *ctx, const sona_add_options *opts, sona_avatar **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](../fields.md#sona_add_options) | required |
| `out` | `sona_avatar **` | Receives the new avatar | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](../../troubleshooting.md#error-codes)).

**Example** (also in [Loading placeholders](../../guides/placeholder.md)):

```c
sona_avatar *seat;
sona_avatar_add_waiting(ctx, &opts, &seat);         /* QUEUED, the neutral figure */
/* ... later, when the network brings the manifest ... */
sona_avatar_set_manifest_base64(seat, b64);         /* now it loads like any avatar */
```

An avatar whose manifest is not known, as for a player joining before their profile arrives. It stays QUEUED and shows the neutral figure (with placeholders on) until `sona_avatar_set_manifest` gives it its manifest, once; then it loads as if it had been added with it. Placement, play, layers and the rest work on it as on any avatar. `sona_avatar_set_manifest`: `SONA_E_ARGUMENT` for an avatar not added waiting or already given one. A bad manifest fails the avatar later with `SONA_E_MANIFEST`, as `sona_avatar_add`.

## sona_avatar_set_manifest

```c
sona_result sona_avatar_set_manifest(sona_avatar *a, const uint8_t manifest[SONA_MANIFEST_BYTES]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `manifest` | `const uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](../../troubleshooting.md#error-codes)).

**Example**:

```c
sona_result result = sona_avatar_set_manifest(avatar, manifest);
if (result != SONA_OK) printf("sona_avatar_set_manifest: %s\n", sona_result_name(result));
```

Gives an avatar added with `sona_avatar_add_waiting` its manifest, once; it then loads as if it had been added with it. `SONA_E_ARGUMENT` for an avatar not added waiting or already given one.

## sona_avatar_set_manifest_base64

```c
sona_result sona_avatar_set_manifest_base64(sona_avatar *a, const char *b64);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `a` | `sona_avatar *` | The avatar | required |
| `b64` | `const char *` | The manifest as base64 text, at most 4096 characters | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_DESTROYED` ([what each means](../../troubleshooting.md#error-codes)).

**Example** (also in [Loading placeholders](../../guides/placeholder.md)):

```c
sona_avatar *seat;
sona_avatar_add_waiting(ctx, &opts, &seat);         /* QUEUED, the neutral figure */
/* ... later, when the network brings the manifest ... */
sona_avatar_set_manifest_base64(seat, b64);         /* now it loads like any avatar */
```

`sona_avatar_set_manifest` with the manifest as base64 text.
