@korial29/tiny-fps 0.13.0 → 0.15.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 +19 -12
- package/dist/index.js +16 -14
- package/dist/local.js +1 -1
- package/dist/server.js +584 -63
- package/dist/types/client/audio.d.ts +10 -2
- package/dist/types/client/body.d.ts +34 -0
- package/dist/types/client/effects.d.ts +22 -6
- package/dist/types/client/foley.d.ts +10 -0
- package/dist/types/client/index.d.ts +2 -1
- package/dist/types/client/input.d.ts +2 -2
- package/dist/types/client/predict.d.ts +9 -0
- package/dist/types/client/render.d.ts +6 -4
- package/dist/types/client/sfx.d.ts +24 -2
- package/dist/types/shared/constants.d.ts +91 -0
- package/dist/types/shared/map.d.ts +8 -5
- package/dist/types/shared/physics.d.ts +27 -10
- package/dist/types/shared/protocol.d.ts +1 -1
- package/dist/types/shared/types.d.ts +80 -12
- package/package.json +1 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Vec3 } from './mesh';
|
|
2
2
|
import type { Voice } from './sfx';
|
|
3
|
+
/** A sound that plays on and on, started on its first set. */
|
|
4
|
+
export interface Loop {
|
|
5
|
+
/** Volume and speed (pitch) to move to, eased over a fraction of a second: 0 is silence. */
|
|
6
|
+
set(volume: number, rate: number): void;
|
|
7
|
+
}
|
|
3
8
|
export interface Audio {
|
|
4
9
|
/**
|
|
5
10
|
* Starts the AudioContext on a user gesture (browsers keep it suspended until one); the first
|
|
@@ -10,9 +15,12 @@ export interface Audio {
|
|
|
10
15
|
listen(eye: Vec3, yaw: number): void;
|
|
11
16
|
/**
|
|
12
17
|
* Plays the sound `id` (an index into the layers). With `at`, panned left or right by its direction from the listener and
|
|
13
|
-
* fainter with distance; without, centred (the own player's sounds). `gain` scales the volume
|
|
18
|
+
* fainter with distance; without, centred (the own player's sounds). `gain` scales the volume,
|
|
19
|
+
* `rate` the speed and so the pitch.
|
|
14
20
|
*/
|
|
15
|
-
play(id: number, at?: Vec3, gain?: number): void;
|
|
21
|
+
play(id: number, at?: Vec3, gain?: number, rate?: number): void;
|
|
22
|
+
/** The sound `id` (one of LOOPED) as a loop, silent until its first set; the own player's, centred. */
|
|
23
|
+
loop(id: number): Loop;
|
|
16
24
|
/** Mutes or unmutes everything, music included. */
|
|
17
25
|
mute(on: boolean): void;
|
|
18
26
|
readonly muted: boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PlayerState } from '../shared/types';
|
|
2
|
+
import type { Vec3 } from './mesh';
|
|
3
|
+
/** What the predictor reports of the live steps since the last frame. */
|
|
4
|
+
export interface Events {
|
|
5
|
+
ev: number;
|
|
6
|
+
fall: number;
|
|
7
|
+
}
|
|
8
|
+
/** A limb in world space: its root, its joint, its end, and where the hand or foot points. */
|
|
9
|
+
export interface Limb {
|
|
10
|
+
root: Vec3;
|
|
11
|
+
mid: Vec3;
|
|
12
|
+
end: Vec3;
|
|
13
|
+
dir: Vec3;
|
|
14
|
+
}
|
|
15
|
+
/** The joints of the body: index 0 is the left side, 1 the right. */
|
|
16
|
+
export interface Rig {
|
|
17
|
+
arms: Limb[];
|
|
18
|
+
legs: Limb[];
|
|
19
|
+
/** Pelvis and the top of the chest. */
|
|
20
|
+
torso: [Vec3, Vec3];
|
|
21
|
+
/** 0 to 1: how much the hands hold a ledge; the sleeves slim down, being this close to the eye. */
|
|
22
|
+
grip: number;
|
|
23
|
+
/** 0 to 1: how low the body is (a crouch or a slide). */
|
|
24
|
+
low: number;
|
|
25
|
+
}
|
|
26
|
+
export interface Body {
|
|
27
|
+
/** Advances dt seconds: the own player (eased, undefined before the first snapshot) and the events of its steps. */
|
|
28
|
+
update(me: PlayerState | undefined, e: Events, dt: number): void;
|
|
29
|
+
/** The joints for a camera at `eye`; undefined without a player, or with the camera away from the body. */
|
|
30
|
+
rig(eye: Vec3, yaw: number, pitch: number, roll?: number): Rig | undefined;
|
|
31
|
+
/** Appends the body's vertices (see STRIDE) for that camera; nothing when rig() has none. */
|
|
32
|
+
draw(out: number[], eye: Vec3, yaw: number, pitch: number, roll?: number): void;
|
|
33
|
+
}
|
|
34
|
+
export declare const createBody: () => Body;
|
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import type { PlayerState } from '../shared/types';
|
|
2
|
-
/** What the
|
|
2
|
+
/** What happened in the live steps since the last frame: predictor.events(). */
|
|
3
|
+
export interface Hit {
|
|
4
|
+
ev: number;
|
|
5
|
+
fall: number;
|
|
6
|
+
}
|
|
3
7
|
export interface Effects {
|
|
4
|
-
/** Vertical eye offset, metres. */
|
|
5
|
-
|
|
6
|
-
/** Radians
|
|
8
|
+
/** Vertical eye offset from the physics eye, metres: the eye height eased, the bob, the landing dip, the jump lift. */
|
|
9
|
+
dy: number;
|
|
10
|
+
/** Radians added to the look pitch (positive looks up): the grab settle and the climb arc. */
|
|
11
|
+
pitch: number;
|
|
12
|
+
/** Radians, positive leans right. */
|
|
7
13
|
roll: number;
|
|
8
|
-
/**
|
|
9
|
-
|
|
14
|
+
/** Degrees added to the vertical field of view. */
|
|
15
|
+
fov: number;
|
|
16
|
+
/** 0 to 1: the speed lines, and the touch of vignette that goes with them. */
|
|
17
|
+
lines: number;
|
|
18
|
+
/** Steps walked on a floor or a wall: each whole number is a footfall. */
|
|
19
|
+
stride: number;
|
|
20
|
+
/** Advances dt seconds: the own player (eased, undefined before the first snapshot), the held keys, the events. */
|
|
21
|
+
update(me: PlayerState | undefined, keys: number, dt: number, hit?: Hit): void;
|
|
10
22
|
}
|
|
23
|
+
/** Metres from one footfall to the next at speed v: longer strides at a sprint. */
|
|
24
|
+
export declare const stepLength: (v: number) => number;
|
|
25
|
+
/** Taking steps: on a floor, or along a wall. */
|
|
26
|
+
export declare const stepping: (s?: PlayerState) => boolean;
|
|
11
27
|
export declare const createEffects: () => Effects;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PlayerState } from '../shared/types';
|
|
2
|
+
import type { Audio } from './audio';
|
|
3
|
+
import type { Hit } from './effects';
|
|
4
|
+
export interface Foley {
|
|
5
|
+
/** The own player as drawn (undefined before the first snapshot), what its live steps did, and the stride of the effects. */
|
|
6
|
+
me(p: PlayerState | undefined, hit: Hit, stride: number): void;
|
|
7
|
+
/** The other players as drawn: their steps and landings, at their position. */
|
|
8
|
+
others(ps: PlayerState[]): void;
|
|
9
|
+
}
|
|
10
|
+
export declare const createFoley: (a: Audio) => Foley;
|
|
@@ -17,6 +17,7 @@ export interface TinyFps {
|
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Mounts the game in a Shadow DOM inside container: one WebGL2 canvas filling it, a click locks the
|
|
20
|
-
* pointer, the mouse looks, WASD (ZQSD on AZERTY) moves, Space jumps
|
|
20
|
+
* pointer, the mouse looks, WASD (ZQSD on AZERTY) moves, Shift sprints, Space jumps (again in the
|
|
21
|
+
* air for a second jump), E or the right button dashes, C crouches and slides.
|
|
21
22
|
*/
|
|
22
23
|
export declare const tinyFps: (container: HTMLElement, opts: TinyFpsOptions) => TinyFps;
|
|
@@ -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
|
-
* `onMute`.
|
|
17
|
+
* Click the canvas to lock the pointer; while locked the mouse looks, the keys move (WASD, Shift
|
|
18
|
+
* sprints, Space jumps, E or the right button dashes, C crouches) and M calls `onMute`.
|
|
19
19
|
*/
|
|
20
20
|
export declare const createInput: (canvas: HTMLCanvasElement, onMute?: () => void) => Controls;
|
|
@@ -13,6 +13,15 @@ export interface Predictor {
|
|
|
13
13
|
step(i: Omit<Input, 'seq' | 'view'>, now?: number): Input;
|
|
14
14
|
/** A decoded snapshot, received at `now` (ms, performance.now()). */
|
|
15
15
|
snapshot(s: Snapshot, now: number): void;
|
|
16
|
+
/**
|
|
17
|
+
* What happened in the own player's live steps since the last call: the EV bits of every one of
|
|
18
|
+
* them or-ed together, and the fastest landing. Replays after a snapshot do not count: a move is
|
|
19
|
+
* reported once, when it is first predicted. For the camera, the body and the sounds.
|
|
20
|
+
*/
|
|
21
|
+
events(): {
|
|
22
|
+
ev: number;
|
|
23
|
+
fall: number;
|
|
24
|
+
};
|
|
16
25
|
/**
|
|
17
26
|
* The own player, eased between the state before and after the last step by alpha in [0, 1]
|
|
18
27
|
* (the share of a step elapsed since it), so the camera moves smoothly at any frame rate.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PlayerState } from '../shared/types';
|
|
2
2
|
import type { World, WorldDef } from '../shared/world';
|
|
3
|
+
import type { Body } from './body';
|
|
3
4
|
import type { Effects } from './effects';
|
|
4
5
|
import type { Light } from './lights';
|
|
5
6
|
import type { Vec3 } from './mesh';
|
|
@@ -13,7 +14,8 @@ export declare const SUN_AREA = 64;
|
|
|
13
14
|
export declare const SUN_DEPTH = 100;
|
|
14
15
|
/** 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
16
|
export declare const HAZE = 0.6;
|
|
16
|
-
/**
|
|
17
|
+
/** The vertical field of view at rest, degrees, and the tangent of its half. */
|
|
18
|
+
export declare const FOV_DEG = 70;
|
|
17
19
|
export declare const FOV: number;
|
|
18
20
|
/**
|
|
19
21
|
* Blinn-Phong strength and exponent: a row per TEX id in order (brick, tile, lava, stone, metal, wood,
|
|
@@ -75,12 +77,12 @@ export declare const daylight: ({ sky: [zenith, horizon] }: WorldDef) => Vec3[];
|
|
|
75
77
|
export declare const fogOf: ({ fog, sky }: WorldDef) => [number, number, number, number];
|
|
76
78
|
export interface Renderer {
|
|
77
79
|
/**
|
|
78
|
-
* Draws one frame: the sky, the brushes and the others as seen from eye
|
|
79
|
-
* to CSS.
|
|
80
|
+
* Draws one frame: the sky, the brushes and the others as seen from eye, then the own `body` over
|
|
81
|
+
* a cleared depth, lit but casting no shadow. colors maps player id to CSS.
|
|
80
82
|
*/
|
|
81
83
|
frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects,
|
|
82
84
|
/** gather() in lights.ts: at most MAX_LIGHTS, the first MAX_SHADOWS shadowed spots mapped, besides the sun. */
|
|
83
|
-
lights: Light[]): void;
|
|
85
|
+
lights: Light[], body?: Body): void;
|
|
84
86
|
/** A world point on screen as of the last frame, in [0, 1] from the top left. */
|
|
85
87
|
project(x: number, y: number, z: number): [number, number] | undefined;
|
|
86
88
|
destroy(): void;
|
|
@@ -19,16 +19,38 @@ export type Voice = [
|
|
|
19
19
|
];
|
|
20
20
|
/** Sample rate of everything rendered here; audio.ts resamples through AudioBuffer if needed. */
|
|
21
21
|
export declare const RATE = 44100;
|
|
22
|
+
/** The ids of the sounds: an index into LAYERS. The last two are loops (see LOOPED). */
|
|
23
|
+
export declare const SOUND: {
|
|
24
|
+
readonly STEP: 0;
|
|
25
|
+
/** The lighter tap of a step on a wall. */
|
|
26
|
+
readonly WALLSTEP: 1;
|
|
27
|
+
readonly JUMP: 2;
|
|
28
|
+
readonly DOUBLE: 3;
|
|
29
|
+
readonly DASH: 4;
|
|
30
|
+
readonly LAND: 5;
|
|
31
|
+
readonly GRAB: 6;
|
|
32
|
+
readonly SCUFF: 7;
|
|
33
|
+
readonly WIND: 8;
|
|
34
|
+
readonly SCRAPE: 9;
|
|
35
|
+
};
|
|
22
36
|
/**
|
|
23
|
-
* The sounds of the game: one entry per sound, its voices layered,
|
|
24
|
-
*
|
|
37
|
+
* The sounds of the game: one entry per sound, its voices layered, in SOUND order. A low-passed
|
|
38
|
+
* noise is quiet (lp 0.06 keeps about a tenth of the swing): the loops have a high volume.
|
|
25
39
|
*/
|
|
26
40
|
export declare const LAYERS: Voice[][];
|
|
41
|
+
/** The sounds played in a loop: their buffers go through seam. */
|
|
42
|
+
export declare const LOOPED: number[];
|
|
27
43
|
/**
|
|
28
44
|
* Renders the sound `id` of `layers` as mono samples in [-1, 1] at RATE, deterministic (seeded
|
|
29
45
|
* noise), silent at both ends (no click).
|
|
30
46
|
*/
|
|
31
47
|
export declare const render: (id: number, layers?: Voice[][]) => Float32Array;
|
|
48
|
+
/**
|
|
49
|
+
* A sound made loopable: the last `x` samples are cross-faded into the first, the length drops by
|
|
50
|
+
* `x`, and the end joins the start. For a stationary sound (a loop's voice is held at full
|
|
51
|
+
* volume, nothing but noise), whose own ends are no longer heard.
|
|
52
|
+
*/
|
|
53
|
+
export declare const seam: (s: Float32Array, x?: number) => Float32Array;
|
|
32
54
|
/**
|
|
33
55
|
* The music: a loop of four bars in A minor at 108 bpm (whole beats, whole samples), mono samples
|
|
34
56
|
* in [-1, 1] at RATE, deterministic, whose end joins its start without a click. Quiet enough to
|
|
@@ -22,6 +22,97 @@ 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
|
+
/** Ground acceleration toward the wished direction: from standing to RUN_SPEED in 0.12 s. */
|
|
26
|
+
export declare const ACCEL = 50;
|
|
27
|
+
/** Ground deceleration with no direction held: strong, a stop takes about 0.15 s. */
|
|
28
|
+
export declare const FRICTION = 45;
|
|
29
|
+
/**
|
|
30
|
+
* How fast the speed across the wished direction is killed on the ground. A gentle turn keeps
|
|
31
|
+
* nearly all the speed, a turn of 90 degrees loses it all and starts again from RUN_SPEED.
|
|
32
|
+
*/
|
|
33
|
+
export declare const GRIP = 45;
|
|
34
|
+
/** How fast a speed above the current top speed falls back to it (sprint released, dash over). */
|
|
35
|
+
export declare const DECAY = 12;
|
|
36
|
+
/** Acceleration in the air toward the wished direction. The speed never grows from it, see AIR_SPEED. */
|
|
37
|
+
export declare const AIR_ACCEL = 14;
|
|
38
|
+
/** The speed air control may build up to; a faster player keeps his speed and only turns. */
|
|
39
|
+
export declare const AIR_SPEED = 6;
|
|
40
|
+
/** Top speed after about a second of sprinting forward (Shift held, forward held). */
|
|
41
|
+
export declare const SPRINT_SPEED = 9;
|
|
42
|
+
/** Acceleration from RUN_SPEED to SPRINT_SPEED: 3 m/s over 1 s. */
|
|
43
|
+
export declare const SPRINT_ACCEL = 3;
|
|
44
|
+
/** Dash: a burst of this speed in the wished direction (forward without a key), no gravity. */
|
|
45
|
+
export declare const DASH_SPEED = 16;
|
|
46
|
+
/** Ticks the burst lasts (0.17 s, about 2.7 m). */
|
|
47
|
+
export declare const DASH_TICKS = 10;
|
|
48
|
+
/** The speed left after the burst; it then falls to the top speed at DECAY. */
|
|
49
|
+
export declare const DASH_EXIT_SPEED = 10;
|
|
50
|
+
/** Ticks from one dash to the next dash, burst included (1 s). */
|
|
51
|
+
export declare const DASH_COOLDOWN = 60;
|
|
52
|
+
/** The extra jump in the air: weaker than the first one, so a walk and a double jump stay short. */
|
|
53
|
+
export declare const DOUBLE_JUMP_SPEED = 6;
|
|
54
|
+
/** Air jumps that landing, a wall-run and a ledge grab give back. */
|
|
55
|
+
export declare const AIR_JUMPS = 1;
|
|
56
|
+
/** Ticks after walking off an edge in which a jump still works (0.1 s). */
|
|
57
|
+
export declare const COYOTE_TICKS = 6;
|
|
58
|
+
/**
|
|
59
|
+
* Ticks a jump press is remembered after its own (0.1 s): pressed this close to the ground, it
|
|
60
|
+
* goes off on landing. The state counts it as JUMP_BUFFER_TICKS + 1, which must fit 3 bits.
|
|
61
|
+
*/
|
|
62
|
+
export declare const JUMP_BUFFER_TICKS = 6;
|
|
63
|
+
/** Height of the cylinder when sliding or crouching, and the eye in it. */
|
|
64
|
+
export declare const LOW_H = 0.9;
|
|
65
|
+
export declare const LOW_EYE = 0.7;
|
|
66
|
+
/** Speed from which a crouch is a slide (above RUN_SPEED: only a sprint slides). */
|
|
67
|
+
export declare const SLIDE_MIN_SPEED = 7.5;
|
|
68
|
+
/** A slide bleeds speed at this rate (a sprint of 9 m/s is down to 5 after a second)... */
|
|
69
|
+
export declare const SLIDE_DECEL = 4;
|
|
70
|
+
/** ...and ends under this speed, or after this many ticks (1 s), into a crouch or a stand. */
|
|
71
|
+
export declare const SLIDE_END_SPEED = 4.5;
|
|
72
|
+
export declare const SLIDE_TICKS = 60;
|
|
73
|
+
/** Top speed of a crouch walk. */
|
|
74
|
+
export declare const CROUCH_SPEED = 3;
|
|
75
|
+
/** Wall-run: moving at least this fast along a wall (m/s) starts it, and under WALLRUN_KEEP it ends. */
|
|
76
|
+
export declare const WALLRUN_MIN_SPEED = 7;
|
|
77
|
+
export declare const WALLRUN_KEEP_SPEED = 5.5;
|
|
78
|
+
/** Speed lost along the wall, m/s². */
|
|
79
|
+
export declare const WALLRUN_DRAG = 2.5;
|
|
80
|
+
/** Longest run, in ticks (1 s). */
|
|
81
|
+
export declare const WALLRUN_TICKS = 60;
|
|
82
|
+
/** Gravity during the run, as a share of GRAVITY, and the fastest rise it starts with. */
|
|
83
|
+
export declare const WALLRUN_GRAVITY = 0.15;
|
|
84
|
+
export declare const WALLRUN_VY_MAX = 3;
|
|
85
|
+
/** How far from the cylinder a wall still counts as next to it (m). */
|
|
86
|
+
export declare const WALL_REACH = 0.15;
|
|
87
|
+
/** The share of the speed that may point into or away from the wall for it to count as along it. */
|
|
88
|
+
export declare const WALL_PARALLEL = 0.4;
|
|
89
|
+
/** A kick-off from the wall: speed away from it and upward (m/s). */
|
|
90
|
+
export declare const WALL_KICK_SPEED = 5;
|
|
91
|
+
export declare const WALL_KICK_UP = 6.5;
|
|
92
|
+
/** Ledge grab: a top this far above the feet (m) can be caught, if the player faces it (cosine). */
|
|
93
|
+
export declare const GRAB_MIN = 1.2;
|
|
94
|
+
export declare const GRAB_MAX = 2.4;
|
|
95
|
+
export declare const GRAB_FACING = 0.5;
|
|
96
|
+
/** A hand's reach beyond the cylinder (m), and the gap left between the hanging body and the wall. */
|
|
97
|
+
export declare const GRAB_REACH = 0.2;
|
|
98
|
+
export declare const GRAB_GAP = 0.03;
|
|
99
|
+
/** Feet this far under the ledge (m) when hanging, and how fast the body settles there (m/s). */
|
|
100
|
+
export declare const HANG_H = 2;
|
|
101
|
+
export declare const HANG_SNAP = 8;
|
|
102
|
+
/** A forward press climbs from this tick of the hang (0.1 s); with nothing held the hand slips at HANG_SLIDE. */
|
|
103
|
+
export declare const HANG_MIN_TICKS = 6;
|
|
104
|
+
export declare const HANG_SLIDE_TICKS = 30;
|
|
105
|
+
/** Climb: the body rises to the top at this speed (m/s), then moves CLIMB_INSET in from the edge. */
|
|
106
|
+
export declare const CLIMB_RISE = 8;
|
|
107
|
+
export declare const CLIMB_INSET = 0.2;
|
|
108
|
+
export declare const CLIMB_FWD_SPEED = 5.5;
|
|
109
|
+
/** Safety: a climb that has not ended after this many ticks ends where it is. */
|
|
110
|
+
export declare const CLIMB_MAX_TICKS = 40;
|
|
111
|
+
/** Speed forward when the climb ends (m/s). */
|
|
112
|
+
export declare const CLIMB_EXIT_SPEED = 3;
|
|
113
|
+
/** Jumping off a ledge facing away from it: speed away and upward (m/s). */
|
|
114
|
+
export declare const VAULT_SPEED = 4;
|
|
115
|
+
export declare const VAULT_UP = 6;
|
|
25
116
|
/**
|
|
26
117
|
* Host ticks the history of the players goes back (0.5 s): the host rewinds the others to the
|
|
27
118
|
* view tick of an input, clamped to this.
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import type { WorldDef } from './world';
|
|
2
2
|
/**
|
|
3
|
-
* A parkour test course, laid out for the moves of step 3 and
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* A parkour test course, laid out for the moves of step 3 and flown with them by test/lines.ts.
|
|
4
|
+
* Metres, y up, the course runs north (toward -z). A walking jump flies about 4.2 m on the flat, a
|
|
5
|
+
* sprint jump 6.3 m, and reaches a box 1.7 m high; the hands catch a top 1.2 to 2.4 m above the
|
|
6
|
+
* feet, and a fall that reaches a face within about 3.5 m is caught by them.
|
|
6
7
|
*
|
|
7
|
-
* - A: the start roof (10 m), with the spawns. B: a roof at 10 m, across a 2
|
|
8
|
+
* - A: the start roof (10 m), with the spawns. B: a roof at 10 m, across a 4.2 m gap from A (a
|
|
9
|
+
* run and a jump: walking off the edge falls).
|
|
8
10
|
* - On B, a platform floating at 12.2 to 12.6 m (an overhang to walk under, a bump for a jump) and
|
|
9
11
|
* a stair of six 0.4 m steps up to it. 3 m north of it, C (12.4 m): the south face of C above B
|
|
10
12
|
* is a 2.4 m ledge to grab. Two poles stand by the platform.
|
|
11
13
|
* - E (8 m), 3 m east of C and 4.4 m lower: a long wall (6.5 m high, 26 m long) to run along, ledges
|
|
12
14
|
* 2.0 and 2.2 m high, and a 1.2 m low gap under a lintel to slide under, with a way round it.
|
|
13
15
|
* - G (8 m) is across a 10 m drop from E, reached by a 0.5 m wide beam; it has a 1.6 m ledge.
|
|
14
|
-
* - F (12.4 m) is
|
|
16
|
+
* - F (12.4 m) is 13 m north of C: a sprint and a jump fall short of it, and so does a walk with
|
|
17
|
+
* the dash or the double jump; it takes the sprint and the jump and the dash or the double jump.
|
|
15
18
|
*/
|
|
16
19
|
export declare const ROOFTOPS: WorldDef;
|
|
@@ -5,19 +5,36 @@ export declare const TAU: number;
|
|
|
5
5
|
export declare const norm: (a: number) => number;
|
|
6
6
|
/** Unit vector the player faces at yaw, on the floor plane: yaw 0 looks toward -z. */
|
|
7
7
|
export declare const forward: (yaw: number) => [x: number, z: number];
|
|
8
|
+
/** The movement fields of a player at rest on a floor, for a state built by hand. */
|
|
9
|
+
export declare const STILL: {
|
|
10
|
+
vx: number;
|
|
11
|
+
vz: number;
|
|
12
|
+
mode: number;
|
|
13
|
+
t: number;
|
|
14
|
+
wall: number;
|
|
15
|
+
edge: number;
|
|
16
|
+
jumps: number;
|
|
17
|
+
dashes: number;
|
|
18
|
+
dash: number;
|
|
19
|
+
coyote: number;
|
|
20
|
+
buffer: number;
|
|
21
|
+
held: number;
|
|
22
|
+
ev: number;
|
|
23
|
+
fall: number;
|
|
24
|
+
};
|
|
8
25
|
/** A player standing on spawn point n of the world (modulo the count). */
|
|
9
26
|
export declare const spawn: (id: number, w: World, n: number) => PlayerState;
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export declare const walk: (p: PlayerState, dx: number, dz: number, jump: boolean, w: World) => void;
|
|
27
|
+
/** The height of the cylinder in this mode. */
|
|
28
|
+
export declare const heightOf: (p: Pick<PlayerState, "mode">) => number;
|
|
29
|
+
/** The camera height above the feet in this mode. */
|
|
30
|
+
export declare const eyeHeight: (p: Pick<PlayerState, "mode">) => number;
|
|
31
|
+
/** Horizontal speed, m/s. */
|
|
32
|
+
export declare const speedOf: (p: Pick<PlayerState, "vx" | "vz">) => number;
|
|
33
|
+
/** Running faster than a walk on the ground: the sprint, for the animation to pump the arms. */
|
|
34
|
+
export declare const sprinting: (p: Pick<PlayerState, "mode" | "vx" | "vz">) => boolean;
|
|
19
35
|
/**
|
|
20
36
|
* Applies one input for 1 / TICK_HZ s, in place: yaw and pitch from the input (pitch clamped to
|
|
21
|
-
* MAX_PITCH),
|
|
37
|
+
* MAX_PITCH), then the step of the current mode (see the top of the file). Feet under the world's
|
|
38
|
+
* kill floor put the player back at a spawn.
|
|
22
39
|
*/
|
|
23
40
|
export declare const move: (p: PlayerState, i: Input, w: World) => void;
|
|
@@ -14,7 +14,7 @@ export declare const MSG_INPUT = 1;
|
|
|
14
14
|
export declare const MSG_SNAPSHOT = 2;
|
|
15
15
|
export declare const INPUT_BYTES = 11;
|
|
16
16
|
export declare const SNAP_HEAD = 4;
|
|
17
|
-
export declare const SNAP_PLAYER =
|
|
17
|
+
export declare const SNAP_PLAYER = 39;
|
|
18
18
|
/**
|
|
19
19
|
* The input as the host will read it after encodeInput and decodeInput: yaw, pitch and view
|
|
20
20
|
* rounded to the wire (an absent view stays absent here, and reads 0 on the host). The client
|
|
@@ -11,6 +11,56 @@ export declare const KEY: {
|
|
|
11
11
|
readonly LEFT: 4;
|
|
12
12
|
readonly RIGHT: 8;
|
|
13
13
|
readonly JUMP: 16;
|
|
14
|
+
/** Hold to sprint (with forward). */
|
|
15
|
+
readonly SPRINT: 32;
|
|
16
|
+
/** Press to dash. */
|
|
17
|
+
readonly DASH: 64;
|
|
18
|
+
/** Hold to crouch, or to slide when fast. */
|
|
19
|
+
readonly CROUCH: 128;
|
|
20
|
+
};
|
|
21
|
+
/** The movement state of a player: what the body is doing, one of these. */
|
|
22
|
+
export declare const MODE: {
|
|
23
|
+
/** Standing or running on a floor. */
|
|
24
|
+
readonly GROUND: 0;
|
|
25
|
+
/** Off the floor: a jump, a fall, a dash. */
|
|
26
|
+
readonly AIR: 1;
|
|
27
|
+
/** Running along a wall. */
|
|
28
|
+
readonly WALLRUN: 2;
|
|
29
|
+
/** Hanging from a ledge. */
|
|
30
|
+
readonly HANG: 3;
|
|
31
|
+
/** Pulling up onto a ledge. */
|
|
32
|
+
readonly CLIMB: 4;
|
|
33
|
+
/** Sliding on the ground, low. */
|
|
34
|
+
readonly SLIDE: 5;
|
|
35
|
+
/** Walking low. */
|
|
36
|
+
readonly CROUCH: 6;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Which side of the player a wall or a ledge is on (PlayerState.wall). In the air it is the side
|
|
40
|
+
* of the last wall-run or hang, which does not catch the player again until he lands.
|
|
41
|
+
*/
|
|
42
|
+
export declare const SIDE: {
|
|
43
|
+
readonly NONE: 0;
|
|
44
|
+
readonly EAST: 1;
|
|
45
|
+
readonly WEST: 2;
|
|
46
|
+
readonly SOUTH: 3;
|
|
47
|
+
readonly NORTH: 4;
|
|
48
|
+
};
|
|
49
|
+
/** Bits of PlayerState.ev: what happened in the last step. */
|
|
50
|
+
export declare const EV: {
|
|
51
|
+
readonly JUMP: 1;
|
|
52
|
+
/** The extra jump in the air. */
|
|
53
|
+
readonly DOUBLE: 2;
|
|
54
|
+
readonly DASH: 4;
|
|
55
|
+
/** Back on a floor: PlayerState.fall is the speed it came down at. */
|
|
56
|
+
readonly LAND: 8;
|
|
57
|
+
readonly GRAB: 16;
|
|
58
|
+
/** The climb ended standing on the top. */
|
|
59
|
+
readonly CLIMB: 32;
|
|
60
|
+
readonly WALLRUN_START: 64;
|
|
61
|
+
readonly WALLRUN_END: 128;
|
|
62
|
+
readonly SLIDE_START: 256;
|
|
63
|
+
readonly SLIDE_END: 512;
|
|
14
64
|
};
|
|
15
65
|
/** One client step: what the player held during 1 / TICK_HZ s, and where they looked. */
|
|
16
66
|
export interface Input {
|
|
@@ -30,18 +80,44 @@ export interface Input {
|
|
|
30
80
|
*/
|
|
31
81
|
view?: number;
|
|
32
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* One player, float32 where it is a number with a fraction. All of it but the last two fields goes
|
|
85
|
+
* on the wire (see protocol.ts) and is what move() needs to continue from.
|
|
86
|
+
*/
|
|
33
87
|
export interface PlayerState {
|
|
34
88
|
id: number;
|
|
35
89
|
/** Feet position. */
|
|
36
90
|
x: number;
|
|
37
91
|
y: number;
|
|
38
92
|
z: number;
|
|
39
|
-
/**
|
|
93
|
+
/** Speed, m/s. */
|
|
94
|
+
vx: number;
|
|
40
95
|
vy: number;
|
|
96
|
+
vz: number;
|
|
41
97
|
yaw: number;
|
|
42
98
|
pitch: number;
|
|
43
|
-
/**
|
|
99
|
+
/** On a floor, derived from mode (ground, slide, crouch): not sent. */
|
|
44
100
|
ground: boolean;
|
|
101
|
+
/** MODE, and the ticks spent in it (saturates at 255). */
|
|
102
|
+
mode: number;
|
|
103
|
+
t: number;
|
|
104
|
+
/** SIDE of the wall being run on, the ledge hung from, or the last one (see SIDE). */
|
|
105
|
+
wall: number;
|
|
106
|
+
/** Height of the ledge top being hung from or climbed, else 0. */
|
|
107
|
+
edge: number;
|
|
108
|
+
/** Extra jumps and air dashes left: refilled on landing, a wall-run and a ledge grab. */
|
|
109
|
+
jumps: number;
|
|
110
|
+
dashes: number;
|
|
111
|
+
/** Ticks to the next dash; the first DASH_TICKS of DASH_COOLDOWN are the burst. */
|
|
112
|
+
dash: number;
|
|
113
|
+
/** Ticks left in which a jump still works after walking off an edge, and in which a press is kept. */
|
|
114
|
+
coyote: number;
|
|
115
|
+
buffer: number;
|
|
116
|
+
/** KEY.JUMP and KEY.DASH as held in the last step, to tell a press from a hold. */
|
|
117
|
+
held: number;
|
|
118
|
+
/** For the animation, not sent: the EV bits of the last step, and the speed of a landing. */
|
|
119
|
+
ev: number;
|
|
120
|
+
fall: number;
|
|
45
121
|
}
|
|
46
122
|
/** Procedural textures, generated by the client. A brush names one for its top and one for its sides. */
|
|
47
123
|
export declare const TEX: {
|
|
@@ -58,16 +134,8 @@ export declare const TEX: {
|
|
|
58
134
|
/** Metal floor grating over darkness. */
|
|
59
135
|
readonly GRATE: 7;
|
|
60
136
|
};
|
|
61
|
-
/** One player in a snapshot. */
|
|
62
|
-
export interface SnapPlayer {
|
|
63
|
-
id: number;
|
|
64
|
-
x: number;
|
|
65
|
-
y: number;
|
|
66
|
-
z: number;
|
|
67
|
-
vy: number;
|
|
68
|
-
yaw: number;
|
|
69
|
-
pitch: number;
|
|
70
|
-
ground: boolean;
|
|
137
|
+
/** One player in a snapshot: the state (its ev and fall read 0) and the ack. */
|
|
138
|
+
export interface SnapPlayer extends PlayerState {
|
|
71
139
|
/** Seq of the last input of this player the host applied: the client replays the ones after. */
|
|
72
140
|
ack: number;
|
|
73
141
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@korial29/tiny-fps",
|
|
3
3
|
"description": "Tiny multiplayer first-person rooftop game for the browser: raw WebGL, zero runtime dependencies, WebSocket or same-browser multi-tab play.",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.15.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|