RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
motion_store.h File Reference

motion_store.h — element motions (element_motion.h) keyed by a stable nonzero u64 id, for hosts that paint immediate-mode and so have no retained element to own each motion. More...

#include <stddef.h>
#include <stdint.h>
#include "element_motion.h"
#include "style.h"

Data Structures

struct  rmgui_motion_slot_t
 One slot of a store. More...
struct  rmgui_motion_store_t
 A store over caller-owned slots. More...

Functions

void rmgui_motion_store_init (rmgui_motion_store_t *s, rmgui_motion_slot_t *slots, size_t capacity)
 Binds *s to slots[0, capacity) and frees every slot; the generation starts at 0.
int rmgui_motion_store_find (const rmgui_motion_store_t *s, uint64_t id)
 The index of the live slot keyed id, or -1 when none is (always for id 0 or NULL s).
int rmgui_motion_store_claim (rmgui_motion_store_t *s, uint64_t id, unsigned style_key, const rmgui_style_motion_resolved_t *style)
 The index of the slot keyed id: the live one when there is one (its motion and style key unchanged); otherwise a slot claimed for it at rest under style (rmgui_element_motion_init) with style_key, counting as painted now for eviction order but unmarked for the sweep.
void rmgui_motion_store_release (rmgui_motion_store_t *s, int index)
 Frees slot index now, whatever its motion; the generation changes when that motion was not at rest.
uint64_t rmgui_motion_store_id (const rmgui_motion_store_t *s, int index)
 The id slot index is keyed by; 0 when it is free, out of range or s is NULL.
unsigned rmgui_motion_store_style_key (const rmgui_motion_store_t *s, int index)
 The style key slot index was claimed with; 0 when it is free, out of range or s is NULL.
const rmgui_element_motion_t * rmgui_motion_store_motion (const rmgui_motion_store_t *s, int index)
 The motion of live slot index, for the element_motion.h queries (the visual, progress, rest); NULL when the slot is free, out of range or s is NULL.
int rmgui_motion_store_set_levels (rmgui_motion_store_t *s, int index, unsigned levels)
 rmgui_element_motion_set_levels on live slot index; the generation changes when it returns 1.
int rmgui_motion_store_refuse (rmgui_motion_store_t *s, int index, const rmgui_style_motion_resolved_t *style, uint32_t seed)
 rmgui_element_motion_refuse on live slot index; the generation changes when it returns 1.
int rmgui_motion_store_step (rmgui_motion_store_t *s, const rmgui_style_motion_resolved_t *styles, size_t style_count, uint16_t dt_ms)
 rmgui_element_motion_step by dt_ms on every live slot whose style key is below style_count, under styles[style_key]; a slot with a larger key is left unchanged.
void rmgui_motion_store_mark_painted (rmgui_motion_store_t *s, int index)
 Marks live slot index painted: the next sweep keeps it, and it becomes the most recently painted for a full store's claim.
int rmgui_motion_store_sweep (rmgui_motion_store_t *s)
 Frees every live slot at rest and not marked painted since the previous sweep, then clears every mark.
int rmgui_motion_store_is_moving (const rmgui_motion_store_t *s)
 1 when a live slot's motion is moving (rmgui_element_motion_is_moving), so the host should keep waking; 0 otherwise or for NULL s.
uint32_t rmgui_motion_store_generation (const rmgui_motion_store_t *s)
 A counter that changes, wrapping, whenever a live slot's motion state changes: a set_levels or refuse that returned 1, a step that returned 1, a release of a slot not at rest.

Detailed Description

motion_store.h — element motions (element_motion.h) keyed by a stable nonzero u64 id, for hosts that paint immediate-mode and so have no retained element to own each motion.

Protocol: the host binds a store to an array of slots it owns and sizes; each frame it claims the slot of every element it paints, reports that element's levels and triggers through the store, reads its motion to paint, marks it painted, steps the store once by clock dt, and sweeps. The sweep frees every slot whose motion is at rest and that was not painted since the previous sweep; a freed slot equals a fresh claim, so an element whose slot was swept paints exactly as before. A claim with every slot live takes the resting slot painted least recently, and refuses when none rests: the host then paints that element plainly. The generation changes whenever a slot's motion state changes, so it keys repaints; is_moving says whether the host should keep waking.

No allocation, no clock, no global state: the same inputs leave the same bytes on every target. Slots with a live id hold motion; slots are reused lowest index first.

Function Documentation

◆ rmgui_motion_store_init()

void rmgui_motion_store_init ( rmgui_motion_store_t * s,
rmgui_motion_slot_t * slots,
size_t capacity )

Binds *s to slots[0, capacity) and frees every slot; the generation starts at 0.

The store uses at most INT_MAX slots; NULL slots binds none. The slots must outlive every later call on *s and belong to no other store. NULL s: no-op.

◆ rmgui_motion_store_find()

int rmgui_motion_store_find ( const rmgui_motion_store_t * s,
uint64_t id )

The index of the live slot keyed id, or -1 when none is (always for id 0 or NULL s).

◆ rmgui_motion_store_claim()

int rmgui_motion_store_claim ( rmgui_motion_store_t * s,
uint64_t id,
unsigned style_key,
const rmgui_style_motion_resolved_t * style )

The index of the slot keyed id: the live one when there is one (its motion and style key unchanged); otherwise a slot claimed for it at rest under style (rmgui_element_motion_init) with style_key, counting as painted now for eviction order but unmarked for the sweep.

A claim takes the lowest free slot; with none free, it frees the resting slot (rmgui_element_motion_is_at_rest) whose claim or last mark is oldest, the lowest index among equals, and takes that. -1, changing nothing, when every slot is live and none rests, or for id 0, NULL s or NULL style. Claiming never changes the generation: a slot at rest has no visual.

◆ rmgui_motion_store_release()

void rmgui_motion_store_release ( rmgui_motion_store_t * s,
int index )

Frees slot index now, whatever its motion; the generation changes when that motion was not at rest.

Out of range, a free slot or NULL s: no-op.

◆ rmgui_motion_store_id()

uint64_t rmgui_motion_store_id ( const rmgui_motion_store_t * s,
int index )

The id slot index is keyed by; 0 when it is free, out of range or s is NULL.

◆ rmgui_motion_store_style_key()

unsigned rmgui_motion_store_style_key ( const rmgui_motion_store_t * s,
int index )

The style key slot index was claimed with; 0 when it is free, out of range or s is NULL.

◆ rmgui_motion_store_motion()

const rmgui_element_motion_t * rmgui_motion_store_motion ( const rmgui_motion_store_t * s,
int index )

The motion of live slot index, for the element_motion.h queries (the visual, progress, rest); NULL when the slot is free, out of range or s is NULL.

Valid until the slot is freed.

◆ rmgui_motion_store_set_levels()

int rmgui_motion_store_set_levels ( rmgui_motion_store_t * s,
int index,
unsigned levels )

rmgui_element_motion_set_levels on live slot index; the generation changes when it returns 1.

Returns its result; 0 for a free or out of range slot or NULL s.

◆ rmgui_motion_store_refuse()

int rmgui_motion_store_refuse ( rmgui_motion_store_t * s,
int index,
const rmgui_style_motion_resolved_t * style,
uint32_t seed )

rmgui_element_motion_refuse on live slot index; the generation changes when it returns 1.

Returns its result; 0 for a free or out of range slot or NULL s.

◆ rmgui_motion_store_step()

int rmgui_motion_store_step ( rmgui_motion_store_t * s,
const rmgui_style_motion_resolved_t * styles,
size_t style_count,
uint16_t dt_ms )

rmgui_element_motion_step by dt_ms on every live slot whose style key is below style_count, under styles[style_key]; a slot with a larger key is left unchanged.

Returns 1 when any slot's step returned 1, and the generation then changes; 0 otherwise (styles NULL or s NULL included). Stepping by a then by b leaves exactly the slots stepping by a + b leaves.

◆ rmgui_motion_store_mark_painted()

void rmgui_motion_store_mark_painted ( rmgui_motion_store_t * s,
int index )

Marks live slot index painted: the next sweep keeps it, and it becomes the most recently painted for a full store's claim.

Out of range, a free slot or NULL s: no-op.

◆ rmgui_motion_store_sweep()

int rmgui_motion_store_sweep ( rmgui_motion_store_t * s)

Frees every live slot at rest and not marked painted since the previous sweep, then clears every mark.

Returns how many it freed (0 for NULL s). Never changes the generation: a slot at rest has no visual.

◆ rmgui_motion_store_is_moving()

int rmgui_motion_store_is_moving ( const rmgui_motion_store_t * s)

1 when a live slot's motion is moving (rmgui_element_motion_is_moving), so the host should keep waking; 0 otherwise or for NULL s.

◆ rmgui_motion_store_generation()

uint32_t rmgui_motion_store_generation ( const rmgui_motion_store_t * s)

A counter that changes, wrapping, whenever a live slot's motion state changes: a set_levels or refuse that returned 1, a step that returned 1, a release of a slot not at rest.

Under unchanged styles, equal values across a span mean no slot's visual changed within it. 0 for NULL s.