rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
ui_cats.c File Reference

The pick of a cat among the poses that fit a screen's spots, its drawing, and the random source. See include/ui_cats.h. More...

#include "ui_cats.h"
#include <stddef.h>

Functions

void ui_cats_set_random (ui_cats_random_fn fn)
 Name the source ui_cats_roll() reads.
void ui_cats_seed (uint32_t seed)
 Seed the built-in xorshift.
uint32_t ui_cats_roll (void)
 The next random number from the source.
void ui_cats_force (int pose)
 Put one pose, or none, in place of the random pick.
int ui_cats_forced (void)
 The pose ui_cats_force() set.
gfx_rect_t ui_cat_rect (int pose, const ui_cat_spot_t *spot)
 The box pose pose covers in spot.
static uint32_t clear_spots (int pose, const ui_cat_spot_t *spots, int n, ui_cat_clear_fn clear)
 The spots of spots that pose pose may take and that are clear, as a mask of indexes.
static int nth_bit (uint32_t m, unsigned k)
 The index of the k-th set bit of m, counting from 0.
static unsigned bits (uint32_t m)
 The set bits of m.
ui_cat_pick_t ui_cats_pick (const ui_cat_spot_t *spots, int n, ui_cat_clear_fn clear, uint32_t roll)
 Pick a pose among the ones with a clear spot, and that spot.
gfx_rect_t ui_cats_draw (gfx_canvas_t *c, ui_cat_pick_t pick, const ui_cat_spot_t *spots, int n)
 Draw a pick.

Variables

static ui_cats_random_fn s_random
 The source ui_cats_roll() reads; NULL for the xorshift.
static uint32_t s_state = 1u
 The xorshift's state, never 0.
static int s_forced = UI_CAT_RANDOM
 The pose ui_cats_force() set, UI_CAT_RANDOM by default.

Detailed Description

The pick of a cat among the poses that fit a screen's spots, its drawing, and the random source. See include/ui_cats.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ bits()

unsigned bits ( uint32_t m)
static

The set bits of m.

Parameters
mthe mask
Returns
how many

◆ clear_spots()

uint32_t clear_spots ( int pose,
const ui_cat_spot_t * spots,
int n,
ui_cat_clear_fn clear )
static

The spots of spots that pose pose may take and that are clear, as a mask of indexes.

Parameters
poseindex into ui_cat_poses[]
spotsthe screen's spots
nhow many, at most 32
clearthe screen's test of a box
Returns
bit i set for spots[i]

◆ nth_bit()

int nth_bit ( uint32_t m,
unsigned k )
static

The index of the k-th set bit of m, counting from 0.

Parameters
mthe mask, with more than k bits set
kwhich set bit
Returns
its index

◆ ui_cat_rect()

gfx_rect_t ui_cat_rect ( int pose,
const ui_cat_spot_t * spot )

The box pose pose covers in spot.

Parameters
poseindex into ui_cat_poses[]
spotthe spot
Returns
the box; empty for a pose out of range or a NULL spot

◆ ui_cats_draw()

gfx_rect_t ui_cats_draw ( gfx_canvas_t * c,
ui_cat_pick_t pick,
const ui_cat_spot_t * spots,
int n )

Draw a pick.

Parameters
cthe canvas
pickthe pick
spotsthe list its spot indexes
nhow many
Returns
the box drawn, empty for none

◆ ui_cats_force()

void ui_cats_force ( int pose)

Put one pose, or none, in place of the random pick.

Parameters
poseindex into ui_cat_poses[], UI_CAT_RANDOM or UI_CAT_NONE; anything else is UI_CAT_NONE

◆ ui_cats_forced()

int ui_cats_forced ( void )

The pose ui_cats_force() set.

Returns
the pose, UI_CAT_RANDOM or UI_CAT_NONE

◆ ui_cats_pick()

ui_cat_pick_t ui_cats_pick ( const ui_cat_spot_t * spots,
int n,
ui_cat_clear_fn clear,
uint32_t roll )

Pick a pose among the ones with a clear spot, and that spot.

A pose counts when one of the n spots is one it may take and clear says its box there is clear. roll picks among them, and among the clear spots of the pose picked: pose roll mod P, spot (roll / P) mod S. A forced pose (ui_cats_force()) is the only one looked at; UI_CAT_NONE forced picks none.

Parameters
spotsthe screen's spots
nhow many, at most 32
clearthe screen's test of a box
rollthe random number
Returns
the pick, or UI_CAT_PICK_NONE when no pose fits

◆ ui_cats_roll()

uint32_t ui_cats_roll ( void )

The next random number from the source.

Returns
the number

◆ ui_cats_seed()

void ui_cats_seed ( uint32_t seed)

Seed the built-in xorshift.

Parameters
seedthe seed; 0 is taken as 1, which xorshift needs nonzero

◆ ui_cats_set_random()

void ui_cats_set_random ( ui_cats_random_fn fn)

Name the source ui_cats_roll() reads.

Parameters
fnthe source, esp_random() on the panel; NULL for the built-in xorshift