@korial29/tiny-fps 0.12.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.
- package/README.md +1 -1
- package/dist/index.js +31 -16
- package/dist/local.js +1 -1
- package/dist/server.js +375 -321
- package/dist/types/client/effects.d.ts +1 -12
- package/dist/types/client/lights.d.ts +6 -16
- package/dist/types/client/predict.d.ts +3 -2
- package/dist/types/client/render.d.ts +43 -16
- package/dist/types/shared/map.d.ts +14 -10
- package/dist/types/shared/physics.d.ts +11 -9
- package/dist/types/shared/room.d.ts +4 -3
- package/dist/types/shared/types.d.ts +1 -51
- package/dist/types/shared/world.d.ts +59 -0
- package/package.json +1 -1
- package/dist/types/shared/level.d.ts +0 -13
- package/dist/types/shared/trace.d.ts +0 -12
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
import type { PlayerState } from '../shared/types';
|
|
2
|
-
import type { Vec3 } from './mesh';
|
|
3
2
|
/** What the renderer and the camera read; update moves it. */
|
|
4
3
|
export interface Effects {
|
|
5
4
|
/** Vertical eye offset, metres. */
|
|
6
5
|
bob: number;
|
|
7
6
|
/** Radians, positive leans right (strafing right). */
|
|
8
7
|
roll: number;
|
|
9
|
-
/** Dust motes, x y z each, in a box around the own eye; `lit` says which the flashlight shows. */
|
|
10
|
-
motes: Float32Array;
|
|
11
8
|
/** Advances dt seconds: the own player (eased, undefined before the first snapshot) and the held keys. */
|
|
12
9
|
update(me: PlayerState | undefined, keys: number, dt: number): void;
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
export declare const MOTES = 128;
|
|
16
|
-
/**
|
|
17
|
-
* The motes the own flashlight shows, from the eye along the unit view direction f: x, y, z and a
|
|
18
|
-
* brightness in (0, 1] each, fuller near the axis and the eye.
|
|
19
|
-
*/
|
|
20
|
-
export declare const lit: (fx: Effects, eye: Vec3, f: Vec3) => number[];
|
|
21
|
-
/** rand in [0, 1): injectable so the tests are exact. */
|
|
22
|
-
export declare const createEffects: (rand?: () => number) => Effects;
|
|
11
|
+
export declare const createEffects: () => Effects;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PlayerState } from '../shared/types';
|
|
2
2
|
import type { Vec3 } from './mesh';
|
|
3
3
|
export declare const LIGHT: {
|
|
4
|
-
/** A cone from p along d
|
|
4
|
+
/** A cone from p along d. */
|
|
5
5
|
readonly SPOT: 0;
|
|
6
|
-
/** All around p
|
|
6
|
+
/** All around p. */
|
|
7
7
|
readonly POINT: 1;
|
|
8
8
|
};
|
|
9
9
|
export interface Light {
|
|
@@ -23,7 +23,7 @@ export interface Light {
|
|
|
23
23
|
}
|
|
24
24
|
/** Lights the renderer takes at most, in list order: put the important ones first. */
|
|
25
25
|
export declare const MAX_LIGHTS = 16;
|
|
26
|
-
/** 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. */
|
|
27
27
|
export declare const MAX_SHADOWS = 4;
|
|
28
28
|
export interface Scene {
|
|
29
29
|
/** The own eye (bob included) and look angles, as the camera has them. */
|
|
@@ -32,18 +32,8 @@ export interface Scene {
|
|
|
32
32
|
pitch: number;
|
|
33
33
|
/** The other players, interpolated. */
|
|
34
34
|
others: PlayerState[];
|
|
35
|
-
/** The level, for its lava. */
|
|
36
|
-
lvl: Level;
|
|
37
35
|
/** Seconds, for pulsing lights. */
|
|
38
36
|
t: number;
|
|
39
37
|
}
|
|
40
|
-
/** The
|
|
41
|
-
|
|
42
|
-
p: Vec3;
|
|
43
|
-
range: number;
|
|
44
|
-
}
|
|
45
|
-
/** The lava sectors of a level, derived once per Level object: they never change. */
|
|
46
|
-
export declare const lava: (lvl: Level) => Pool[];
|
|
47
|
-
/** The lights of this frame, most important first. */
|
|
48
|
-
export declare const gather: ({ eye, yaw, pitch, others, lvl, t }: Scene) => Light[];
|
|
49
|
-
export {};
|
|
38
|
+
/** The lights of this frame, most important first: none yet. */
|
|
39
|
+
export declare const gather: (scene: Scene) => Light[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Input,
|
|
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;
|
|
@@ -21,4 +22,4 @@ export interface Predictor {
|
|
|
21
22
|
/** The other players at now - INTERP_DELAY; a player missing from the latest snapshot is gone. */
|
|
22
23
|
others(now: number): PlayerState[];
|
|
23
24
|
}
|
|
24
|
-
export declare const createPredictor: (
|
|
25
|
+
export declare const createPredictor: (world: World) => Predictor;
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import type {
|
|
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
|
-
/**
|
|
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
20
|
* moss, grate), then the flat bodies. Lava and glows never get here: they light themselves.
|
|
@@ -36,23 +45,41 @@ 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
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
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
|
|
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
|
|
52
|
-
* CSS.
|
|
78
|
+
* Draws one frame: the sky, the brushes and the others as seen from eye. colors maps player id
|
|
79
|
+
* to CSS.
|
|
53
80
|
*/
|
|
54
81
|
frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects,
|
|
55
|
-
/** gather() in lights.ts: at most MAX_LIGHTS, the first MAX_SHADOWS shadowed spots mapped. */
|
|
82
|
+
/** gather() in lights.ts: at most MAX_LIGHTS, the first MAX_SHADOWS shadowed spots mapped, besides the sun. */
|
|
56
83
|
lights: Light[]): void;
|
|
57
84
|
/** A world point on screen as of the last frame, in [0, 1] from the top left. */
|
|
58
85
|
project(x: number, y: number, z: number): [number, number] | undefined;
|
|
@@ -63,4 +90,4 @@ export declare const MAX_PIXELS: number;
|
|
|
63
90
|
/** The canvas size in device pixels: the CSS size times the pixel ratio (2 at most), scaled down to MAX_PIXELS. */
|
|
64
91
|
export declare const backing: (cw: number, ch: number, dpr: number) => [number, number];
|
|
65
92
|
/** Throws when the browser has no WebGL2. */
|
|
66
|
-
export declare const createRenderer: (canvas: HTMLCanvasElement,
|
|
93
|
+
export declare const createRenderer: (canvas: HTMLCanvasElement, world: World) => Renderer;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WorldDef } from './world';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* A parkour test course, laid out for the moves of step 3 and walkable now with run, jump and the
|
|
4
|
+
* 0.5 m step-up. Metres, y up, the course runs north (toward -z). Jumps reach about 4 m on the
|
|
5
|
+
* flat, and a box 1.7 m high.
|
|
6
|
+
*
|
|
7
|
+
* - A: the start roof (10 m), with the spawns. B: a roof at 10 m, across a 2.5 m gap from A.
|
|
8
|
+
* - On B, a platform floating at 12.2 to 12.6 m (an overhang to walk under, a bump for a jump) and
|
|
9
|
+
* 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
|
+
* is a 2.4 m ledge to grab. Two poles stand by the platform.
|
|
11
|
+
* - 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
|
+
* 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
|
+
* - 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 8 m north of C: out of reach until the dash and the double jump.
|
|
5
15
|
*/
|
|
6
|
-
export declare const
|
|
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;
|
|
16
|
+
export declare const ROOFTOPS: WorldDef;
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import type { Input,
|
|
1
|
+
import type { Input, PlayerState } from './types';
|
|
2
|
+
import type { World } from './world';
|
|
2
3
|
export declare const TAU: number;
|
|
3
4
|
/** An angle in [0, 2π). */
|
|
4
5
|
export declare const norm: (a: number) => number;
|
|
5
6
|
/** Unit vector the player faces at yaw, on the floor plane: yaw 0 looks toward -z. */
|
|
6
7
|
export declare const forward: (yaw: number) => [x: number, z: number];
|
|
8
|
+
/** A player standing on spawn point n of the world (modulo the count). */
|
|
9
|
+
export declare const spawn: (id: number, w: World, n: number) => PlayerState;
|
|
7
10
|
/**
|
|
8
11
|
* Moves the feet by (dx, dz) for 1 / TICK_HZ s, then a jump from the ground, GRAVITY and the
|
|
9
|
-
* collisions of the cylinder (PLAYER_R, PLAYER_H) with the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
12
|
+
* collisions of the cylinder (PLAYER_R, PLAYER_H) with the brushes of the world: it slides along
|
|
13
|
+
* their sides (see push), stands on the highest top under the circle (a top up to STEP_H above the
|
|
14
|
+
* feet is climbed at once, a higher one needs a jump, an edge is a fall), and bumps its head on the
|
|
15
|
+
* lowest bottom, in place. Feet under the world's kill floor put the player back at a spawn.
|
|
16
|
+
* Sides and tops are judged from the feet at the start of the step.
|
|
13
17
|
*/
|
|
14
|
-
export declare const walk: (p: PlayerState, dx: number, dz: number, jump: boolean,
|
|
18
|
+
export declare const walk: (p: PlayerState, dx: number, dz: number, jump: boolean, w: World) => void;
|
|
15
19
|
/**
|
|
16
20
|
* Applies one input for 1 / TICK_HZ s, in place: yaw and pitch from the input (pitch clamped to
|
|
17
21
|
* MAX_PITCH), RUN_SPEED along the held keys (diagonals not faster), then walk().
|
|
18
22
|
*/
|
|
19
|
-
export declare const move: (p: PlayerState, i: Input,
|
|
20
|
-
/** A player standing on the floor at spawn point n of the map (modulo the count). */
|
|
21
|
-
export declare const spawn: (id: number, lvl: Level, n: number) => PlayerState;
|
|
23
|
+
export declare const move: (p: PlayerState, i: Input, w: World) => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Conn, Every,
|
|
1
|
+
import type { Conn, Every, PlayerState, Rules } from './types';
|
|
2
|
+
import type { WorldDef } from './world';
|
|
2
3
|
/**
|
|
3
4
|
* One game, transport-agnostic. The Node server and the local host tab both drive a Room: they
|
|
4
5
|
* feed it connections and frames, the room answers through Conn.send.
|
|
@@ -17,13 +18,13 @@ export declare class Room {
|
|
|
17
18
|
private ticks;
|
|
18
19
|
/** The players as each snapshot of the last MAX_REWIND ticks sent them. */
|
|
19
20
|
private history;
|
|
20
|
-
private
|
|
21
|
+
private world;
|
|
21
22
|
private halt;
|
|
22
23
|
private rules;
|
|
23
24
|
/** Round-robin cursor over the spawn points, used once they are all taken. */
|
|
24
25
|
private rr;
|
|
25
26
|
/** Missing rules fall back to RULES. */
|
|
26
|
-
constructor(rules?: Partial<Rules>, map?:
|
|
27
|
+
constructor(rules?: Partial<Rules>, map?: WorldDef);
|
|
27
28
|
/** Number of joined players. */
|
|
28
29
|
get size(): number;
|
|
29
30
|
/** A peer opened. Nothing is sent until it joins. */
|
|
@@ -43,7 +43,7 @@ export interface PlayerState {
|
|
|
43
43
|
/** Standing on a floor: a jump is allowed. */
|
|
44
44
|
ground: boolean;
|
|
45
45
|
}
|
|
46
|
-
/** Procedural textures, generated by the client. A
|
|
46
|
+
/** Procedural textures, generated by the client. A brush names one for its top and one for its sides. */
|
|
47
47
|
export declare const TEX: {
|
|
48
48
|
readonly BRICK: 0;
|
|
49
49
|
readonly TILE: 1;
|
|
@@ -58,56 +58,6 @@ export declare const TEX: {
|
|
|
58
58
|
/** Metal floor grating over darkness. */
|
|
59
59
|
readonly GRATE: 7;
|
|
60
60
|
};
|
|
61
|
-
/**
|
|
62
|
-
* A room, Doom style: a convex polygon on the floor plane with a flat floor and a flat ceiling.
|
|
63
|
-
* Two sectors are joined where one has the edge a→b and the other b→a with the very same
|
|
64
|
-
* coordinates (a portal); every other edge is a solid wall. Split an edge with collinear points
|
|
65
|
-
* when several sectors meet it (no T-junctions).
|
|
66
|
-
*/
|
|
67
|
-
export interface Sector {
|
|
68
|
-
/**
|
|
69
|
-
* Corners as (x, z), counter-clockwise: the signed area Σ (x_i z_{i+1} - x_{i+1} z_i) is positive.
|
|
70
|
-
* Collinear points are allowed.
|
|
71
|
-
*/
|
|
72
|
-
pts: [x: number, z: number][];
|
|
73
|
-
/** Heights in metres, ceil > floor. */
|
|
74
|
-
floor: number;
|
|
75
|
-
ceil: number;
|
|
76
|
-
/** TEX ids of the floor, the walls (and steps) on its edges, and the ceiling. */
|
|
77
|
-
ft: number;
|
|
78
|
-
wt: number;
|
|
79
|
-
ct: number;
|
|
80
|
-
/** Light level multiplied into the shading, 0 to 1. Absent: 1. */
|
|
81
|
-
light?: number;
|
|
82
|
-
/** Colour of the sector's ambient light, linear RGB 0 to 1 (a cold blue cellar, a warm furnace). Absent: white. */
|
|
83
|
-
tint?: [r: number, g: number, b: number];
|
|
84
|
-
}
|
|
85
|
-
export interface MapDef {
|
|
86
|
-
/** Shown on the title screen. */
|
|
87
|
-
name?: string;
|
|
88
|
-
/** Fog colour (linear RGB 0 to 1) and density per metre (0.02 is the default haze). Absent: the default. */
|
|
89
|
-
fog?: [r: number, g: number, b: number, density: number];
|
|
90
|
-
sectors: Sector[];
|
|
91
|
-
/** Spawn points: feet x, z (inside a sector, standing on its floor) and the yaw to face. */
|
|
92
|
-
spawns: [x: number, z: number, yaw: number][];
|
|
93
|
-
}
|
|
94
|
-
/** One directed edge of a sector, see compile in level.ts. */
|
|
95
|
-
export interface Edge {
|
|
96
|
-
ax: number;
|
|
97
|
-
az: number;
|
|
98
|
-
bx: number;
|
|
99
|
-
bz: number;
|
|
100
|
-
/** Index of the sector the edge belongs to (the side it faces into). */
|
|
101
|
-
front: number;
|
|
102
|
-
/** Index of the sector across a portal, -1 for a solid wall. */
|
|
103
|
-
back: number;
|
|
104
|
-
}
|
|
105
|
-
/** A map ready for physics and drawing. */
|
|
106
|
-
export interface Level {
|
|
107
|
-
map: MapDef;
|
|
108
|
-
/** Every edge of every sector, in sector then point order. */
|
|
109
|
-
edges: Edge[];
|
|
110
|
-
}
|
|
111
61
|
/** One player in a snapshot. */
|
|
112
62
|
export interface SnapPlayer {
|
|
113
63
|
id: number;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
type Vec3 = [number, number, number];
|
|
2
|
+
/** One solid box. */
|
|
3
|
+
export interface Brush {
|
|
4
|
+
/** Corners, metres, min < max on every axis. */
|
|
5
|
+
min: Vec3;
|
|
6
|
+
max: Vec3;
|
|
7
|
+
/** TEX id of the top face, and of the sides and the bottom. */
|
|
8
|
+
top: number;
|
|
9
|
+
side: number;
|
|
10
|
+
/** Colour of its ambient light, linear RGB 0 to 1. Absent: white. */
|
|
11
|
+
tint?: Vec3;
|
|
12
|
+
}
|
|
13
|
+
export interface WorldDef {
|
|
14
|
+
/** Shown on the title screen. */
|
|
15
|
+
name?: string;
|
|
16
|
+
brushes: Brush[];
|
|
17
|
+
/** Feet x, y, z (standing on a top) and the yaw to face. */
|
|
18
|
+
spawns: [x: number, y: number, z: number, yaw: number][];
|
|
19
|
+
/** Feet below this height have fallen off the roofs: the player is put back at a spawn. */
|
|
20
|
+
floor: number;
|
|
21
|
+
/** Unit direction toward the sun, and its colour (linear RGB, may exceed 1). */
|
|
22
|
+
sun: {
|
|
23
|
+
dir: Vec3;
|
|
24
|
+
color: Vec3;
|
|
25
|
+
};
|
|
26
|
+
/** Sky colours at the zenith and the horizon, linear RGB. */
|
|
27
|
+
sky: [zenith: Vec3, horizon: Vec3];
|
|
28
|
+
/** Fog colour and density per metre. Absent: none. */
|
|
29
|
+
fog?: [r: number, g: number, b: number, density: number];
|
|
30
|
+
}
|
|
31
|
+
/** A world ready for physics and drawing: the definition and a grid of brushes on the floor plane. */
|
|
32
|
+
export interface World {
|
|
33
|
+
def: WorldDef;
|
|
34
|
+
/** Metres per grid cell. */
|
|
35
|
+
cell: number;
|
|
36
|
+
/** Cell key (see key()) to the indices of the brushes overlapping it. */
|
|
37
|
+
grid: Map<number, number[]>;
|
|
38
|
+
}
|
|
39
|
+
/** The key of the cell with integer coordinates (cx, cz). */
|
|
40
|
+
export declare const key: (cx: number, cz: number) => number;
|
|
41
|
+
/** Builds the grid: each brush is listed in every cell its footprint covers. */
|
|
42
|
+
export declare const build: (def: WorldDef, cell?: number) => World;
|
|
43
|
+
/**
|
|
44
|
+
* Indices of the brushes whose footprint may overlap the square of half side r around (x, z): every
|
|
45
|
+
* brush listed in a cell the square touches, once each. A candidate list, not an exact overlap.
|
|
46
|
+
*/
|
|
47
|
+
export declare const near: (w: World, x: number, z: number, r: number) => number[];
|
|
48
|
+
/**
|
|
49
|
+
* Distance along the ray from o in the unit direction d to the first brush face, at most max. A ray
|
|
50
|
+
* that starts inside a brush hits at 0; one that starts on a face and moves away from it does not hit it.
|
|
51
|
+
*
|
|
52
|
+
* Walks the grid cells the ray crosses (Amanatides and Woo), testing the brushes of each against
|
|
53
|
+
* the exact slab test, and stops once the next cell starts beyond the best hit or max. A brush
|
|
54
|
+
* spanning several cells is tested in each: the hit is the same, and lists are short.
|
|
55
|
+
*/
|
|
56
|
+
export declare const ray: (w: World, o: Vec3, d: Vec3, max: number) => number;
|
|
57
|
+
/** Whether a brush hides b from a. */
|
|
58
|
+
export declare const hidden: (w: World, a: Vec3, b: Vec3) => boolean;
|
|
59
|
+
export {};
|
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.13.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Level, MapDef, Sector } from './types';
|
|
2
|
-
/** Joins every edge a→b with the sector that has b→a, if any: that edge is a portal. */
|
|
3
|
-
export declare const compile: (map: MapDef) => Level;
|
|
4
|
-
/** Whether (x, z) is inside the sector, its edges included. */
|
|
5
|
-
export declare const inside: ({ pts }: Sector, x: number, z: number) => boolean;
|
|
6
|
-
/** Index of the first sector holding (x, z), -1 outside the map. */
|
|
7
|
-
export declare const sectorAt: ({ map }: Level, x: number, z: number) => number;
|
|
8
|
-
/**
|
|
9
|
-
* Whether a wall, a step or a ceiling hides b from a (both inside the map). Between two edge
|
|
10
|
-
* crossings the segment stays in one sector, and each crossing is checked against the opening of
|
|
11
|
-
* its portal, so floors and ceilings need no test of their own.
|
|
12
|
-
*/
|
|
13
|
-
export declare const blocked: ({ map, edges }: Level, [ax, ay, az]: [number, number, number], [bx, by, bz]: [number, number, number]) => boolean;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Level } from './types';
|
|
2
|
-
type Vec3 = [number, number, number];
|
|
3
|
-
/**
|
|
4
|
-
* Distance along the ray from o (inside the map) in the unit direction d to the first wall, step
|
|
5
|
-
* face, floor or ceiling, at most max.
|
|
6
|
-
*
|
|
7
|
-
* Walks the sectors: in the current convex one the ray leaves through the edge with the least
|
|
8
|
-
* crossing distance among the edges it goes outward through, or ends earlier on the floor or the
|
|
9
|
-
* ceiling. A solid edge, or a portal whose opening does not hold the crossing height, ends it.
|
|
10
|
-
*/
|
|
11
|
-
export declare const trace: (lvl: Level, o: Vec3, d: Vec3, max: number) => number;
|
|
12
|
-
export {};
|