@korial29/tiny-fps 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import type { GameEvent } from '../shared/types';
2
1
  import type { Vec3 } from './mesh';
2
+ import type { Voice } from './sfx';
3
3
  export interface Audio {
4
4
  /**
5
5
  * Starts the AudioContext on a user gesture (browsers keep it suspended until one); the first
@@ -9,7 +9,7 @@ export interface Audio {
9
9
  /** Where the listener is and looks, each frame (yaw as a player's: 0 looks toward -z). */
10
10
  listen(eye: Vec3, yaw: number): void;
11
11
  /**
12
- * Plays the SOUND `id`. With `at`, panned left or right by its direction from the listener and
12
+ * Plays the sound `id` (an index into the layers). With `at`, panned left or right by its direction from the listener and
13
13
  * fainter with distance; without, centred (the own player's sounds). `gain` scales the volume.
14
14
  */
15
15
  play(id: number, at?: Vec3, gain?: number): void;
@@ -19,20 +19,7 @@ export interface Audio {
19
19
  /** Stops the music and closes the AudioContext. */
20
20
  destroy(): void;
21
21
  }
22
- export declare const createAudio: () => Audio;
23
- /** Plays the sound of a host event: where it happened, centred for the own player's hurt. */
24
- export declare const hear: (a: Audio, { type, id, x, y, z }: GameEvent, you: number) => void;
25
- /** Returns a function that plays CLOCK once a second while called with `on`; `now` in ms. */
26
- export declare const createClock: (a: Audio) => (on: boolean, now: number) => void;
27
- /** The heart beats at this health or below, while alive. */
28
- export declare const LOW_HP = 3;
29
- /**
30
- * Returns a function called each frame with the own health (0 when dead) and `now` in ms. At 1 to
31
- * LOW_HP health it plays HEART, every 0.8 s, and at 1 every 0.5 s and louder; the first beat
32
- * comes the moment health gets low. Returns the beat for the screen: 1 at a thump, fading to 0 by
33
- * the next, and 0 when the health is not low.
34
- */
35
- export declare const createHeart: (a: Audio) => (hp: number, now: number) => number;
22
+ export declare const createAudio: (layers?: Voice[][]) => Audio;
36
23
  /** The mute choice of the last visit. Storage throws when blocked: no memory then. */
37
24
  export declare const savedMute: () => boolean;
38
25
  /** Flips mute, remembers it, and returns the new state. */
@@ -1,177 +1,11 @@
1
- import type { Bullet, GameEvent, Level, Monster, PlayerState, Shot } from '../shared/types';
2
- import type { Vec3 } from './mesh';
3
- export interface Spark {
4
- p: Vec3;
5
- v: Vec3;
6
- /** Seconds left. */
7
- life: number;
8
- /** Flat colour, orange when absent. */
9
- c?: number[];
10
- }
11
- /** What `fall` moves: a position, a velocity, the half height it rests on, the floor under it. */
12
- interface Body {
13
- p: Vec3;
14
- v: Vec3;
15
- size: number;
16
- /** Floor height under it, as of the last sector it was in. */
17
- floor: number;
18
- /** Landed for good. */
19
- rest: boolean;
20
- }
21
- /** A chunk of a dead monster: it flies, lands on the floor below, then shrinks away. */
22
- export interface Gib extends Body {
23
- yaw: number;
24
- /** Half its sides along x, y and z before the turn by yaw, metres; `size` is the y one. */
25
- half: Vec3;
26
- c: number[];
27
- /** Seconds left. */
28
- life: number;
29
- /** Leaves a splat where it first lands. */
30
- gore: boolean;
31
- }
32
- /** A blot of blood on the floor: it shrinks away over its last second. */
33
- export interface Splat {
34
- /** On the floor, a hair above it. */
35
- p: Vec3;
36
- /** Half its side, metres. */
37
- r: number;
38
- yaw: number;
39
- /** Seconds left. */
40
- life: number;
41
- }
42
- /**
43
- * A brass shell casing: it tumbles end over end (`tilt` is its angle to the floor, about the
44
- * horizontal axis across `yaw`), bounces on the floor below, lies still, then shrinks away. A
45
- * free slot has `life` 0 or less; `size` is its radius, its half length is 2.8 times that.
46
- */
47
- export interface Casing extends Body {
48
- yaw: number;
49
- tilt: number;
50
- /** Tumble, radians a second. */
51
- spin: number;
52
- /** Seconds left. */
53
- life: number;
54
- /** Ejected by the own gun: the rest are the others', smaller and few. */
55
- own: boolean;
56
- }
57
- /** An explosion: a glow of radius r at its biggest, t seconds old. */
58
- export interface Blast {
59
- p: Vec3;
60
- r: number;
61
- t: number;
62
- }
63
- /** A puff of smoke: it rises and drifts, swells, then shrinks away over `life` seconds. */
64
- export interface Puff {
65
- p: Vec3;
66
- v: Vec3;
67
- /** Half the side of its cube at its biggest, metres. */
68
- r: number;
69
- yaw: number;
70
- /** Age and lifetime, seconds. */
71
- t: number;
72
- life: number;
73
- }
74
- /** What the client keeps of each monster it has drawn. */
75
- export interface Walker {
76
- x: number;
77
- z: number;
78
- /** Distance covered, metres: the limbs swing with it. */
79
- walked: number;
80
- kind: number;
81
- }
82
- /** What the renderer and the camera read; update and shot move it. */
1
+ import type { PlayerState } from '../shared/types';
2
+ /** What the renderer and the camera read; update moves it. */
83
3
  export interface Effects {
84
4
  /** Vertical eye offset, metres. */
85
5
  bob: number;
86
6
  /** Radians, positive leans right (strafing right). */
87
7
  roll: number;
88
- /** Camera yaw and pitch jitter, radians. */
89
- shakeYaw: number;
90
- shakePitch: number;
91
- /** Recoil, 1 at a shot down to 0. */
92
- kick: number;
93
- /** Barrel angle, radians. */
94
- spin: number;
95
- /** Seconds of own muzzle flash left. */
96
- flash: number;
97
- /** Seconds of flash left at each other shooter, by player id. */
98
- flashes: Map<number, number>;
99
- sparks: Spark[];
100
- gibs: Gib[];
101
- /** A fixed pool: the live ones have `life` above 0. */
102
- casings: Casing[];
103
- splats: Splat[];
104
- blasts: Blast[];
105
- smoke: Puff[];
106
- /** Dust motes, x y z each, in a box around the own eye; `lit` says which the flashlight shows. */
107
- motes: Float32Array;
108
- /** Seconds of the red hurt tint left. */
109
- hurt: number;
110
- /** Seconds left of the fade of a picked-up item's colour, and that colour (0 to 1 each). */
111
- gain: number;
112
- gainC: number[];
113
- /** 0 to 1: how far the camera has sunk and tilted since the own player died; the gun hides. */
114
- dead: number;
115
- /** Seconds of blow left at each monster, by id. */
116
- swings: Map<number, number>;
117
- /** Every monster seen so far, by id. Ids are bounded, so it is too. */
118
- herd: Map<number, Walker>;
119
- /** Unit heading of each bullet in flight, by id, once it has moved. */
120
- aim: Map<number, Vec3>;
121
- /**
122
- * Advances dt seconds: the own player (eased, undefined before the first snapshot), the held
123
- * keys and whether the own player is dead.
124
- */
125
- update(me: PlayerState | undefined, keys: number, dt: number, dead?: boolean): void;
126
- /** The own health dropped: the red tint. */
127
- hit(): void;
128
- /** An item of colour c was picked up near the own player: its colour fades over the screen. */
129
- pickup(c: number[]): void;
130
- /** A new level: drops every effect of the old one, and lets gibs and casings land on the new `lvl`. */
131
- reset(lvl: Level): void;
132
- /**
133
- * A shot, from the shooter's eye; own ones kick the camera and the gun. Each ejects a casing to
134
- * the right of the view. No sparks with `sparks` false: a shot that hit the viewer would burst
135
- * them inside the camera.
136
- */
137
- shot(s: Shot, from: Vec3, own: boolean, sparks?: boolean): void;
138
- /** The monsters and bullets drawn this frame: how far each walked, which way each bullet flies. */
139
- track(monsters: Monster[], bullets: Bullet[]): void;
140
- /** A host event, once delayed to line up with the drawn monsters; `you` is the own player id. */
141
- event(e: GameEvent, you: number): void;
8
+ /** Advances dt seconds: the own player (eased, undefined before the first snapshot) and the held keys. */
9
+ update(me: PlayerState | undefined, keys: number, dt: number): void;
142
10
  }
143
- /** Motes, and the half sides of the box they live in: they wrap round it as the eye moves. */
144
- export declare const MOTES = 128;
145
- export declare const BLAST = 0.3;
146
- /** Seconds the hit vignette and the pickup fade take to go out. */
147
- export declare const HURT = 0.45;
148
- export declare const GAIN = 0.4;
149
- /** Seconds of velocity a spark's streak spans. */
150
- export declare const TRAIL = 0.04;
151
- /** Dark red: the gibs that leave a splat, and the splat. */
152
- export declare const BLOOD: number[];
153
- /** Half the side of an explosion's glow: it swells fast, then shrinks to nothing as it ends. */
154
- export declare const glow: ({ r, t }: Blast) => number;
155
- /** Half the side of a puff of smoke: it starts at a third, swells for half its life, then shrinks to nothing. */
156
- export declare const puff: ({ r, t, life }: Puff) => number;
157
- /** How opaque a puff of smoke is, 0 to 1: it comes in over a tenth of its life, then thins out to nothing. */
158
- export declare const fade: ({ t, life }: Puff) => number;
159
- /**
160
- * The motes the own flashlight shows, from the eye along the unit view direction f: x, y, z and a
161
- * brightness in (0, 1] each, fuller near the axis and the eye. None while the own player is dead.
162
- */
163
- export declare const lit: (fx: Effects, eye: Vec3, f: Vec3) => number[];
164
- /**
165
- * Holds what the host reported at `now` for INTERP_DELAY ms, so it fires in step with the others,
166
- * who are drawn that far in the past. Keeps at most `max`: a hidden tab does not grow it.
167
- */
168
- export declare const createDelay: <T>(max?: number) => {
169
- /** Forgets what is held: it belongs to a level that is gone. */
170
- clear(): void;
171
- push(items: T[], now: number): void;
172
- /** What is due at `now`, oldest first. */
173
- due(now: number): T[];
174
- };
175
- /** rand in [0, 1): injectable so the tests are exact. The level lets gibs land and bounce off walls. */
176
- export declare const createEffects: (rand?: () => number, level?: Level) => Effects;
177
- export {};
11
+ export declare const createEffects: () => Effects;
@@ -1,33 +1,9 @@
1
- /** Slots of say(): a title, a hint under it; and seconds each stays up (the end screen is the third). */
2
- export declare const SAY: {
3
- readonly TITLE: 0;
4
- readonly NOTE: 1;
5
- };
6
- /** A player's line of the end screen. */
7
- export type Score = [name: string, color: string, kills: number, deaths: number];
8
1
  export declare const HUD_CSS: string;
9
2
  export interface Hud {
10
- /** The own health: the bar's width, number and colour. It flashes on a rise and shakes on a fall. */
11
- hp(n: number): void;
12
- /** The keys held, as the snapshot's bit set (1 << ITEM.KEY_*). */
13
- keys(bits: number): void;
14
- /** The own player is dead and respawns in `secs` seconds; 0 hides the death screen. */
15
- dead(secs: number): void;
16
- /**
17
- * The screen fades, each 0 to 1: the red vignette of a hit, the low-health beat (0 when the
18
- * health is not low), and the fade of a picked-up item's colour.
19
- */
20
- fade(hurt: number, low: number, gain: number, color: number[]): void;
21
3
  /** The title screen with `status` under the controls, "Click to play" or why not; '' hides it. */
22
- title(status: string, level: string): void;
23
- /** The end screen: `head`, the players' scores in the order given, `foot`. */
24
- end(head: string, scores: Score[], foot: string): void;
4
+ title(status: string, name: string): void;
25
5
  /** Shows or hides the muted mark. */
26
6
  mute(on: boolean): void;
27
- /** Shows text in a SAY slot, for that slot's time. */
28
- say(slot: number, text: string): void;
29
- /** Advances dt seconds. */
30
- update(dt: number): void;
31
7
  }
32
8
  /** Appends the HUD to `screen`, whose stylesheet has HUD_CSS. */
33
9
  export declare const createHud: (screen: HTMLElement) => Hud;
@@ -14,7 +14,7 @@ export interface Controls {
14
14
  destroy(): void;
15
15
  }
16
16
  /**
17
- * Click the canvas to lock the pointer; while locked the mouse looks, the keys move, the left
18
- * button fires and M calls `onMute`.
17
+ * Click the canvas to lock the pointer; while locked the mouse looks, the keys move and M calls
18
+ * `onMute`.
19
19
  */
20
20
  export declare const createInput: (canvas: HTMLCanvasElement, onMute?: () => void) => Controls;
@@ -1,10 +1,9 @@
1
- import type { Bullet, Level, PlayerState } from '../shared/types';
2
- import type { Effects } from './effects';
1
+ import type { PlayerState } from '../shared/types';
3
2
  import type { Vec3 } from './mesh';
4
3
  export declare const LIGHT: {
5
- /** A cone from p along d: flashlights, muzzle flashes. */
4
+ /** A cone from p along d. */
6
5
  readonly SPOT: 0;
7
- /** All around p: explosions, bursts, the exit, the goal. */
6
+ /** All around p. */
8
7
  readonly POINT: 1;
9
8
  };
10
9
  export interface Light {
@@ -24,32 +23,17 @@ export interface Light {
24
23
  }
25
24
  /** Lights the renderer takes at most, in list order: put the important ones first. */
26
25
  export declare const MAX_LIGHTS = 16;
27
- /** Shadow maps the renderer keeps, one per shadowed SPOT. */
26
+ /** Shadow maps the renderer keeps for lights, one per shadowed SPOT: the sun has its own. */
28
27
  export declare const MAX_SHADOWS = 4;
29
28
  export interface Scene {
30
29
  /** The own eye (bob included) and look angles, as the camera has them. */
31
30
  eye: Vec3;
32
31
  yaw: number;
33
32
  pitch: number;
34
- /** The own player is dead: no flashlight. */
35
- dead: boolean;
36
- /** The living other players, interpolated. */
33
+ /** The other players, interpolated. */
37
34
  others: PlayerState[];
38
- fx: Effects;
39
- /** The monster bullets in flight, as drawn. */
40
- bullets: Bullet[];
41
- /** The level, with its live `barred` (the exit is open once it is not barred). */
42
- lvl: Level;
43
35
  /** Seconds, for pulsing lights. */
44
36
  t: number;
45
37
  }
46
- /** The lava sector's light: its centre, two metres above the floor, and how far it reaches. */
47
- interface Pool {
48
- p: Vec3;
49
- range: number;
50
- }
51
- /** The lava sectors of a level, derived once per Level object: they never change. */
52
- export declare const lava: (lvl: Level) => Pool[];
53
- /** The lights of this frame, most important first. */
54
- export declare const gather: ({ eye, yaw, pitch, dead, others, fx, bullets, lvl, t }: Scene) => Light[];
55
- export {};
38
+ /** The lights of this frame, most important first: none yet. */
39
+ export declare const gather: (scene: Scene) => Light[];
@@ -2,46 +2,37 @@ export type Vec3 = [number, number, number];
2
2
  /**
3
3
  * Floats per vertex: position, normal, then c. A map vertex has c = (u, v, texture layer, light),
4
4
  * u and v in metres. A player vertex has layer -1 and its flat colour in c.x, c.y, c.w; layer -2 is
5
- * the same colour, bright and unlit (flashes, sparks, eyes); layer METAL is a flat colour with the
6
- * metal's specular (the gun, brass).
5
+ * the same colour, bright and unlit (dust, visors, markers).
7
6
  */
8
7
  export declare const STRIDE = 10;
9
- /** The flat colour layer that shines like the metal texture. */
10
- export declare const METAL = -0.5;
11
8
  /**
12
9
  * Camera axes [right, up, forward]: forward is (-sin yaw cos pitch, sin pitch, -cos yaw cos pitch),
13
10
  * y up at roll 0. A positive roll leans the camera right: up tilts toward right.
14
11
  */
15
12
  export declare const basis: (yaw: number, pitch: number, roll?: number) => [Vec3, Vec3, Vec3];
16
- /** The corners of a unit square's two triangles, in the square's own units. */
17
- export declare const QUAD: number[][];
18
13
  /**
19
14
  * Appends the 36 vertices of a box centred on (cx, cy, cz) with half sizes (hx, hy, hz), turned
20
15
  * by yaw about its own vertical axis (local forward, -z, ends up along forward(yaw)).
21
16
  */
22
17
  export declare const pushBox: (out: number[], [cx, cy, cz]: Vec3, [hx, hy, hz]: Vec3, yaw: number, color: number[], layer?: number) => void;
23
- /** gun.ts vertices (position, normal) given a flat colour, in the vertex format above. */
24
- export declare const dress: (v: number[], [r, g, b]: number[], layer?: number) => number[];
25
- /** The cross product of two vectors. */
26
- export declare const cross: (a: Vec3, b: Vec3) => Vec3;
27
- /** Unit axes [d, u, w] of a frame whose first axis is the unit vector d. */
28
- export declare const axesAlong: (d: Vec3) => Vec3[];
29
18
  /**
30
- * Appends the 36 vertices of a box centred on c with half sizes h along the unit axes `ax`. The
31
- * vertices at the +ax[0] end take the colour `end`: a gradient along the first axis.
19
+ * Revolves a profile of [radius, length] points around the axis through `at` along -z: `length`
20
+ * runs forward from `at`. Returns triangles as x, y, z, nx, ny, nz per vertex, `sides` quads of 2
21
+ * triangles per profile segment. The profile goes from back to front and closes on the axis, so
22
+ * the normals (smooth around the ring, flat along the profile) point outward.
32
23
  */
33
- export declare const pushFrame: (out: number[], c: Vec3, ax: Vec3[], h: Vec3, color: number[], layer?: number, end?: number[]) => void;
24
+ export declare const lathe: (profile: [number, number][], sides: number, at?: Vec3) => number[];
25
+ /** lathe() vertices (position, normal) given a flat colour, in the vertex format above. */
26
+ export declare const dress: (v: number[], [r, g, b]: number[]) => number[];
34
27
  /**
35
- * Appends gun-space vertices (x right, y up, -z forward) scaled by k (one factor, or one per axis
36
- * before the turn), turned by spin about z, then carried to the world: axes `[r, u, f]` at eye,
37
- * moved by off = (right, up, forward) along them. `tint` multiplies the flat colour. Written
38
- * without allocations: a body is placed a thousand vertices at a time.
28
+ * Appends model-space vertices (x right, y up, -z forward) scaled by k (one factor, or one per
29
+ * axis), then carried to the world: axes `[r, u, f]` at eye, moved by off = (right, up, forward)
30
+ * along them. `tint` multiplies the flat colour. Written without allocations: a body is placed a
31
+ * thousand vertices at a time.
39
32
  */
40
- export declare const place: (out: number[], src: number[], eye: Vec3, [r, u, f]: Vec3[], off: Vec3, k: number | Vec3, spin?: number, tint?: number[]) => void;
33
+ export declare const place: (out: number[], src: number[], eye: Vec3, [r, u, f]: Vec3[], off: Vec3, k: number | Vec3, tint?: number[]) => void;
41
34
  /**
42
35
  * Axes [r, u, f] with f along the unit vector `to` and r as near `side` as it can be: the frame of
43
36
  * a bone, which `place` takes. Right-handed like `basis`.
44
37
  */
45
38
  export declare const aim: (to: Vec3, side: Vec3) => [Vec3, Vec3, Vec3];
46
- /** Appends a quad a, b, c, d, lit on both faces: a membrane. */
47
- export declare const pushQuad: (out: number[], a: Vec3, b: Vec3, c: Vec3, d: Vec3, color: number[], layer?: number) => void;
@@ -1,4 +1,5 @@
1
- import type { Bullet, Input, Level, Monster, PlayerState, Shot, Snapshot } from '../shared/types';
1
+ import type { Input, PlayerState, Snapshot } from '../shared/types';
2
+ import type { World } from '../shared/world';
2
3
  export interface Predictor {
3
4
  /** The own player id, from the roster. Snapshots before it are only used for the others. */
4
5
  you(id: number): void;
@@ -10,22 +11,6 @@ export interface Predictor {
10
11
  * With `now` (ms, performance.now()) the input carries the view tick the others are drawn at.
11
12
  */
12
13
  step(i: Omit<Input, 'seq' | 'view'>, now?: number): Input;
13
- /**
14
- * The shot the last step fired, resolved with fire() against the living others(now) and
15
- * monsters(now) of that step (a monster this predictor already shot dead, and the host has not
16
- * acked yet, is not a target); undefined when it did not fire (a dead own player never does).
17
- * Replays on a snapshot never fire again.
18
- */
19
- shot(): Shot | undefined;
20
- /**
21
- * Switches to another level (a snapshot with a new `level` or `hard`): prediction, replay and
22
- * interpolation use it from now on, and the snapshots of the previous level are dropped; the own
23
- * player waits for the next snapshot, as at the start. Each snapshot also bars the level with
24
- * its keys and phase (bar() in level.ts) before the replay. A gate that opens between a
25
- * snapshot and the inputs the host has not applied yet is the one thing prediction cannot know:
26
- * it corrects at the next snapshot.
27
- */
28
- level(lvl: Level): void;
29
14
  /** A decoded snapshot, received at `now` (ms, performance.now()). */
30
15
  snapshot(s: Snapshot, now: number): void;
31
16
  /**
@@ -36,14 +21,5 @@ export interface Predictor {
36
21
  me(alpha: number): PlayerState | undefined;
37
22
  /** The other players at now - INTERP_DELAY; a player missing from the latest snapshot is gone. */
38
23
  others(now: number): PlayerState[];
39
- /**
40
- * The living monsters at now - INTERP_DELAY, interpolated like others() (yaw along the shortest
41
- * arc). Unlike others(), presence follows the newer snapshot of the interpolation pair, not the
42
- * latest: a monster is drawn until the pair reaches the first snapshot that lacks it, as late
43
- * as its DIE event is shown.
44
- */
45
- monsters(now: number): Monster[];
46
- /** The bullets in flight at now - INTERP_DELAY, interpolated and kept the same way (until their BOOM). */
47
- bullets(now: number): Bullet[];
48
24
  }
49
- export declare const createPredictor: (first: Level) => Predictor;
25
+ export declare const createPredictor: (world: World) => Predictor;
@@ -1,14 +1,23 @@
1
- import type { Bullet, Edge, Item, Level, Monster, PlayerState } from '../shared/types';
1
+ import type { PlayerState } from '../shared/types';
2
+ import type { World, WorldDef } from '../shared/world';
2
3
  import type { Effects } from './effects';
3
4
  import type { Light } from './lights';
4
5
  import type { Vec3 } from './mesh';
5
- /** MapDef.fog when a map sets none: the clear colour and what distance fog fades to, then its density. Dark, the map is indoors. */
6
- export declare const FOG: number[];
7
- /** Tints a level can use at once, white included (see palette). */
6
+ /** Tints a world can use at once, white included (see palette). */
8
7
  export declare const MAX_TINTS = 16;
8
+ /** Shadow map side in texels. */
9
+ export declare const SHADOW = 1024;
10
+ /** Metres the sun's shadow window spans on a side, centred on the eye: 6 cm a texel. */
11
+ export declare const SUN_AREA = 64;
12
+ /** Half the depth range of the sun's window, metres: what stands this far from the eye along the sun's direction still casts. */
13
+ export declare const SUN_DEPTH = 100;
14
+ /** How far the fog colour is pulled toward the sky's horizon, 0 to 1: a fog unlike the horizon draws an edge against the sky. */
15
+ export declare const HAZE = 0.6;
16
+ /** Tangent of half the vertical field of view (70 degrees). */
17
+ export declare const FOV: number;
9
18
  /**
10
19
  * Blinn-Phong strength and exponent: a row per TEX id in order (brick, tile, lava, stone, metal, wood,
11
- * moss, grate), then the flat bodies and the flat metal (layer METAL). Lava and glows never get here: they light themselves.
20
+ * moss, grate), then the flat bodies. Lava and glows never get here: they light themselves.
12
21
  */
13
22
  export declare const SPEC: number[][];
14
23
  /**
@@ -36,27 +45,42 @@ export declare const pack: (lights: Light[]) => {
36
45
  k: Float32Array<ArrayBuffer>;
37
46
  m: Float32Array<ArrayBuffer>;
38
47
  };
39
- /** Vertical spans [y0, y1] an edge draws on its own side: the wall, or the steps of a portal. */
40
- export declare const spans: ({ map }: Level, { front, back }: Edge) => [number, number][];
41
- /** The tints of a level's sectors, white first and each once: the shader's palette, MAX_TINTS at most. */
42
- export declare const palette: ({ map }: Level) => Vec3[];
43
48
  /**
44
- * Floors and ceilings as fans, then every edge's walls as quads, in the vertex format above. A
45
- * sector's light is packed with its palette index as 2 * index + light: light is at most 1, so
46
- * the shader takes the index from floor(w / 2) and keeps the vertex at 10 floats.
49
+ * The view-projection of the sun's shadow map: an orthographic window of `area` metres a side
50
+ * looking along -dir (dir points toward the sun), centred on the eye and clipped `depth` metres
51
+ * either side of it. The centre is snapped to the map's texels along the window's own axes, so a
52
+ * shadow edge keeps its texels as the eye moves instead of crawling.
47
53
  */
48
- export declare const levelVerts: (lvl: Level) => number[];
54
+ export declare const sunProj: (dir: Vec3, eye: Vec3, area?: number, depth?: number) => Float32Array<ArrayBuffer>;
55
+ /** The tints of a world's brushes, white first and each once: the shader's palette, MAX_TINTS at most. */
56
+ export declare const palette: ({ def }: World) => Vec3[];
57
+ /**
58
+ * The faces of every brush as triangles in the vertex format of mesh.ts: the top gets the brush's
59
+ * top texture, every other face its side texture. Texture coordinates are world metres on the face
60
+ * (x, z on horizontal faces; z, y on faces facing x; x, y on faces facing z), so a texture runs on
61
+ * across neighbouring brushes. A face another brush covers flush is not built, nor is the bottom
62
+ * of a brush at or under the kill floor: nothing is seen from there. A brush's light is packed
63
+ * with its palette index as 2 * index + 1: the light is 1 (the daylight is in the shader), and
64
+ * the shader takes the index from floor(w / 2).
65
+ */
66
+ export declare const level: (world: World) => number[];
67
+ /**
68
+ * What the daylight of a world lights its surfaces with, linear RGB, as the shader's H uniform:
69
+ * the ambient from the sky above, from the sides and bounced up from below, then the sky's zenith
70
+ * and horizon colours. The ambient is the sky's own colour, washed toward white so a shadow is
71
+ * blue-grey and not blue, and dimmer on the sides and below.
72
+ */
73
+ export declare const daylight: ({ sky: [zenith, horizon] }: WorldDef) => Vec3[];
74
+ /** The shader's fog uniform: the world's fog colour pulled toward its horizon by HAZE, and its density; none when the world has no fog. */
75
+ export declare const fogOf: ({ fog, sky }: WorldDef) => [number, number, number, number];
49
76
  export interface Renderer {
50
77
  /**
51
- * Draws one frame: the map, its gates, goal and items, the others, the monsters, their bullets
52
- * and the effects as seen from eye, with the view model on top (not while fx.dead). colors maps
53
- * player id to CSS.
78
+ * Draws one frame: the sky, the brushes and the others as seen from eye. colors maps player id
79
+ * to CSS.
54
80
  */
55
- frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects, monsters: Monster[], bullets: Bullet[], items: Item[],
56
- /** gather() in lights.ts: at most MAX_LIGHTS, the first MAX_SHADOWS shadowed spots mapped. */
81
+ frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects,
82
+ /** gather() in lights.ts: at most MAX_LIGHTS, the first MAX_SHADOWS shadowed spots mapped, besides the sun. */
57
83
  lights: Light[]): void;
58
- /** Builds the geometry of another level, drawn from the next frame on. */
59
- level(lvl: Level): void;
60
84
  /** A world point on screen as of the last frame, in [0, 1] from the top left. */
61
85
  project(x: number, y: number, z: number): [number, number] | undefined;
62
86
  destroy(): void;
@@ -66,4 +90,4 @@ export declare const MAX_PIXELS: number;
66
90
  /** The canvas size in device pixels: the CSS size times the pixel ratio (2 at most), scaled down to MAX_PIXELS. */
67
91
  export declare const backing: (cw: number, ch: number, dpr: number) => [number, number];
68
92
  /** Throws when the browser has no WebGL2. */
69
- export declare const createRenderer: (canvas: HTMLCanvasElement, first: Level) => Renderer;
93
+ export declare const createRenderer: (canvas: HTMLCanvasElement, world: World) => Renderer;
@@ -1,27 +1,34 @@
1
+ /**
2
+ * One oscillator: wave (0 square, 1 saw, 2 sine, 3 noise held for one period), hz, slide in octaves
3
+ * per second, attack, sustain and decay in seconds, vibrato depth, low-pass (0..1, 1 is off),
4
+ * arpeggio time and frequency multiplier, volume; optionally the seconds it starts late.
5
+ */
6
+ export type Voice = [
7
+ number,
8
+ number,
9
+ number,
10
+ number,
11
+ number,
12
+ number,
13
+ number,
14
+ number,
15
+ number,
16
+ number,
17
+ number,
18
+ number?
19
+ ];
1
20
  /** Sample rate of everything rendered here; audio.ts resamples through AudioBuffer if needed. */
2
21
  export declare const RATE = 44100;
3
- /** The sounds of the game. */
4
- export declare const SOUND: {
5
- /** The chaingun, one per shot. */
6
- readonly SHOT: 0;
7
- /** A monster's death. */
8
- readonly BOOM: 1;
9
- /** A player hurt: a blow or a bullet. */
10
- readonly HIT: 2;
11
- /** A pickup taken: health or a key. */
12
- readonly COLLECT: 3;
13
- /** A tick, once a second while the team runs back to the exit (RETURN). */
14
- readonly CLOCK: 4;
15
- /** A bullet bursting on a wall. */
16
- readonly BURST: 5;
17
- /** A heartbeat, looped by the client while the own health is low. */
18
- readonly HEART: 6;
19
- };
20
22
  /**
21
- * Renders the SOUND `id` as mono samples in [-1, 1] at RATE, deterministic (seeded noise), a few
22
- * tenths of a second long, silent at both ends (no click).
23
+ * The sounds of the game: one entry per sound, its voices layered, an index per sound for
24
+ * audio.play. None yet: the footsteps, the dash and the grab of the next steps go here.
25
+ */
26
+ export declare const LAYERS: Voice[][];
27
+ /**
28
+ * Renders the sound `id` of `layers` as mono samples in [-1, 1] at RATE, deterministic (seeded
29
+ * noise), silent at both ends (no click).
23
30
  */
24
- export declare const render: (id: number) => Float32Array;
31
+ export declare const render: (id: number, layers?: Voice[][]) => Float32Array;
25
32
  /**
26
33
  * The music: a loop of four bars in A minor at 108 bpm (whole beats, whole samples), mono samples
27
34
  * in [-1, 1] at RATE, deterministic, whose end joins its start without a click. Quiet enough to
@@ -0,0 +1,21 @@
1
+ import type { PlayerState } from '../shared/types';
2
+ /** What the client keeps of each body it draws: the limbs follow the distance, the pace the speed. */
3
+ export interface Gait {
4
+ x: number;
5
+ z: number;
6
+ /** Distance covered, metres. */
7
+ walked: number;
8
+ /** Eased velocity on x and z, m/s. */
9
+ vx: number;
10
+ vz: number;
11
+ }
12
+ /** Moves the gait of `id` to (x, z) after dt seconds. A jump of metres (a respawn) is not a walk. */
13
+ export declare const follow: (book: Map<number, Gait>, id: number, x: number, z: number, dt: number) => Gait;
14
+ /** 0 standing to 1 striding: the limbs swing less when slow. */
15
+ export declare const pace: (g: Gait) => number;
16
+ /**
17
+ * Appends another player as a soldier: `color` (r, g, b) for the body, darker for the legs, the
18
+ * helmet and the gloves, a visor that glows in it. The legs stride with `walked` and `pace`, and
19
+ * each arm swings against the leg on its side, empty handed.
20
+ */
21
+ export declare const soldier: (out: number[], p: PlayerState, color: number[], walked: number, pace: number) => void;