# gizgame/crowd

a map's people (Map3D people) as its layers draw them: the casts of their kinds' looks, each person drawn as it walks, and the people who walk a place's ways (gizlang/capture Ways), as Unreal's Mass crowd walks its zone graph. A city's layer has its own people (Procgen people); both are drawn here.

```gizlang
import * as Crowd from "gizgame/crowd";
```

## Types

### `Walkers`

```gizlang
class Walkers { private w: Captured.Ways; private kinds: i64; private come: Vec<f64> = []; private people: Vec<Walker> = []; private random: Random = newRandom(7u); private made = 0; private last = -1.0; constructor(w: Captured.Ways, kinds: i64) { this.w = w; this.kinds = kinds; this.come = new Array(w.points.length/3).fill(0.0); for (const way of w.ways) { for (const p of range(way.from+1, way.to)) { this.come[p] = this.come[p-1]+groundDistance(this.point(p-1), this.point(p)); } } } private point(p: i64): Point3 { return point3(this.w.points[p*3], this.w.points[p*3+1], this.w.points[p*3+2]); } private length(way: i64): f64 { return this.come[this.w.ways[way].to-1]; } private placed(way: i64, along: f64, side: f64): [Point3, f64] { const v = this.w.ways[way]; let p = v.from; while (p+2 <v.to && this.come[p+1] <along) { p+ = 1; } const a = this.point(p); const b = this.point(p+1); const span = this.come[p+1]-this.come[p]; const t = span> 0 ? Math.max(0.0, Math.min(1.0, (along-this.come[p])/span)): 0.0; const dx = (b.x-a.x)/Math.max(span, 1.0e-6); const dz = (b.z-a.z)/Math.max(span, 1.0e-6); const off = side*v.wide; return [point3(a.x+(b.x-a.x)*t-dz*off, a.y+(b.y-a.y)*t, a.z+(b.z-a.z)*t+dx*off), frontYaw(point3(dx, 0, dz))]; } frame(eye: Point3, time: f64): Vec<Person> { const step = this.last <0 ? 0.0: Math.max(0.0, Math.min(0.5, time-this.last)); this.last = time; let kept: Vec<Walker> = []; for (const one of this.people) { let p = one; p.along+ = p.pace*step; while (p.along> this.length(p.way)) { const next = this.w.ways[p.way].next; if (next.length === 0) { p.along = -1.0; break; } p.along- = this.length(p.way); p.way = next[this.random.below(next.length)]; } if (p.along> = 0 && groundDistance(this.placed(p.way, p.along, p.side)[0], eye) <PEOPLE_SEEN) { kept.push(p); } } this.people = kept; let near: Vec<i64> = []; let ground = 0.0; for (const [n, v] of this.w.ways.entries()) { if (groundDistance(this.point(v.from), eye) <PEOPLE_SEEN) { near.push(n); ground+ = this.length(n); } } const wanted = Math.minI64(PEOPLE*this.kinds, i64(ground/SPACING)); const anywhere = this.made === 0; for (let tries = 0; this.people.length <wanted && near.length> 0 && tries <64; tries+ = 1) { const way = near[this.random.below(near.length)]; const along = this.random.float()*this.length(way); if (!anywhere && groundDistance(this.placed(way, along, 0)[0], eye) <PEOPLE_SEEN*0.8) { continue; } this.people.push({ id: this.made, way, along, pace: 1.1+0.5*this.random.float(), side: 0.3*(this.random.float()-0.5), model: this.random.below(this.kinds) }); this.made+ = 1; } return this.people.map((p: Walker): Person => { const [at, yaw] = this.placed(p.way, p.along, p.side); return { id: p.id, at, yaw, model: p.model, pace: p.pace }; }); } }
```

The people of KINDS who walk the WAYS of a place about the eye, as Unreal's Mass crowd walks its zone graph: each on
a way, at its own pace and on its own side of it, and on to one of the way's next ways at its end. As many walk
within PEOPLE_SEEN of the eye as the ways there hold (a person a SPACING of way, PEOPLE of each kind at most): one who
leaves that circle is let go, and another comes on a way near its edge (anywhere in it at the start).

- `w`: `gizlang_capture.Ways`
- `kinds`: `i64`
- `come`: `Vec<f64>` — The meters from its way's first point to each point.
- `people`: `Vec<M216.Walker>`
- `random`: `gizlang_random.Random`
- `made`: `i64`
- `last`: `f64`

## Functions

### `casts`

```gizlang
function casts(kinds: Vec<string>, host: Host): Vec<Casting>
```

The casts of the people of KINDS (the kinds of HOST's design): one for each look of a kind (Figure looks), each with
room for its share of the nearest and as many again.

Effects: fail, read, alloc.

### `shown`

```gizlang
function shown(host: Host, kinds: Vec<string>, people: Vec<Person>, eye: Point3, time: f64): void throws string
```

Draws PEOPLE (each where its feet are) of KINDS on HOST's stage at TIME: the nearest PEOPLE of each kind to EYE,
each a character of the cast of its kind in a look and an outfit of its kind's by who it is, at its stride.

Effects: fail, read, write, console, io, alloc.

### `constructor`

```gizlang
constructor(w: Captured.Ways, kinds: i64)
```

People of KINDS kinds (their looks) who walk the ways W.

Effects: fail, read, write, alloc.

## Methods

### `Walkers.frame`

```gizlang
frame(eye: Point3, time: f64): Vec<Person>
```

The people about EYE at TIME, each where its feet are.

Effects: fail, read, write, alloc.

## Constants

### `PEOPLE_SEEN`

```gizlang
const PEOPLE_SEEN: f64 = 90
```

How near the eye people are drawn, in meters.

### `PEOPLE`

```gizlang
const PEOPLE = 40
```

The most people of each kind drawn in a frame.

