@korial29/tiny-fps 0.11.0 → 0.12.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.
- package/README.md +27 -38
- package/dist/index.js +12 -13
- package/dist/local.js +1 -1
- package/dist/server.js +261 -2220
- package/dist/types/client/audio.d.ts +3 -16
- package/dist/types/client/effects.d.ts +7 -162
- package/dist/types/client/hud.d.ts +1 -25
- package/dist/types/client/input.d.ts +2 -2
- package/dist/types/client/lights.d.ts +6 -12
- package/dist/types/client/mesh.d.ts +13 -22
- package/dist/types/client/predict.d.ts +2 -27
- package/dist/types/client/render.d.ts +6 -9
- package/dist/types/client/sfx.d.ts +27 -20
- package/dist/types/client/soldier.d.ts +21 -0
- package/dist/types/shared/constants.d.ts +2 -49
- package/dist/types/shared/level.d.ts +0 -2
- package/dist/types/shared/map.d.ts +7 -2
- package/dist/types/shared/physics.d.ts +3 -19
- package/dist/types/shared/protocol.d.ts +2 -22
- package/dist/types/shared/room.d.ts +12 -53
- package/dist/types/shared/trace.d.ts +12 -0
- package/dist/types/shared/types.d.ts +2 -147
- package/package.json +2 -2
- package/dist/types/client/gun.d.ts +0 -24
- package/dist/types/client/items.d.ts +0 -19
- package/dist/types/client/monsters.d.ts +0 -60
- package/dist/types/client/progress.d.ts +0 -56
- package/dist/types/shared/levels.d.ts +0 -2
- package/dist/types/shared/monsters.d.ts +0 -23
- package/dist/types/shared/shoot.d.ts +0 -33
|
@@ -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
|
|
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,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PlayerState } from '../shared/types';
|
|
2
2
|
import type { Vec3 } from './mesh';
|
|
3
|
-
|
|
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. */
|
|
3
|
+
/** What the renderer and the camera read; update moves it. */
|
|
83
4
|
export interface Effects {
|
|
84
5
|
/** Vertical eye offset, metres. */
|
|
85
6
|
bob: number;
|
|
86
7
|
/** Radians, positive leans right (strafing right). */
|
|
87
8
|
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
9
|
/** Dust motes, x y z each, in a box around the own eye; `lit` says which the flashlight shows. */
|
|
107
10
|
motes: Float32Array;
|
|
108
|
-
/**
|
|
109
|
-
|
|
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;
|
|
11
|
+
/** Advances dt seconds: the own player (eased, undefined before the first snapshot) and the held keys. */
|
|
12
|
+
update(me: PlayerState | undefined, keys: number, dt: number): void;
|
|
142
13
|
}
|
|
143
14
|
/** Motes, and the half sides of the box they live in: they wrap round it as the eye moves. */
|
|
144
15
|
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
16
|
/**
|
|
160
17
|
* 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.
|
|
18
|
+
* brightness in (0, 1] each, fuller near the axis and the eye.
|
|
162
19
|
*/
|
|
163
20
|
export declare const lit: (fx: Effects, eye: Vec3, f: Vec3) => number[];
|
|
164
|
-
/**
|
|
165
|
-
|
|
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 {};
|
|
21
|
+
/** rand in [0, 1): injectable so the tests are exact. */
|
|
22
|
+
export declare const createEffects: (rand?: () => number) => 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,
|
|
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
|
|
18
|
-
*
|
|
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 {
|
|
2
|
-
import type { Effects } from './effects';
|
|
1
|
+
import type { Level, 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
|
|
4
|
+
/** A cone from p along d: flashlights. */
|
|
6
5
|
readonly SPOT: 0;
|
|
7
|
-
/** All around p:
|
|
6
|
+
/** All around p: the lava. */
|
|
8
7
|
readonly POINT: 1;
|
|
9
8
|
};
|
|
10
9
|
export interface Light {
|
|
@@ -31,14 +30,9 @@ export interface Scene {
|
|
|
31
30
|
eye: Vec3;
|
|
32
31
|
yaw: number;
|
|
33
32
|
pitch: number;
|
|
34
|
-
/** The
|
|
35
|
-
dead: boolean;
|
|
36
|
-
/** The living other players, interpolated. */
|
|
33
|
+
/** The other players, interpolated. */
|
|
37
34
|
others: PlayerState[];
|
|
38
|
-
|
|
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). */
|
|
35
|
+
/** The level, for its lava. */
|
|
42
36
|
lvl: Level;
|
|
43
37
|
/** Seconds, for pulsing lights. */
|
|
44
38
|
t: number;
|
|
@@ -51,5 +45,5 @@ interface Pool {
|
|
|
51
45
|
/** The lava sectors of a level, derived once per Level object: they never change. */
|
|
52
46
|
export declare const lava: (lvl: Level) => Pool[];
|
|
53
47
|
/** The lights of this frame, most important first. */
|
|
54
|
-
export declare const gather: ({ eye, yaw, pitch,
|
|
48
|
+
export declare const gather: ({ eye, yaw, pitch, others, lvl, t }: Scene) => Light[];
|
|
55
49
|
export {};
|
|
@@ -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 (
|
|
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
|
-
*
|
|
31
|
-
*
|
|
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
|
|
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
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
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,
|
|
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,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Input, Level, PlayerState, Snapshot } from '../shared/types';
|
|
2
2
|
export interface Predictor {
|
|
3
3
|
/** The own player id, from the roster. Snapshots before it are only used for the others. */
|
|
4
4
|
you(id: number): void;
|
|
@@ -10,22 +10,6 @@ export interface Predictor {
|
|
|
10
10
|
* With `now` (ms, performance.now()) the input carries the view tick the others are drawn at.
|
|
11
11
|
*/
|
|
12
12
|
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
13
|
/** A decoded snapshot, received at `now` (ms, performance.now()). */
|
|
30
14
|
snapshot(s: Snapshot, now: number): void;
|
|
31
15
|
/**
|
|
@@ -36,14 +20,5 @@ export interface Predictor {
|
|
|
36
20
|
me(alpha: number): PlayerState | undefined;
|
|
37
21
|
/** The other players at now - INTERP_DELAY; a player missing from the latest snapshot is gone. */
|
|
38
22
|
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
23
|
}
|
|
49
|
-
export declare const createPredictor: (
|
|
24
|
+
export declare const createPredictor: (lvl: Level) => Predictor;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Edge, Level, PlayerState } from '../shared/types';
|
|
2
2
|
import type { Effects } from './effects';
|
|
3
3
|
import type { Light } from './lights';
|
|
4
4
|
import type { Vec3 } from './mesh';
|
|
@@ -8,7 +8,7 @@ export declare const FOG: number[];
|
|
|
8
8
|
export declare const MAX_TINTS = 16;
|
|
9
9
|
/**
|
|
10
10
|
* 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
|
|
11
|
+
* moss, grate), then the flat bodies. Lava and glows never get here: they light themselves.
|
|
12
12
|
*/
|
|
13
13
|
export declare const SPEC: number[][];
|
|
14
14
|
/**
|
|
@@ -48,15 +48,12 @@ export declare const palette: ({ map }: Level) => Vec3[];
|
|
|
48
48
|
export declare const levelVerts: (lvl: Level) => number[];
|
|
49
49
|
export interface Renderer {
|
|
50
50
|
/**
|
|
51
|
-
* Draws one frame: the map,
|
|
52
|
-
*
|
|
53
|
-
* player id to CSS.
|
|
51
|
+
* Draws one frame: the map, the others and the dust as seen from eye. colors maps player id to
|
|
52
|
+
* CSS.
|
|
54
53
|
*/
|
|
55
|
-
frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects,
|
|
54
|
+
frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects,
|
|
56
55
|
/** gather() in lights.ts: at most MAX_LIGHTS, the first MAX_SHADOWS shadowed spots mapped. */
|
|
57
56
|
lights: Light[]): void;
|
|
58
|
-
/** Builds the geometry of another level, drawn from the next frame on. */
|
|
59
|
-
level(lvl: Level): void;
|
|
60
57
|
/** A world point on screen as of the last frame, in [0, 1] from the top left. */
|
|
61
58
|
project(x: number, y: number, z: number): [number, number] | undefined;
|
|
62
59
|
destroy(): void;
|
|
@@ -66,4 +63,4 @@ export declare const MAX_PIXELS: number;
|
|
|
66
63
|
/** The canvas size in device pixels: the CSS size times the pixel ratio (2 at most), scaled down to MAX_PIXELS. */
|
|
67
64
|
export declare const backing: (cw: number, ch: number, dpr: number) => [number, number];
|
|
68
65
|
/** Throws when the browser has no WebGL2. */
|
|
69
|
-
export declare const createRenderer: (canvas: HTMLCanvasElement,
|
|
66
|
+
export declare const createRenderer: (canvas: HTMLCanvasElement, lvl: Level) => 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
|
-
*
|
|
22
|
-
*
|
|
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;
|
|
@@ -22,17 +22,9 @@ export declare const GRAVITY = 20;
|
|
|
22
22
|
export declare const MAX_PITCH = 1.55;
|
|
23
23
|
/** A floor at most this much higher is walked onto; a higher one needs a jump. */
|
|
24
24
|
export declare const STEP_H = 0.5;
|
|
25
|
-
/** Steps between two chaingun shots while the trigger is held: 60 / 5 = 12 shots per second. */
|
|
26
|
-
export declare const FIRE_EVERY = 5;
|
|
27
|
-
/** Speed factor while the trigger is held. */
|
|
28
|
-
export declare const FIRE_SLOW = 0.5;
|
|
29
|
-
/** Metres a shot reaches. */
|
|
30
|
-
export declare const RANGE = 100;
|
|
31
|
-
/** Largest angle, in radians, between a shot and the view direction. */
|
|
32
|
-
export declare const SPREAD = 0.02;
|
|
33
25
|
/**
|
|
34
|
-
* Host ticks
|
|
35
|
-
*
|
|
26
|
+
* Host ticks the history of the players goes back (0.5 s): the host rewinds the others to the
|
|
27
|
+
* view tick of an input, clamped to this.
|
|
36
28
|
*/
|
|
37
29
|
export declare const MAX_REWIND = 30;
|
|
38
30
|
/**
|
|
@@ -41,45 +33,6 @@ export declare const MAX_REWIND = 30;
|
|
|
41
33
|
*/
|
|
42
34
|
export declare const INPUT_BURST = 10;
|
|
43
35
|
export declare const MAX_PLAYERS = 16;
|
|
44
|
-
/** Monsters alive at once at most; their ids run from MAX_PLAYERS to MAX_PLAYERS + MAX_MONSTERS - 1. */
|
|
45
|
-
export declare const MAX_MONSTERS = 64;
|
|
46
|
-
export declare const WALKER_R = 0.4;
|
|
47
|
-
export declare const WALKER_H = 1.8;
|
|
48
|
-
export declare const WALKER_SPEED = 2.5;
|
|
49
|
-
export declare const FLYER_R = 0.45;
|
|
50
|
-
export declare const FLYER_H = 0.9;
|
|
51
|
-
/** A flyer's underside floats this high above the floor below it, ceilings allowing. */
|
|
52
|
-
export declare const FLYER_HOVER = 1.2;
|
|
53
|
-
export declare const FLYER_SPEED = 3.5;
|
|
54
|
-
/** Each monster looks for players once per SIGHT_EVERY ticks (staggered), in a cone this wide. */
|
|
55
|
-
export declare const SIGHT_EVERY = 60;
|
|
56
|
-
export declare const SIGHT_COS: number;
|
|
57
|
-
export declare const SIGHT_RANGE = 30;
|
|
58
|
-
/** A monster that sees a player or dies alerts the others within ALERT_R that can see it. */
|
|
59
|
-
export declare const ALERT_R = 12;
|
|
60
|
-
/** A chasing monster this close (centre to centre, on the floor plane) swings, once per MELEE_EVERY. */
|
|
61
|
-
export declare const MELEE_R = 1.4;
|
|
62
|
-
export declare const MELEE_EVERY = 45;
|
|
63
|
-
/** A chasing walker that sees its target fires once per SHOOT_EVERY ticks. */
|
|
64
|
-
export declare const SHOOT_EVERY = 90;
|
|
65
|
-
export declare const BULLET_SPEED = 12;
|
|
66
|
-
export declare const BULLET_R = 0.15;
|
|
67
|
-
/** Ticks a bullet lives at most. */
|
|
68
|
-
export declare const BULLET_LIFE = 300;
|
|
69
|
-
export declare const HEALTH = 9;
|
|
70
|
-
/** A hit takes 1 health, then the player cannot be hurt for HIT_COOLDOWN ticks. */
|
|
71
|
-
export declare const HIT_COOLDOWN = 60;
|
|
72
|
-
/** Every DROP_EVERY-th kill of the team leaves a HEALTH pickup where the monster died. */
|
|
73
|
-
export declare const DROP_EVERY = 4;
|
|
74
|
-
export declare const HEAL = 3;
|
|
75
|
-
/** A player whose axis comes this close to a pickup (on the floor plane) takes it. */
|
|
76
|
-
export declare const PICKUP_R = 0.8;
|
|
77
|
-
export declare const GOAL_R = 1;
|
|
78
|
-
/** A dead player comes back at the level start after this long. */
|
|
79
|
-
export declare const PLAYER_RESPAWN = 180;
|
|
80
|
-
/** Hard mode (second run on): monster speed factor, and the share of SHOOT_EVERY and MELEE_EVERY. */
|
|
81
|
-
export declare const HARD_SPEED = 1.3;
|
|
82
|
-
export declare const HARD_RATE = 0.6;
|
|
83
36
|
/** Longest player name, in characters (code points). */
|
|
84
37
|
export declare const MAX_NAME = 16;
|
|
85
38
|
export declare const RULES: Rules;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Level, MapDef, Sector } from './types';
|
|
2
2
|
/** Joins every edge a→b with the sector that has b→a, if any: that edge is a portal. */
|
|
3
3
|
export declare const compile: (map: MapDef) => Level;
|
|
4
|
-
/** Bars the gates whose key is not in `keys` (bits 1 << ITEM.KEY_*), and the exit before RETURN. */
|
|
5
|
-
export declare const bar: ({ map, barred }: Level, keys: number, phase: number) => void;
|
|
6
4
|
/** Whether (x, z) is inside the sector, its edges included. */
|
|
7
5
|
export declare const inside: ({ pts }: Sector, x: number, z: number) => boolean;
|
|
8
6
|
/** Index of the first sector holding (x, z), -1 outside the map. */
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { MapDef } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* The first sector map, a test bed for heights: a start room, a low corridor, a tall hall around a
|
|
4
|
-
* lava pit, stairs up to a balcony. Each spot is reachable on foot; the pit is a 1 m drop.
|
|
5
|
-
* is on the balcony, the exit is the start room, and a health pack lies in the hall.
|
|
4
|
+
* lava pit, stairs up to a balcony. Each spot is reachable on foot; the pit is a 1 m drop.
|
|
6
5
|
*/
|
|
7
6
|
export declare const HALL: MapDef;
|
|
7
|
+
/**
|
|
8
|
+
* The first rooftop, for the capture-the-flag game: a flat 40 x 40 m deck in the open, a 1 m
|
|
9
|
+
* parapet round it, a crate, a block and a platform with steps. Built as a grid of cells, one
|
|
10
|
+
* sector each: neighbours at one height are open to each other, and the edge is solid wall.
|
|
11
|
+
*/
|
|
12
|
+
export declare const ROOF: MapDef;
|