aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / om / allen-scene / native / mind.h
| 1 | /* mind.h -- Allen's presence: no face and no body, a mind drawn as light. |
| 2 | * |
| 3 | * About a hundred points of light sit on and inside a sphere, joined by fine |
| 4 | * threads into a network, turning slowly in three dimensions round a warm |
| 5 | * heart. Small sparks run along the threads from point to point; each one |
| 6 | * that arrives lights its point for a moment. How it moves is how Allen is: |
| 7 | * idle it breathes (a slow swell) and turns slowly; a few sparks. |
| 8 | * listening each key typed sends a soft wave of light up through it. |
| 9 | * thinking it draws in a little, turns faster, the heart brightens and |
| 10 | * sparks cascade through the whole network. |
| 11 | * speaking every word sends a pulse out from the heart, and the heart |
| 12 | * follows the voice. |
| 13 | * It is born from the light of the black holes' merger: the points start |
| 14 | * scattered wide and gather, spiralling, into the network. |
| 15 | * |
| 16 | * Integer only, freestanding. ck_mind_at moves it to a time (one caller); |
| 17 | * ck_mind_draw then only reads, so several processor cores can draw |
| 18 | * different parts of the screen at once. Host tested in |
| 19 | * ui/tests/allen_ui_test.c. */ |
| 20 | #ifndef AIENOS_MIND_H |
| 21 | #define AIENOS_MIND_H |
| 22 | #include <stddef.h> |
| 23 | #include <stdint.h> |
| 24 | |
| 25 | #include "paint.h" |
| 26 | |
| 27 | #define CK_MIND_NODES 120u |
| 28 | #define CK_MIND_EDGES 300u |
| 29 | #define CK_MIND_SPARKS 64u |
| 30 | #define CK_MIND_FORM_MS 3000u /* from born to fully gathered */ |
| 31 | |
| 32 | enum { CK_MIND_IDLE, CK_MIND_LISTEN, CK_MIND_THINK, CK_MIND_SPEAK }; |
| 33 | |
| 34 | typedef struct { |
| 35 | /* the shape, fixed at init */ |
| 36 | int32_t cx, cy, R; /* px */ |
| 37 | uint32_t k; |
| 38 | int16_t home[CK_MIND_NODES][3]; /* unit sphere, Q14 */ |
| 39 | uint8_t ea[CK_MIND_EDGES], eb[CK_MIND_EDGES]; |
| 40 | unsigned ne; |
| 41 | uint32_t born; /* ms */ |
| 42 | /* how it is, moved on by ck_mind_at */ |
| 43 | uint32_t t, rng, spawn; |
| 44 | int mode; |
| 45 | uint32_t angle; /* the turn so far, 1/256 of a 65536th */ |
| 46 | uint32_t spin, squeeze; /* eased toward the mode's: per-ms turn (same units), and 0..256 drawn in */ |
| 47 | uint32_t heart, voice; /* 0..256 */ |
| 48 | uint32_t words[4], keys[4]; /* when the last pulses began (ms; 0 none) */ |
| 49 | uint16_t act[CK_MIND_NODES]; /* how lit each point is, 0..256 */ |
| 50 | struct { |
| 51 | uint16_t e, dur; |
| 52 | uint8_t back; /* runs eb to ea */ |
| 53 | uint32_t t0; |
| 54 | } spark[CK_MIND_SPARKS]; |
| 55 | unsigned nspark; |
| 56 | /* the frame, worked out by ck_mind_at for ck_mind_draw */ |
| 57 | int32_t px[CK_MIND_NODES], py[CK_MIND_NODES]; /* 16ths of a pixel */ |
| 58 | uint16_t lum[CK_MIND_NODES], near[CK_MIND_NODES]; /* brightness 0..256; nearness 0..256 */ |
| 59 | uint32_t alpha; /* the whole figure, 0..256 */ |
| 60 | int32_t hx, hy, hr; /* the heart: 16ths of a pixel */ |
| 61 | ck_rect box, was; /* where it is now, and was the frame before */ |
| 62 | } ck_mind; |
| 63 | |
| 64 | /* (cx, cy) its centre, px; k the scale (1/256 px per design px); born the |
| 65 | * time it starts to gather (ms). */ |
| 66 | void ck_mind_init(ck_mind *m, int32_t cx, int32_t cy, uint32_t k, uint32_t born); |
| 67 | void ck_mind_mode(ck_mind *m, int mode, uint32_t t); |
| 68 | void ck_mind_word(ck_mind *m, uint32_t t); /* a word was spoken */ |
| 69 | void ck_mind_key(ck_mind *m, uint32_t t); /* a key was typed */ |
| 70 | void ck_mind_voice(ck_mind *m, uint32_t level); /* 0..256 */ |
| 71 | void ck_mind_at(ck_mind *m, uint32_t t); |
| 72 | /* The figure into the part r of out (light added). */ |
| 73 | void ck_mind_draw(const ck_mind *m, ck_canvas *out, const ck_rect *r); |
| 74 | /* What needs redrawing for this frame: where it was and where it is. */ |
| 75 | ck_rect ck_mind_dirty(const ck_mind *m); |
| 76 | #endif |