Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
raea/people: the people of a place as data and as days (docs/character.feature CH50-CH53)
shinyobjectzcfb58e87ac34
diff --git a/docs/character.feature b/docs/character.featureindex b52e4619..710425e0 100644--- a/docs/character.feature+++ b/docs/character.feature@@ -985,3 +985,41 @@ Feature: The character SDK as one system: SOMA bodies, Kimodo motion, generated# copy SOMA's bare shape.Then words make a helmet, a hat or armour that SOMA wears and moves withAnd each piece is its own part on the bone it covers, so pieces mix with sewn garments as layers++ Scenario: CH50. The people of a place, drawn from its roles+ # 11-17, sdk/character/src/people (raea/people), for a city's worth of characters (THE GAMBIT's Berlin): a+ # project lists roles (a profession, a rank in a service, a household part: the share of women, the ages, the+ # traits the role leans to, the dress and things carried by weight, how its people travel, where they work,+ # their day and habits) and places (homes with how many households, shops, works, posts, stops). populate()+ # draws everyone from one seed: name, sex, age, five traits, habits, a crowd face's numbers (its own seed,+ # build, iris, stubble, facial hair by age), height, hair style, colour and grey, dress, kit and gait.+ # test/people.test.ts.+ Given roles, places and a seed+ Then the same seed draws the same people on every machine, and a different one draws others+ And everyone drawn from a role keeps its sex, ages, rank and gait, and a working role has a workplace++ Scenario: CH51. A person's day+ # dayOf(): the role's blocks that apply on the weekday (a shift, a queue, a patrol round of posts), at real+ # places (the person's home or work, or one of the nearest few of a kind), at times moved by how punctual+ # the person is (conscientiousness scales each block's jitter from 1.6x to 0.4x); habits (church on Sunday,+ # a pipe on the doorstep) on their own chance leaned by traits; the trips between, by a mode chosen from the+ # distance, the cold and the person's leanings (under 900 m always walked), leaving in time by that mode,+ # waiting when early. whereAt() says where anyone is at any minute, along a trip's path.+ Then a day covers 00:00 to 24:00 with no gaps, and a trip joins every change of place+ And punctual people start closer to their times than careless ones+ And a far commute in the cold goes by tram, and a short errand is walked++ Scenario: CH52. Three levels of detail by distance+ # Every person exists as data and a day. snapshot() gives everyone's place, facing and doing at a minute and+ # their level for a camera: near (skinned characters performing their acts), middle (agents moved along+ # their trips with no skinning), far (census(): how many are at each kind of place, or moving by each mode,+ # in each hour). A person changes level with a tenth of hysteresis so the edge does not flicker. The ranges+ # are the project's (THE GAMBIT's world/budgets.ts: near 150 m, middle 1500 m).+ Then a city of thousands is placed at any minute, and only those near the camera are characters++ Scenario: CH53. How a person meets an event+ # react(): a shock underfoot (a mine's blast felt through the ground), a gun's report, a shout. Felt+ # strength falls with distance; a look toward it (or at the ground, for a shock underfoot), a flinch or+ # covered ears for the nervous, a dead stop for the rest, a turn to a neighbour for the outgoing, a run for+ # the very nervous and young; how long they freeze. Acts are in the stage's words.+ Then a crowd reacts to one event each in their own way, the same way on every rundiff --git a/sdk/character/src/people.ts b/sdk/character/src/people.tsnew file mode 100644index 00000000..47d62400--- /dev/null+++ b/sdk/character/src/people.ts@@ -0,0 +1,15 @@+// raea/people: the people of a place as data and as days (docs/character.feature CH50-CH53). A project lists its+// roles (a profession, a rank, a household part: who fills it, what they wear and carry, how they travel, their day+// and habits) and its places; the SDK draws the people, each from a seed (name, sex, age, traits, face and body+// numbers, hair, dress, gait), gives each a day (blocks at real places, trips between them by mode, habits), and+// says where anyone is at any minute, at three levels of detail by distance from the camera.+//+// import { populate, cityDay, snapshot, react } from "raea/people";+// const people = populate({ roles, places, folk, mix: { baker: 3, housewife: 40 }, seed: "leipziger" });+// const day = cityDay(people, roles, places, { key: "1917-12-03", weekday: 1 });+// const now = snapshot(day, 17 * 60 + 30, cameraAt, { near: 150, middle: 1500 });+export * from "./people/types";+export { rng, hash, type Rng } from "./people/rng";+export { makePerson, gaitOf, leaned, TRAITS, type Folk, type Names } from "./people/persona";+export { dayOf, whereAt, walkSpeed, straight, SPEED, WALK_UNDER, type DayInput } from "./people/day";+export { populate, cityDay, snapshot, census, levelAt, react, type CityInput, type Mix, type Day, type Event } from "./people/city";diff --git a/sdk/character/src/people/city.ts b/sdk/character/src/people/city.tsnew file mode 100644index 00000000..6cd27160--- /dev/null+++ b/sdk/character/src/people/city.ts@@ -0,0 +1,147 @@+// A city's people at three levels of detail (docs/character.feature CH52): every person exists as data and a day;+// near the camera they are skinned characters performing their acts, further out agents moved along their trips with+// no skinning, and beyond that only counts (how many are at each kind of place in each hour). A person moves between+// levels by id, keeping their day.+import { dayOf, whereAt, type DayInput } from "./day";+import { makePerson, type Folk } from "./persona";+import { hash, rng } from "./rng";+import type { Activity, Level, Person, Place, Role, Router, Traits, V3 } from "./types";++/** How many of each role a place holds (or its share of the population, when `people` is given). */+export type Mix = Record<string, number>;++export interface CityInput {+ roles: Role[];+ places: Place[];+ folk: Folk;+ /** roles by count, or by share when `people` is given */+ mix: Mix;+ people?: number;+ seed: number | string;+}++/** Everyone in the place: each a role drawn by the mix, a home (households filled in order of a shuffle) and, for a+ * role that works somewhere, a workplace of its kind within reach, filled up to what it holds. */+export function populate(c: CityInput): Person[] {+ const r = rng(c.seed);+ const roles = new Map(c.roles.map((x) => [x.id, x]));+ const counts: [string, number][] = c.people+ ? Object.entries(c.mix).map(([k, s]) => [k, Math.round((s / Object.values(c.mix).reduce((a, b) => a + b, 0)) * c.people!)])+ : Object.entries(c.mix);+ const homes = c.places.filter((p) => p.kind === "home");+ if (homes.length === 0) throw new Error("populate: no places of kind 'home'");+ const slots: Place[] = [];+ for (const h of homes) for (let k = 0; k < (h.holds ?? 3); k++) slots.push(h);+ for (let i = slots.length - 1; i > 0; i--) { const j = r.int(0, i); [slots[i], slots[j]] = [slots[j], slots[i]]; }+ const used = new Map<string, number>();+ const out: Person[] = [];+ let n = 0;+ for (const [rid, count] of counts) {+ const role = roles.get(rid);+ if (!role) throw new Error(`populate: the mix names a role no one defined: ${rid}`);+ for (let k = 0; k < count; k++, n++) {+ const home = slots[n % slots.length];+ let work: Place | undefined;+ if (role.work) {+ const cand = c.places.filter((p) => p.kind === role.work!.at && (used.get(p.id) ?? 0) < (p.holds ?? Infinity)+ && Math.hypot(p.at[0] - home.at[0], p.at[2] - home.at[2]) <= (role.work!.within ?? Infinity));+ work = cand.length ? cand[r.int(0, cand.length - 1)] : undefined;+ if (work) used.set(work.id, (used.get(work.id) ?? 0) + 1);+ }+ out.push(makePerson(`p${n}`, role, c.folk, home, hash(`${c.seed}-${n}`), work));+ }+ }+ return out;+}++/** The level a person is simulated at, from their distance to the camera; `was` gives hysteresis (a tenth of each+ * range) so a person at the edge doesn't flip each frame. */+export function levelAt(dist: number, range: { near: number; middle: number }, was?: Level): Level {+ const h = 0.1;+ const near = was === "near" ? range.near * (1 + h) : range.near * (was ? 1 - h : 1);+ const middle = was === "far" ? range.middle * (1 - h) : range.middle * (was === "middle" || was === "near" ? 1 + h : 1);+ return dist <= near ? "near" : dist <= middle ? "middle" : "far";+}++export interface Day {+ people: Person[];+ days: Map<string, Activity[]>;+ places: Map<string, Place>;+}++/** Every person's day for a date. */+export function cityDay(people: Person[], roles: Role[], places: Place[], date: DayInput["date"], router?: Router, cold?: number): Day {+ const pm = new Map(places.map((p) => [p.id, p])), byKind = new Map<string, Place[]>();+ for (const p of places) byKind.set(p.kind, [...(byKind.get(p.kind) ?? []), p]);+ const rm = new Map(roles.map((x) => [x.id, x]));+ const days = new Map<string, Activity[]>();+ for (const person of people) days.set(person.id, dayOf({ person, role: rm.get(person.role)!, date, places: pm, byKind, router, cold }));+ return { people, days, places: pm };+}++/** Spacing of a queue along a front (metres) and how far out from the wall it stands. */+export const QUEUE_GAP = 0.65, QUEUE_OUT = 1.1;++/** Everyone at a minute: where they are, what they are doing, and the level they are at for a camera. A person inside+ * a place (`Place.inside`, on a block not `outside`) is "inside": counted, never drawn. People out at the same door+ * stand in a queue along its front, first come nearest the door, facing it. */+export function snapshot(d: Day, m: number, camera: V3, range: { near: number; middle: number }, was?: Map<string, Level>) {+ const rows = d.people.map((p) => ({ p, w: whereAt(d.days.get(p.id)!, d.places, m) }));+ const lines = new Map<string, { i: number; since: number }[]>();+ rows.forEach(({ w }, i) => {+ const a = w.activity;+ if (a.kind === "stay" && a.outside) lines.set(a.at, [...(lines.get(a.at) ?? []), { i, since: a.from }]);+ });+ const placed = new Map<number, { at: V3; facing: number }>();+ for (const [id, line] of lines) {+ const pl = d.places.get(id)!, f = pl.facing ?? 0;+ // the front runs across the facing; the queue runs along it from the door, a step out from the wall+ const out: V3 = [Math.sin(f), 0, Math.cos(f)], along: V3 = [Math.cos(f), 0, -Math.sin(f)];+ line.sort((a, b) => a.since - b.since || a.i - b.i).forEach((q, k) => {+ const s = (k + 1) * QUEUE_GAP;+ placed.set(q.i, { at: [pl.at[0] + out[0] * QUEUE_OUT + along[0] * s, pl.at[1], pl.at[2] + out[2] * QUEUE_OUT + along[2] * s], facing: f + Math.PI / 2 });+ });+ }+ return rows.map(({ p, w }, i) => {+ const q = placed.get(i), at = q?.at ?? w.at, facing = q?.facing ?? w.facing;+ const a = w.activity;+ const hidden = a.kind === "stay" && !a.outside && d.places.get(a.at)?.inside === true;+ const dist = Math.hypot(at[0] - camera[0], at[2] - camera[2]);+ return { id: p.id, ...w, at, facing, level: hidden ? ("inside" as const) : levelAt(dist, range, was?.get(p.id)) };+ });+}++/** The far level: how many people are at each kind of place (or on the move, by mode) in each hour of the day. */+export function census(d: Day): Map<string, number[]> {+ const out = new Map<string, number[]>();+ const add = (k: string, h: number) => { const a = out.get(k) ?? new Array(24).fill(0); a[h]++; out.set(k, a); };+ for (const p of d.people) {+ const day = d.days.get(p.id)!;+ for (let h = 0; h < 24; h++) {+ const a = day.find((x) => x.from <= h * 60 + 30 && h * 60 + 30 < x.to) ?? day[day.length - 1];+ add(a.kind === "trip" ? `moving:${a.mode}` : d.places.get(a.at)?.kind ?? "unknown", h);+ }+ }+ return out;+}++/** Something everyone near feels: a gun's report through the ground, a shout, a horse bolting. */+export interface Event { kind: string; at: V3; strength: number }++/** How a person meets an event, in the stage's words: a look toward it (or at the ground, for a shock underfoot),+ * a flinch or a stop, a run for the nervous; how long they freeze. Nerves and age decide; distance softens it. */+export function react(p: Person, e: Event, at: V3, seed = 0): { acts: string[]; freeze: number } {+ const r = rng(`${p.seed}-${e.kind}-${seed}`);+ const d = Math.hypot(e.at[0] - at[0], e.at[2] - at[2]);+ const felt = e.strength / (1 + d / 50);+ if (felt < 0.08) return { acts: [], freeze: 0 };+ const t: Traits = p.traits;+ const acts: string[] = [];+ const under = e.kind === "tremor" || e.kind === "underground";+ acts.push(under ? "look down at the ground" : "look toward the sound");+ if (felt > 0.5 && t.neuroticism > 0.6) acts.push(r.chance(0.5) ? "flinch and duck" : "cover the ears");+ else if (felt > 0.25) acts.push("stop dead");+ if (felt > 0.7 && t.neuroticism > 0.75 && p.age < 60) acts.push("hurry away");+ else if (t.extraversion > 0.65 && felt > 0.2) acts.push("turn to the nearest person");+ return { acts, freeze: Math.round((0.6 + felt * (0.8 + t.neuroticism)) * 10) / 10 };+}diff --git a/sdk/character/src/people/day.ts b/sdk/character/src/people/day.tsnew file mode 100644index 00000000..354c2505--- /dev/null+++ b/sdk/character/src/people/day.ts@@ -0,0 +1,160 @@+// A person's day: the role's blocks that apply on that date, at real places, at times moved by how punctual the person+// is, with the trips between them (a mode drawn by the person's own leanings and the distance), and habits slotted in+// where they fit. The same person and date give the same day.+import { leaned } from "./persona";+import { rng } from "./rng";+import type { Activity, Block, Habit, Minute, Mode, Person, Place, Role, Router, V3 } from "./types";++/** Speeds by mode in metres a second, door to door (a tram's counts its stops; a walk is an ordinary adult's). */+export const SPEED: Record<Mode, number> = { walk: 1.25, tram: 4.2, bus: 3.6, cab: 3.4, cart: 1.6, bicycle: 3.8, car: 6, train: 9 };+/** Below this a trip is walked whatever the person's leaning (metres). */+export const WALK_UNDER = 900;++/** A straight line, a fifth longer for the corners a street makes. A project's router follows its streets. */+export const straight: Router = (a, b) => {+ const d = Math.hypot(b.at[0] - a.at[0], b.at[2] - a.at[2]) * 1.2;+ return { path: [a.at, b.at], metres: d };+};++/** How fast this person walks: age, the gait and the cold (people hurry in the cold, the old slow down). */+export function walkSpeed(p: Person, cold = 0.5): number {+ const age = p.age < 25 ? 1.05 : p.age < 55 ? 1 : p.age < 70 ? 0.86 : 0.74;+ const gait = p.gait === "old" ? 0.85 : p.gait === "hurried" ? 1.15 : p.gait === "tired" ? 0.92 : p.gait === "march" ? 1.1 : 1;+ return SPEED.walk * age * gait * (1 + 0.08 * (cold - 0.5));+}++export interface DayInput {+ person: Person;+ role: Role;+ /** the date: its weekday (0 Sunday) decides which blocks apply, its key varies the day ("1917-12-03") */+ date: { key: string; weekday: number };+ /** the places by id, and all places of a kind (for blocks "at" a kind: the nearest open one, else any) */+ places: Map<string, Place>;+ byKind: Map<string, Place[]>;+ router?: Router;+ /** how cold it is (0 mild to 1 bitter): pace and how many take the tram */+ cold?: number;+}++function placeFor(at: string, p: Person, inp: DayInput, near: Place, r: ReturnType<typeof rng>): Place | undefined {+ if (at === "home") return inp.places.get(p.home);+ if (at === "work") return p.work ? inp.places.get(p.work) : undefined;+ if (at === "here") return near;+ const all = inp.byKind.get(at);+ if (!all || all.length === 0) return undefined;+ // the nearest few, one of them (people do not all use the one nearest shop)+ const ranked = [...all].sort((a, b) => Math.hypot(a.at[0] - near.at[0], a.at[2] - near.at[2]) - Math.hypot(b.at[0] - near.at[0], b.at[2] - near.at[2]));+ return ranked[Math.min(ranked.length - 1, Math.floor(Math.pow(r.next(), 2) * Math.min(4, ranked.length)))];+}++function modeFor(p: Person, metres: number, cold: number, r: ReturnType<typeof rng>): Mode {+ if (metres < WALK_UNDER) return "walk";+ const w = { ...p.modes };+ // the further and the colder, the more the tram (or whatever the person rides) is worth the fare+ const far = Math.min(1, (metres - WALK_UNDER) / 2500);+ for (const k of Object.keys(w) as Mode[]) if (k !== "walk") w[k] = (w[k] ?? 0) * (1 + 2 * far + cold);+ return r.weighted(w);+}++function applies(b: Block | Habit, weekday: number) {+ return !b.days || b.days.includes(weekday);+}++/** The day's activities, in order, covering 00:00 to 24:00. */+export function dayOf(inp: DayInput): Activity[] {+ const { person: p, role, date } = inp;+ const r = rng(`${p.seed}-${date.key}`);+ const cold = inp.cold ?? 0.5;+ const route = inp.router ?? straight;+ const home = inp.places.get(p.home)!;+ // punctual people keep to their times: jitter scaled from 1.6x (careless) to 0.4x (exact)+ const keep = 1.6 - 1.2 * p.traits.conscientiousness;+ type Stay = { what: string; at: Place; from: Minute; to: Minute; acts?: string[]; outside?: boolean };+ const stays: Stay[] = [];+ let here = home;+ for (const b of role.day) {+ if (!applies(b, date.weekday)) continue;+ if (b.chance !== undefined && !r.chance(b.chance)) continue;+ const stops = b.round ? b.round.stops : 1;+ let from = b.from + Math.round(r.normal(0, (b.jitter ?? 10) * keep));+ const end = b.to ?? from + (b.minutes ?? 60);+ for (let s = 0; s < stops; s++) {+ const at = placeFor(b.at, p, inp, here, r) ?? here;+ const to = b.round ? Math.min(end, from + b.round.dwell) : end + Math.round(r.normal(0, (b.jitter ?? 10) * keep * 0.5));+ stays.push({ what: b.what, at, from, to: Math.max(from + 1, to), acts: b.acts, outside: b.outside });+ here = at;+ from = to + 3;+ }+ }+ // habits, each on its own chance for the day, leaned by traits, slotted at their place within their window+ for (const h of role.habits ?? []) {+ if (!p.habits.includes(h.id) || !applies(h, date.weekday)) continue;+ if (!r.fork(h.id).chance(leaned(h.chance, p.traits, h.leans))) continue;+ const start = h.from + Math.floor(r.next() * Math.max(1, h.to - h.from - h.minutes));+ const host = [...stays].reverse().find((s) => s.from <= start) ?? stays[0];+ const at = h.at === "here" && host ? host.at : placeFor(h.at, p, inp, host?.at ?? home, r) ?? home;+ stays.push({ what: h.act, at, from: start, to: start + h.minutes, outside: h.outside });+ }+ stays.sort((a, b) => a.from - b.from);+ // home before the first block and after the last; overlaps clipped (a later block wins its start)+ const out: Activity[] = [];+ let at = home, t = 0;+ // a trip planned before it is taken: the mode first (by distance, cold and the person's leanings), then how long+ // that mode takes, so the person leaves in time for the block by the way they actually travel+ const plan = (dest: Place) => {+ const way = route(at, dest, "walk");+ const mode = modeFor(p, way.metres, cold, r);+ const path = mode === "walk" ? way : route(at, dest, mode);+ const speed = mode === "walk" ? walkSpeed(p, cold) : SPEED[mode];+ const minutes = Math.max(1, Math.round(path.metres / speed / 60 + (mode === "tram" || mode === "bus" ? 6 : 0)));+ return { mode, path, minutes };+ };+ const take = (dest: Place, leaveAt: Minute, what: string, way: ReturnType<typeof plan>) => {+ out.push({ kind: "trip", what, from: leaveAt, to: leaveAt + way.minutes, leave: at.id, arrive: dest.id, mode: way.mode, path: way.path.path, metres: Math.round(way.path.metres) });+ at = dest;+ return leaveAt + way.minutes;+ };+ const legTo = (dest: Place, leaveAt: Minute, what: string) => (dest.id === at.id ? leaveAt : take(dest, leaveAt, what, plan(dest)));+ for (const s of stays) {+ if (s.to <= t) continue;+ if (s.at.id !== at.id) {+ // leave in time to arrive at the block's start; one who arrives early waits for it, one who can't make it is late+ const way = plan(s.at);+ const leave = Math.max(t, s.from - way.minutes);+ if (leave > t) out.push({ kind: "stay", what: at.id === p.home ? "home" : "wait", at: at.id, from: t, to: leave });+ t = take(s.at, leave, `to ${s.what}`, way);+ if (s.from > t) {+ out.push({ kind: "stay", what: "wait", at: at.id, from: t, to: s.from });+ t = s.from;+ }+ } else if (s.from > t) {+ out.push({ kind: "stay", what: at.id === p.home ? "home" : "wait", at: at.id, from: t, to: s.from });+ t = s.from;+ }+ const to = Math.max(t + 1, s.to);+ out.push({ kind: "stay", what: s.what, at: s.at.id, from: t, to, ...(s.acts ? { acts: s.acts } : {}), ...(s.outside ? { outside: true } : {}) });+ t = to;+ }+ if (at.id !== home.id && t < 1440) t = legTo(home, t, "home");+ if (t < 1440) out.push({ kind: "stay", what: "home", at: home.id, from: t, to: 1440 });+ return out;+}++/** Where a person is at a minute of their day, and what they are doing: a place (standing at its door) or a point+ * along a trip, with the direction they face. */+export function whereAt(day: Activity[], places: Map<string, Place>, m: Minute): { at: V3; facing: number; doing: string; mode?: Mode; activity: Activity } {+ const a = day.find((x) => x.from <= m && m < x.to) ?? day[day.length - 1];+ if (a.kind === "stay") {+ const pl = places.get(a.at)!;+ return { at: pl.at, facing: pl.facing ?? 0, doing: a.what, activity: a };+ }+ const u = Math.min(1, Math.max(0, (m - a.from) / Math.max(1, a.to - a.from)));+ const P = a.path;+ const seg = P.slice(1).map((q, i) => Math.hypot(q[0] - P[i][0], q[2] - P[i][2]));+ const total = seg.reduce((x, y) => x + y, 0) || 1;+ let d = u * total, i = 0;+ while (i < seg.length - 1 && d > seg[i]) d -= seg[i++];+ const A = P[i], B = P[Math.min(i + 1, P.length - 1)], k = seg[i] ? d / seg[i] : 0;+ const at: V3 = [A[0] + (B[0] - A[0]) * k, A[1] + (B[1] - A[1]) * k, A[2] + (B[2] - A[2]) * k];+ return { at, facing: Math.atan2(B[0] - A[0], B[2] - A[2]), doing: a.what, mode: a.mode, activity: a };+}diff --git a/sdk/character/src/people/persona.ts b/sdk/character/src/people/persona.tsnew file mode 100644index 00000000..383127d5--- /dev/null+++ b/sdk/character/src/people/persona.ts@@ -0,0 +1,100 @@+// A person drawn from a role: sex, age, traits, habits, face, body, hair, dress, what they carry, how they travel and+// how they walk, all from one seed, so person 12 of a place is the same person on every run and every machine.+import { rng, type Rng } from "./rng";+import type { Body, Face, Mode, Person, Place, Role, Sex, Traits } from "./types";++export const TRAITS: (keyof Traits)[] = ["openness", "conscientiousness", "extraversion", "agreeableness", "neuroticism"];++/** Names a project gives for its people, by sex: given names and family names, each list as common first. */+export interface Names {+ given: Record<Sex, string[]>;+ family: string[];+}++/** What a project says about its people beyond the role: names, the hair styles and colours of the place and time,+ * the face model's tone range, and the share of each iris colour. Everything has a default. */+export interface Folk {+ names: Names;+ /** hair styles by sex, each with a weight; colours (words a hair tool reads) by weight */+ hairStyles?: Record<Sex, Record<string, number>>;+ hairColours?: Record<string, number>;+ /** facial hair for men by age band: style -> weight (style "none" for clean-shaven) */+ facialHair?: { young: Record<string, number>; middle: Record<string, number>; old: Record<string, number> };+ irises?: Record<string, number>;+ /** the face model's build for this population: mean and sd (a hungry city leans thin: below 0) */+ build?: [number, number];+ /** heights by sex in metres: mean and sd */+ heights?: Record<Sex, [number, number]>;+ /** names no one may be given (a real resident's, for a place drawn from its records): a drawn name this rejects is+ * drawn again, up to 50 times, then the person is named by role and number */+ avoid?: (given: string, family: string) => boolean;+}++const DEFAULT_HEIGHT: Record<Sex, [number, number]> = { f: [1.6, 0.06], m: [1.71, 0.065] };++function traitsFor(role: Role, r: Rng): Traits {+ const sd = role.spread ?? 0.15;+ const t = {} as Traits;+ for (const k of TRAITS) t[k] = Math.min(1, Math.max(0, r.normal(role.traits?.[k] ?? 0.5, sd)));+ return t;+}++/** Leans of a chance by traits: each weight times (trait - 0.5), added to the chance's log-odds. */+export function leaned(chance: number, traits: Traits, leans?: Partial<Record<keyof Traits, number>>): number {+ if (!leans) return chance;+ const c = Math.min(0.999, Math.max(0.001, chance));+ let logit = Math.log(c / (1 - c));+ for (const k of TRAITS) logit += (leans[k] ?? 0) * (traits[k] - 0.5) * 4;+ return 1 / (1 + Math.exp(-logit));+}++/** The gait a person keeps when nothing else sets it: a role's own (marching), else from age and nerves. Names are+ * the motion library's situations (100STYLE's "Old", "Tired", "Proud", ...). */+export function gaitOf(role: Role, age: number, traits: Traits, r: Rng): string {+ if (role.gait) return role.gait;+ if (age >= 68) return "old";+ if (age >= 58 && r.chance(0.5)) return "old";+ if (traits.neuroticism > 0.72) return "hurried";+ if (traits.extraversion > 0.75 && traits.neuroticism < 0.35) return "proud";+ return r.chance(0.35) ? "tired" : "neutral";+}++function nameFor(folk: Folk, sex: Sex, r: Rng, fallback: string): string {+ for (let k = 0; k < 50; k++) {+ const given = r.pick(folk.names.given[sex]), family = r.pick(folk.names.family);+ if (!folk.avoid?.(given, family)) return `${given} ${family}`;+ }+ return fallback;+}++export function makePerson(id: string, role: Role, folk: Folk, home: Place, seed: number, work?: Place): Person {+ const r = rng(seed);+ const sex: Sex = r.chance(role.women) ? "f" : "m";+ const age = Math.round(role.ages[0] + (role.ages[1] - role.ages[0]) * Math.pow(r.next(), 1.15));+ const traits = traitsFor(role, r.fork("traits"));+ const name = nameFor(folk, sex, r.fork("name"), `${role.title} ${id}`);+ const habits = (role.habits ?? []).filter((h) => r.fork(h.id).next() < leaned(0.5, traits, h.leans)).map((h) => h.id);+ const [bm, bsd] = folk.build ?? [0, 0.8];+ const build = Math.max(-2.5, Math.min(2.5, r.normal(bm + (age > 45 ? 0.3 : 0), bsd)));+ const greyAt = r.normal(48, 9);+ const grey = Math.max(0, Math.min(1, (age - greyAt) / 22));+ const style = r.weighted(folk.hairStyles?.[sex] ?? { short: 1 });+ const colour = r.weighted(folk.hairColours ?? { brown: 1 });+ const band = age < 30 ? "young" : age < 50 ? "middle" : "old";+ const fh = sex === "m" && folk.facialHair ? r.weighted(folk.facialHair[band]) : "none";+ const face: Face = {+ kind: "crowd", seed: r.int(1, 2 ** 30), build, age, iris: r.weighted(folk.irises ?? { brown: 1 }),+ stubble: sex === "m" ? Math.round(r.next() * 60) / 100 : 0,+ ...(fh === "none" ? {} : fh.startsWith("beard") ? { beard: fh } : { moustache: fh }),+ };+ const [hm, hsd] = (folk.heights ?? DEFAULT_HEIGHT)[sex];+ const body: Body = { height: Math.round(r.normal(hm, hsd) * 100) / 100, build: Math.round(build * 10) / 10 };+ const dress = r.weighted(role.dress);+ const carry = Object.entries(role.carry ?? {}).filter(([k, p]) => r.fork(`carry-${k}`).chance(p)).map(([k]) => k);+ const modes: Partial<Record<Mode, number>> = role.modes ?? { walk: 1 };+ return {+ id, name, sex, age, role: role.id, ...(role.rank ? { rank: role.rank } : {}), home: home.id, ...(work ? { work: work.id } : {}),+ traits, habits, face, body, hair: { style, colour, grey: Math.round(grey * 100) / 100 }, dress, carry, modes,+ gait: gaitOf(role, age, traits, r.fork("gait")), seed,+ };+}diff --git a/sdk/character/src/people/rng.ts b/sdk/character/src/people/rng.tsnew file mode 100644index 00000000..7b755d0e--- /dev/null+++ b/sdk/character/src/people/rng.ts@@ -0,0 +1,55 @@+// A seeded random stream for people: the same seed gives the same person, the same day and the same choices on every+// machine, so a render and live play agree (sdk/guides/craft/bevy/games.md: a game is a pure step over its input).++/** A random stream from a seed: `next()` is uniform in [0, 1). splitmix32: small, fast and well mixed. */+export interface Rng {+ next(): number;+ /** a whole number in [lo, hi] */+ int(lo: number, hi: number): number;+ /** a normal draw, mean `mu`, standard deviation `sd` */+ normal(mu?: number, sd?: number): number;+ /** one of `xs`, each as likely */+ pick<T>(xs: readonly T[]): T;+ /** one key of `w`, as likely as its weight */+ weighted<K extends string>(w: Readonly<Partial<Record<K, number>>>): K;+ /** true with chance `p` */+ chance(p: number): boolean;+ /** a stream of its own for `label`, unaffected by how much of this one has been drawn */+ fork(label: string | number): Rng;+}++/** A 32-bit hash of a string, for seeds made from names ("person-12", "day-1917-12-03"). */+export function hash(s: string | number): number {+ let h = 0x811c9dc5 ^ 0;+ const t = String(s);+ for (let i = 0; i < t.length; i++) h = Math.imul(h ^ t.charCodeAt(i), 0x01000193);+ return h >>> 0;+}++export function rng(seed: number | string): Rng {+ const base = typeof seed === "number" ? seed >>> 0 : hash(seed);+ let s = base;+ const next = () => {+ s = (s + 0x9e3779b9) >>> 0;+ let z = s;+ z = Math.imul(z ^ (z >>> 16), 0x85ebca6b) >>> 0;+ z = Math.imul(z ^ (z >>> 13), 0xc2b2ae35) >>> 0;+ return ((z ^ (z >>> 16)) >>> 0) / 4294967296;+ };+ const self: Rng = {+ next,+ int: (lo, hi) => lo + Math.floor(next() * (hi - lo + 1)),+ normal: (mu = 0, sd = 1) => mu + sd * Math.sqrt(-2 * Math.log(1 - next())) * Math.cos(2 * Math.PI * next()),+ pick: (xs) => xs[Math.floor(next() * xs.length)],+ weighted: (w) => {+ const ks = Object.keys(w) as (keyof typeof w)[];+ const total = ks.reduce((a, k) => a + (w[k] ?? 0), 0);+ let r = next() * total;+ for (const k of ks) if ((r -= w[k] ?? 0) < 0) return k as never;+ return ks[ks.length - 1] as never;+ },+ chance: (p) => next() < p,+ fork: (label) => rng((base ^ hash(label)) >>> 0),+ };+ return self;+}diff --git a/sdk/character/src/people/types.ts b/sdk/character/src/people/types.tsnew file mode 100644index 00000000..0c17092d--- /dev/null+++ b/sdk/character/src/people/types.ts@@ -0,0 +1,172 @@+// The people of a place, as data: who they are (a role, a rank, a trade, a face, a body, what they wear and carry), what+// they are like (traits, habits) and what they do each hour (a day of activities and the trips between them). A+// project gives the roles and places; the SDK makes the people and their days, the same from the same seed.++/** Minutes after midnight (0 to 1439); a day is one calendar day. */+export type Minute = number;+export type V3 = [number, number, number];+export type Sex = "f" | "m";++/** How a person gets about. */+export type Mode = "walk" | "tram" | "bus" | "cab" | "cart" | "bicycle" | "car" | "train";++/** What a person is like, each 0 to 1 (0.5 is ordinary): the five broad traits, which the SDK reads for timing+ * (conscientious people keep to their times), company (extraverts stop to talk), nerves (neurotic people flinch and+ * hurry) and manners (agreeable people give way). */+export interface Traits {+ openness: number;+ conscientiousness: number;+ extraversion: number;+ agreeableness: number;+ neuroticism: number;+}++/** How a person is, each 0 to 1, changing through the day: what moves gait, pace and reactions. */+export interface Condition {+ hunger: number;+ cold: number;+ fatigue: number;+ fear: number;+}++/** A thing a person does by habit: in a window of the day, at a kind of place (or wherever they are), with a chance a+ * day, for some minutes, as an act a body can perform ("smokes a pipe on the doorstep", "reads the paper"). */+export interface Habit {+ id: string;+ /** what the body does: a stage act's do line, or a clip's situation */+ act: string;+ /** when it may happen */+ from: Minute;+ to: Minute;+ /** where: a place kind, "home", "work" or "here" (wherever the person is then) */+ at: string;+ minutes: number;+ /** the chance it happens on a given day, before traits */+ chance: number;+ /** traits that make it likelier (+) or rarer (-), each a weight on (trait - 0.5) */+ leans?: Partial<Record<keyof Traits, number>>;+ /** only on these days of the week (0 Sunday) */+ days?: number[];+ /** done out of doors (see Block.outside) */+ outside?: boolean;+}++/** One block of a role's day: what, where and roughly when. A day is the blocks that apply, in order, with the+ * trips between them added. */+export interface Block {+ what: string;+ /** a place kind, "home" or "work" */+ at: string;+ /** when it starts, and when it ends (or how long it lasts) */+ from: Minute;+ to?: Minute;+ minutes?: number;+ /** minutes either way the start may move, before traits (punctual people move less) */+ jitter?: number;+ /** the chance this block happens on a given day */+ chance?: number;+ /** only on these days of the week (0 Sunday) */+ days?: number[];+ /** acts performed there, in the stage's words (go, wait, look, face, sit, take, do) */+ acts?: string[];+ /** done out of doors at the place (a queue at a shop's door, a beat corner, a guard post), so the person is seen+ * even when the place is `inside`; people out at the same door stand in a queue along the front */+ outside?: boolean;+ /** a block that moves: a patrol or a round goes from place to place of its kind */+ round?: { stops: number; dwell: number };+}++/** A role in a place: a profession, a rank in a service, a household part. The project lists its roles with how+ * many of each the place holds; the SDK draws people from them. */+export interface Role {+ id: string;+ title: string;+ /** who fills it: the share of women (0 to 1) and the range of ages */+ women: number;+ ages: [number, number];+ /** the traits people in the role lean to (each 0 to 1; unset, 0.5) and how far one person may stray (sd, 0.15) */+ traits?: Partial<Traits>;+ spread?: number;+ /** a rank the role carries (a project's rank table names its insignia) */+ rank?: string;+ /** the dress, by the project's kit ids: one is drawn per person, as likely as its weight */+ dress: Record<string, number>;+ /** what they carry, by the project's thing ids, each with its chance */+ carry?: Record<string, number>;+ /** how they get about, by weight (walk unless said) */+ modes?: Partial<Record<Mode, number>>;+ /** a vehicle that is their work (a tram's driver, a cabman): its kind and their place on it */+ vehicle?: { kind: string; station: string };+ /** the kind of place they work at, and how far from home it may be (metres) */+ work?: { at: string; within?: number };+ /** their day */+ day: Block[];+ /** habits open to the role */+ habits?: Habit[];+ /** a gait the role keeps (a soldier marching, an officer upright), else one from age and condition */+ gait?: string;+}++/** A place people go: a home, a shop, a workplace, a stop, a post. */+export interface Place {+ id: string;+ kind: string;+ at: V3;+ /** the door's facing (radians about +Y), where people queue or stand */+ facing?: number;+ /** open hours, if it has them */+ opens?: [Minute, Minute];+ /** how many it holds (homes: households; workplaces: hands) */+ holds?: number;+ /** being there hides a person (a home, a works, a school): no character is drawn for them unless their block is+ * `outside`. Unset: a place out of doors (a corner, a post, a courtyard, a square) */+ inside?: boolean;+}++/** A face: a hero's own head (made from its pictures) or a crowd head drawn from a face model by these numbers. */+export type Face =+ | { kind: "hero"; id: string }+ | { kind: "crowd"; seed: number; build: number; tone?: V3; iris: string; stubble: number; age: number; moustache?: string; beard?: string };++/** A body: the standard skeleton's shape, by numbers the body build reads. */+export interface Body {+ height: number;+ build: number;+ /** the person's posture: a stoop, a limp, a missing limb */+ marks?: string[];+}++/** A person in the place. */+export interface Person {+ id: string;+ name: string;+ sex: Sex;+ age: number;+ role: string;+ rank?: string;+ trade?: string;+ home: string;+ work?: string;+ traits: Traits;+ habits: string[];+ face: Face;+ body: Body;+ hair: { style: string; colour: string; grey: number };+ dress: string;+ carry: string[];+ modes: Partial<Record<Mode, number>>;+ gait: string;+ seed: number;+}++/** One stretch of a person's day: at a place doing something, or on the way from one place to another. */+export type Activity =+ | { kind: "stay"; what: string; at: string; from: Minute; to: Minute; acts?: string[]; outside?: boolean }+ | { kind: "trip"; what: string; from: Minute; to: Minute; leave: string; arrive: string; mode: Mode; path: V3[]; metres: number };++/** A way from one place to another for a mode: the project's street graph, tram lines, or a straight line. */+export type Router = (from: Place, to: Place, mode: Mode) => { path: V3[]; metres: number };++/** The level a person is simulated at, by distance from the camera (docs/character.feature CH52); "inside" for a+ * person hidden in a building, who is counted and never drawn. */+export type Level = "near" | "middle" | "far";diff --git a/sdk/character/test/people.test.ts b/sdk/character/test/people.test.tsnew file mode 100644index 00000000..0342c9c2--- /dev/null+++ b/sdk/character/test/people.test.ts@@ -0,0 +1,166 @@+// raea/people (src/people.ts, docs/character.feature CH50-CH53): people drawn from roles, their days, where they are+// at a minute, the levels of detail and how they meet an event.+import { expect, test } from "bun:test";+import { census, cityDay, dayOf, levelAt, populate, react, snapshot, whereAt, type Folk, type Place, type Role } from "../src/people";++const folk: Folk = {+ names: { given: { f: ["Anna", "Martha", "Frieda"], m: ["Karl", "Otto", "Paul"] }, family: ["Schulz", "Müller", "Krüger"] },+ irises: { blue: 2, brown: 1 }, build: [-0.8, 0.6],+ facialHair: { young: { none: 3, moustache: 1 }, middle: { none: 1, moustache: 2 }, old: { moustache: 2, "beard-full": 1 } },+};+const places: Place[] = [+ ...Array.from({ length: 20 }, (_, i) => ({ id: `h${i}`, kind: "home", at: [i * 30, 0, 0] as [number, number, number], holds: 4 })),+ { id: "bakery", kind: "bakery", at: [100, 0, 40], opens: [6 * 60, 19 * 60] },+ { id: "bakery2", kind: "bakery", at: [500, 0, 40], opens: [6 * 60, 19 * 60] },+ { id: "works", kind: "munitions", at: [2500, 0, 1800], holds: 200 },+ { id: "post1", kind: "post", at: [300, 0, 10] },+ { id: "post2", kind: "post", at: [400, 0, -60] },+];+const roles: Role[] = [+ {+ id: "housewife", title: "Housewife", women: 1, ages: [22, 70], dress: { "winter-coat": 2, shawl: 1 }, carry: { basket: 0.8 },+ traits: { conscientiousness: 0.6 },+ day: [{ what: "queue for bread", at: "bakery", from: 6 * 60, minutes: 120, jitter: 30, acts: ["wait", "look at the shop door"] },+ { what: "market", at: "bakery", from: 10 * 60 + 30, minutes: 45, chance: 0.5 }],+ habits: [{ id: "church", act: "church", from: 9 * 60, to: 11 * 60, at: "home", minutes: 60, chance: 0.9, days: [0] }],+ },+ {+ id: "munitions-worker", title: "Munitions worker", women: 0.8, ages: [16, 45], dress: { overall: 1 }, work: { at: "munitions" },+ modes: { walk: 1, tram: 3 }, day: [{ what: "shift", at: "work", from: 6 * 60, to: 18 * 60, jitter: 5 }],+ },+ {+ id: "sentry", title: "Landsturm sentry", women: 0, ages: [38, 48], rank: "landsturmmann", dress: { "greatcoat-m15": 1 }, gait: "march",+ traits: { conscientiousness: 0.75 },+ day: [{ what: "patrol", at: "post", from: 8 * 60, to: 16 * 60, round: { stops: 6, dwell: 50 }, jitter: 2 }],+ },+];+const mix = { housewife: 50, "munitions-worker": 20, sentry: 2 };++test("the same seed draws the same people, a different one others", () => {+ const a = populate({ roles, places, folk, mix, seed: "leipziger" }), b = populate({ roles, places, folk, mix, seed: "leipziger" });+ const c = populate({ roles, places, folk, mix, seed: "jerusalemer" });+ expect(a.length).toBe(72);+ expect(JSON.stringify(a)).toBe(JSON.stringify(b));+ expect(a.map((p) => p.name).join()).not.toBe(c.map((p) => p.name).join());+});++test("a role's sex, ages, rank and gait hold for everyone drawn from it", () => {+ const ps = populate({ roles, places, folk, mix, seed: 3 });+ for (const p of ps.filter((x) => x.role === "housewife")) { expect(p.sex).toBe("f"); expect(p.age).toBeGreaterThanOrEqual(22); expect(p.age).toBeLessThanOrEqual(70); }+ for (const p of ps.filter((x) => x.role === "sentry")) { expect(p.rank).toBe("landsturmmann"); expect(p.gait).toBe("march"); expect(p.sex).toBe("m"); }+ // workers have a workplace; faces are crowd faces with a seed of their own+ expect(ps.filter((x) => x.role === "munitions-worker").every((p) => p.work === "works")).toBe(true);+ expect(new Set(ps.map((p) => (p.face.kind === "crowd" ? p.face.seed : 0))).size).toBe(ps.length);+});++test("a day covers 00:00 to 24:00 with no gaps, and a trip joins every change of place", () => {+ const ps = populate({ roles, places, folk, mix, seed: 5 });+ const d = cityDay(ps, roles, places, { key: "1917-12-03", weekday: 1 });+ for (const p of ps) {+ const day = d.days.get(p.id)!;+ expect(day[0].from).toBe(0);+ expect(day[day.length - 1].to).toBe(1440);+ for (let i = 1; i < day.length; i++) expect(day[i].from).toBe(day[i - 1].to);+ let at = p.home;+ for (const a of day) {+ if (a.kind === "trip") { expect(a.leave).toBe(at); at = a.arrive; } else expect(a.at).toBe(at);+ }+ }+});++test("a far commute in the cold goes by tram; a short errand is walked", () => {+ const ps = populate({ roles, places, folk, mix, seed: 9 });+ const d = cityDay(ps, roles, places, { key: "1917-12-04", weekday: 2 }, undefined, 0.9);+ const trips = [...d.days.values()].flat().filter((a) => a.kind === "trip");+ const far = trips.filter((t) => t.kind === "trip" && t.metres > 2500), near = trips.filter((t) => t.kind === "trip" && t.metres < 900);+ expect(far.filter((t) => t.kind === "trip" && t.mode === "tram").length / far.length).toBeGreaterThan(0.6);+ expect(near.every((t) => t.kind === "trip" && t.mode === "walk")).toBe(true);+});++test("punctual people start their shift closer to its time than careless ones", () => {+ const ps = populate({ roles, places, folk, mix: { "munitions-worker": 200 }, seed: 11 });+ const d = cityDay(ps, roles, places, { key: "1917-12-05", weekday: 3 });+ const late = (p: (typeof ps)[number]) => Math.abs(d.days.get(p.id)!.find((a) => a.kind === "stay" && a.what === "shift")!.from - 360);+ const exact = ps.filter((p) => p.traits.conscientiousness > 0.65), loose = ps.filter((p) => p.traits.conscientiousness < 0.35);+ const mean = (xs: number[]) => xs.reduce((a, b) => a + b, 0) / xs.length;+ expect(mean(exact.map(late))).toBeLessThan(mean(loose.map(late)));+});++test("a patrol is a round of posts; Sunday brings church", () => {+ const ps = populate({ roles, places, folk, mix, seed: 13 });+ const sun = cityDay(ps, roles, places, { key: "1917-12-02", weekday: 0 });+ const sentry = ps.find((p) => p.role === "sentry")!;+ const posts = sun.days.get(sentry.id)!.filter((a) => a.kind === "stay" && a.what === "patrol");+ expect(posts.length).toBe(6);+ const church = ps.filter((p) => p.habits.includes("church")).filter((p) => sun.days.get(p.id)!.some((a) => a.kind === "stay" && a.what === "church"));+ expect(church.length).toBeGreaterThan(0);+ const mon = cityDay(ps, roles, places, { key: "1917-12-03", weekday: 1 });+ expect([...mon.days.values()].flat().some((a) => a.kind === "stay" && a.what === "church")).toBe(false);+});++test("whereAt walks a trip's path; snapshot and census count everyone", () => {+ const ps = populate({ roles, places, folk, mix, seed: 17 });+ const d = cityDay(ps, roles, places, { key: "1917-12-03", weekday: 1 });+ const day = d.days.get(ps.find((p) => p.role === "munitions-worker")!.id)!;+ const trip = day.find((a) => a.kind === "trip")!;+ const mid = whereAt(day, d.places, (trip.from + trip.to) / 2);+ expect(mid.activity).toBe(trip);+ const s = snapshot(d, 7 * 60, [0, 0, 0], { near: 150, middle: 1500 });+ expect(s.length).toBe(ps.length);+ expect(s.some((x) => x.level === "far")).toBe(true);+ const c = census(d);+ for (let h = 0; h < 24; h++) expect([...c.values()].reduce((a, v) => a + v[h], 0)).toBe(ps.length);+});++test("levels change with hysteresis at their edges", () => {+ const range = { near: 150, middle: 1500 };+ expect(levelAt(140, range)).toBe("near");+ expect(levelAt(160, range, "near")).toBe("near");+ expect(levelAt(170, range, "near")).toBe("middle");+ expect(levelAt(140, range, "middle")).toBe("middle");+ expect(levelAt(130, range, "middle")).toBe("near");+});++test("a shock underfoot turns eyes to the ground; the nervous flinch, the far feel nothing", () => {+ const ps = populate({ roles, places, folk, mix, seed: 19 });+ const e = { kind: "tremor", at: [0, 0, 0] as [number, number, number], strength: 1 };+ const nervous = ps.find((p) => p.traits.neuroticism > 0.65)!;+ const near = react(nervous, e, [5, 0, 0]);+ expect(near.acts[0]).toBe("look down at the ground");+ expect(near.acts.some((a) => a === "flinch and duck" || a === "cover the ears")).toBe(true);+ expect(react(nervous, e, [5000, 0, 0]).acts.length).toBe(0);+});++test("dayOf is the same for the same person and date", () => {+ const ps = populate({ roles, places, folk, mix, seed: 23 });+ const pm = new Map(places.map((p) => [p.id, p])), byKind = new Map<string, Place[]>();+ for (const p of places) byKind.set(p.kind, [...(byKind.get(p.kind) ?? []), p]);+ const inp = { person: ps[0], role: roles[0], date: { key: "1918-01-15", weekday: 2 }, places: pm, byKind };+ expect(JSON.stringify(dayOf(inp))).toBe(JSON.stringify(dayOf(inp)));+});++test("a name the place rejects (a real resident's) is never given", () => {+ const avoid = (_g: string, f: string) => f === "Müller" || f === "Schulz";+ const ps = populate({ roles, places, folk: { ...folk, avoid }, mix, seed: 29 });+ expect(ps.every((p) => !p.name.endsWith(" Müller") && !p.name.endsWith(" Schulz"))).toBe(true);+ // every family name rejected: named by role and number instead+ const none = populate({ roles, places, folk: { ...folk, avoid: () => true }, mix: { sentry: 1 }, seed: 31 });+ expect(none[0].name).toBe("Landsturm sentry p0");+});++test("people inside are counted, not drawn; a queue stands in a line along the front, first come nearest", () => {+ const inside = places.map((p) => (p.kind === "home" || p.kind === "munitions" ? { ...p, inside: true } : p.kind === "bakery" ? { ...p, inside: true, facing: 0 } : p));+ const queueRoles = roles.map((r) => (r.id === "housewife" ? { ...r, day: r.day.map((b) => (b.what === "queue for bread" ? { ...b, outside: true } : b)) } : r));+ const ps = populate({ roles: queueRoles, places: inside, folk, mix, seed: 37 });+ const d = cityDay(ps, queueRoles, inside, { key: "1917-12-03", weekday: 1 });+ const s = snapshot(d, 2 * 60, [0, 0, 0], { near: 150, middle: 1500 });+ expect(s.every((x) => x.level === "inside")).toBe(true);+ const q = snapshot(d, 7 * 60 + 15, [0, 0, 0], { near: 150, middle: 1500 }).filter((x) => x.doing === "queue for bread");+ expect(q.length).toBeGreaterThan(5);+ expect(q.every((x) => x.level !== "inside")).toBe(true);+ // no two in the queue on the same spot; each 0.65 m from the next along the front+ for (const door of new Set(q.map((x) => (x.activity.kind === "stay" ? x.activity.at : "")))) {+ const at = q.filter((x) => x.activity.kind === "stay" && x.activity.at === door).map((x) => x.at[0]).sort((a, b) => a - b);+ for (let k = 1; k < at.length; k++) expect(at[k] - at[k - 1]).toBeCloseTo(0.65, 5);+ }+});diff --git a/sdk/raea/conformance/layout.test.ts b/sdk/raea/conformance/layout.test.tsindex b868a992..2aa54769 100644--- a/sdk/raea/conformance/layout.test.ts+++ b/sdk/raea/conformance/layout.test.ts@@ -11,7 +11,7 @@ const fileOf = (sub: string) => Bun.resolveSync(`raea/${sub}`, ROOT);// Bevy's crates (bevy_ prefix dropped) and raea's own subjects; anything else is an older topic subpath (S7 M5)const BEVY = ["app", "asset", "time", "state", "input", "transform", "math", "color", "mesh", "image", "camera", "light", "pbr", "post_process", "sprite", "text", "ui", "animation", "audio", "picking", "gizmos", "scene", "remote", "dev_tools", "feathers", "window", "ecs", "prelude"];-const RAEA = ["video", "physics", "character", "room", "ml"];+const RAEA = ["video", "physics", "character", "people", "room", "ml"];// modules the guides name whose file isn't sdk/raea/src/<name> (S1f's trim dropped raea/bevy-own for a while)const NAMED = ["bevy-own", "glb", "views", "modelling", "arena", "window", "screen", "asset"];diff --git a/sdk/tsconfig.base.json b/sdk/tsconfig.base.jsonindex 188ccd06..7d3cd833 100644--- a/sdk/tsconfig.base.json+++ b/sdk/tsconfig.base.json@@ -44,6 +44,7 @@"raea/overlay": ["./video/src/overlay.tsx"],"raea/paint": ["./render/src/paint.tsx"],"raea/panel": ["./video/src/panel.ts"],+ "raea/people": ["./character/src/people.ts"],"raea/physics": ["./physics/src/physics.tsx"],"raea/r3f": ["./r3f/src/index.ts"],"raea/blender": ["./blender/src/index.ts"],