@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.
- package/README.md +27 -38
- package/dist/index.js +32 -18
- package/dist/local.js +1 -1
- package/dist/server.js +394 -2299
- package/dist/types/client/audio.d.ts +3 -16
- package/dist/types/client/effects.d.ts +5 -171
- 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 +7 -23
- package/dist/types/client/mesh.d.ts +13 -22
- package/dist/types/client/predict.d.ts +3 -27
- package/dist/types/client/render.d.ts +45 -21
- 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/map.d.ts +14 -5
- package/dist/types/shared/physics.d.ts +11 -25
- package/dist/types/shared/protocol.d.ts +2 -22
- package/dist/types/shared/room.d.ts +14 -54
- package/dist/types/shared/types.d.ts +2 -197
- package/dist/types/shared/world.d.ts +59 -0
- 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/level.d.ts +0 -15
- 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
|
@@ -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,7 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WorldDef } from './world';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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.
|
|
6
15
|
*/
|
|
7
|
-
export declare const
|
|
16
|
+
export declare const ROOFTOPS: WorldDef;
|
|
@@ -1,37 +1,23 @@
|
|
|
1
|
-
import type { Input,
|
|
2
|
-
type
|
|
3
|
-
/** What walk() moves: a player, or a walker with the same feet, speed and floor contact. */
|
|
4
|
-
type Walker = Pos & Pick<PlayerState, 'vy' | 'ground'>;
|
|
1
|
+
import type { Input, PlayerState } from './types';
|
|
2
|
+
import type { World } from './world';
|
|
5
3
|
export declare const TAU: number;
|
|
6
4
|
/** An angle in [0, 2π). */
|
|
7
5
|
export declare const norm: (a: number) => number;
|
|
8
6
|
/** Unit vector the player faces at yaw, on the floor plane: yaw 0 looks toward -z. */
|
|
9
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;
|
|
10
10
|
/**
|
|
11
11
|
* Moves the feet by (dx, dz) for 1 / TICK_HZ s, then a jump from the ground, GRAVITY and the
|
|
12
|
-
* collisions of the cylinder (PLAYER_R, PLAYER_H) with the
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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.
|
|
16
17
|
*/
|
|
17
|
-
export declare const walk: (p:
|
|
18
|
-
/**
|
|
19
|
-
* Moves a flyer (underside at p.y, radius FLYER_R, height FLYER_H) by (dx, dy, dz): sideways it is
|
|
20
|
-
* stopped by solid walls and by openings too small for it, and it never steps (it flies over
|
|
21
|
-
* steps and pits); then y is held between FLYER_HOVER above the highest floor under it and the
|
|
22
|
-
* lowest ceiling minus FLYER_H, the ceiling winning in a low room. Below the hover height it
|
|
23
|
-
* rises at FLYER_SPEED, so crossing from a pit to a ledge is not a jump; the floor itself is
|
|
24
|
-
* never entered.
|
|
25
|
-
*/
|
|
26
|
-
export declare const fly: (p: Pos, dx: number, dy: number, dz: number, lvl: Level) => void;
|
|
18
|
+
export declare const walk: (p: PlayerState, dx: number, dz: number, jump: boolean, w: World) => void;
|
|
27
19
|
/**
|
|
28
20
|
* Applies one input for 1 / TICK_HZ s, in place: yaw and pitch from the input (pitch clamped to
|
|
29
21
|
* MAX_PITCH), RUN_SPEED along the held keys (diagonals not faster), then walk().
|
|
30
|
-
* The chaingun: `cool` counts down one per step, RUN_SPEED is scaled by FIRE_SLOW while KEY.FIRE
|
|
31
|
-
* is held, and the step that finds it held with `cool` at 0 re-arms it to FIRE_EVERY and returns
|
|
32
|
-
* true: the caller resolves a shot (one every FIRE_EVERY steps, the first at once).
|
|
33
22
|
*/
|
|
34
|
-
export declare const move: (p: PlayerState, i: Input,
|
|
35
|
-
/** A player standing on the floor at spawn point n of the map (modulo the count). */
|
|
36
|
-
export declare const spawn: (id: number, lvl: Level, n: number) => PlayerState;
|
|
37
|
-
export {};
|
|
23
|
+
export declare const move: (p: PlayerState, i: Input, w: World) => void;
|
|
@@ -9,32 +9,12 @@ export type ServerText = {
|
|
|
9
9
|
players: PlayerInfo[];
|
|
10
10
|
} | {
|
|
11
11
|
t: 'full';
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The last level of a run was won: the run took `ticks` host ticks; `hard` says whether that run
|
|
15
|
-
* was hard. The next run always is. `stats` has one row per player still in the room, kills and
|
|
16
|
-
* deaths over the whole run.
|
|
17
|
-
*/
|
|
18
|
-
| {
|
|
19
|
-
t: 'end';
|
|
20
|
-
ticks: number;
|
|
21
|
-
hard: boolean;
|
|
22
|
-
stats: {
|
|
23
|
-
id: number;
|
|
24
|
-
kills: number;
|
|
25
|
-
deaths: number;
|
|
26
|
-
}[];
|
|
27
12
|
};
|
|
28
13
|
export declare const MSG_INPUT = 1;
|
|
29
14
|
export declare const MSG_SNAPSHOT = 2;
|
|
30
15
|
export declare const INPUT_BYTES = 11;
|
|
31
|
-
export declare const SNAP_HEAD =
|
|
32
|
-
export declare const SNAP_PLAYER =
|
|
33
|
-
export declare const SNAP_SHOT = 14;
|
|
34
|
-
export declare const SNAP_MONSTER = 16;
|
|
35
|
-
export declare const SNAP_BULLET = 13;
|
|
36
|
-
export declare const SNAP_EVENT = 14;
|
|
37
|
-
export declare const SNAP_ITEM = 14;
|
|
16
|
+
export declare const SNAP_HEAD = 4;
|
|
17
|
+
export declare const SNAP_PLAYER = 24;
|
|
38
18
|
/**
|
|
39
19
|
* The input as the host will read it after encodeInput and decodeInput: yaw, pitch and view
|
|
40
20
|
* rounded to the wire (an absent view stays absent here, and reads 0 on the host). The client
|
|
@@ -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.
|
|
@@ -7,52 +8,23 @@ import type { Conn, Every, MapDef, Rules } from './types';
|
|
|
7
8
|
* taken by another player; 'full' beyond rules.maxPlayers. Everyone gets a fresh 'roster' on
|
|
8
9
|
* every join and leave.
|
|
9
10
|
* - Each input frame moves its player at once with move(); the INPUT_BURST bank drops the excess.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* -
|
|
13
|
-
* rewinds the monsters with the players, and one that hits a monster kills it.
|
|
14
|
-
* - A player has HEALTH. A monster's blow or bullet takes 1, then HIT_COOLDOWN ticks of grace
|
|
15
|
-
* (only a hit that took health is told as a HURT event). A dead player moves, shoots and
|
|
16
|
-
* counts for nothing until PLAYER_RESPAWN ticks later, when it is back at a spawn.
|
|
17
|
-
* - The level's items lie in it, and every DROP_EVERY-th kill leaves a HEALTH pack. A key taken
|
|
18
|
-
* opens its gates for the team, a pack heals below full health.
|
|
19
|
-
* - Touching the goal turns the level from HUNT to RETURN (the exit opens); when every living
|
|
20
|
-
* player is in the exit the level is won: the next one starts, everyone respawned. After the
|
|
21
|
-
* last, every player gets { t: 'end' } with the run's kills and deaths per player, and a new
|
|
22
|
-
* run starts at level 0, hard from then on, the counts back at 0.
|
|
23
|
-
* - Every SNAP_EVERY ticks of TICK_HZ, one snapshot with every player, the shots resolved since
|
|
24
|
-
* the last one, the monsters, the bullets, the events since the last one and the items goes to
|
|
25
|
-
* every peer.
|
|
11
|
+
* rewind() answers where the others were drawn at the view tick of an input (lag compensation,
|
|
12
|
+
* at most MAX_REWIND ticks back).
|
|
13
|
+
* - Every SNAP_EVERY ticks of TICK_HZ, one snapshot with every player goes to every peer.
|
|
26
14
|
*/
|
|
27
15
|
export declare class Room {
|
|
28
16
|
/** Every connected peer; null until it joins. */
|
|
29
17
|
private peers;
|
|
30
18
|
private ticks;
|
|
31
|
-
/** The players
|
|
19
|
+
/** The players as each snapshot of the last MAX_REWIND ticks sent them. */
|
|
32
20
|
private history;
|
|
33
|
-
private
|
|
34
|
-
private lvl;
|
|
35
|
-
private horde;
|
|
36
|
-
private rand;
|
|
37
|
-
private level;
|
|
38
|
-
private hard;
|
|
39
|
-
private phase;
|
|
40
|
-
/** The team's key bits (1 << ITEM.KEY_*). */
|
|
41
|
-
private keys;
|
|
42
|
-
private items;
|
|
43
|
-
private nextItem;
|
|
44
|
-
/** Monsters the team killed in this level. */
|
|
45
|
-
private kills;
|
|
46
|
-
/** Host tick the run started at. */
|
|
47
|
-
private runStart;
|
|
48
|
-
/** Shots resolved since the last snapshot. */
|
|
49
|
-
private shots;
|
|
21
|
+
private world;
|
|
50
22
|
private halt;
|
|
51
23
|
private rules;
|
|
52
24
|
/** Round-robin cursor over the spawn points, used once they are all taken. */
|
|
53
25
|
private rr;
|
|
54
|
-
/** Missing rules fall back to RULES.
|
|
55
|
-
constructor(rules?: Partial<Rules>,
|
|
26
|
+
/** Missing rules fall back to RULES. */
|
|
27
|
+
constructor(rules?: Partial<Rules>, map?: WorldDef);
|
|
56
28
|
/** Number of joined players. */
|
|
57
29
|
get size(): number;
|
|
58
30
|
/** A peer opened. Nothing is sent until it joins. */
|
|
@@ -73,26 +45,14 @@ export declare class Room {
|
|
|
73
45
|
start(every?: Every): void;
|
|
74
46
|
stop(): void;
|
|
75
47
|
/**
|
|
76
|
-
* The
|
|
77
|
-
* fractional, read against the current tick and clamped to the
|
|
78
|
-
*
|
|
79
|
-
*
|
|
48
|
+
* The players other than `id` as player `id` drew them at `view`, the view tick of
|
|
49
|
+
* one of its inputs (a u16 tick, fractional, read against the current tick and clamped to the
|
|
50
|
+
* kept history): x, y, z interpolated between the two snapshots around it like the client does.
|
|
51
|
+
* One the history does not hold stands where it is.
|
|
80
52
|
*/
|
|
81
|
-
|
|
82
|
-
/** Resets everything a level owns, and puts every player on a spawn of it with full health. */
|
|
83
|
-
private load;
|
|
53
|
+
rewind(id: number, view?: number): PlayerState[];
|
|
84
54
|
/** The first spawn point with none of `others` within SPAWN_CLEAR, else the next one round-robin. */
|
|
85
55
|
private place;
|
|
86
|
-
/** The floor of the sector holding (x, z). */
|
|
87
|
-
private floor;
|
|
88
|
-
/** Leaves an item of `kind` on the floor at (x, z). */
|
|
89
|
-
private drop;
|
|
90
|
-
/** Takes 1 health off player `id` unless it was hurt less than HIT_COOLDOWN ticks ago. */
|
|
91
|
-
private wound;
|
|
92
|
-
/** What the living players do to the level: pick things up, touch the goal, win. */
|
|
93
|
-
private progress;
|
|
94
|
-
/** The level is won: the next one, or the end of the run and a new, hard one. */
|
|
95
|
-
private win;
|
|
96
56
|
private players;
|
|
97
57
|
private join;
|
|
98
58
|
/** Each joined peer gets the full roster with its own id. */
|
|
@@ -11,8 +11,6 @@ export declare const KEY: {
|
|
|
11
11
|
readonly LEFT: 4;
|
|
12
12
|
readonly RIGHT: 8;
|
|
13
13
|
readonly JUMP: 16;
|
|
14
|
-
/** Left mouse button: the chaingun fires every FIRE_EVERY steps while held. */
|
|
15
|
-
readonly FIRE: 32;
|
|
16
14
|
};
|
|
17
15
|
/** One client step: what the player held during 1 / TICK_HZ s, and where they looked. */
|
|
18
16
|
export interface Input {
|
|
@@ -26,7 +24,7 @@ export interface Input {
|
|
|
26
24
|
pitch: number;
|
|
27
25
|
/**
|
|
28
26
|
* Host tick the client drew the others at when it sent this input, fractional (interpolation
|
|
29
|
-
* between two snapshots), in [0, 65536): the host rewinds the
|
|
27
|
+
* between two snapshots), in [0, 65536): the host rewinds the other players to it (lag
|
|
30
28
|
* compensation). The wire keeps 1/256 tick. Absent (no snapshot seen yet) goes out as 0: the host
|
|
31
29
|
* clamps it to the oldest tick it keeps.
|
|
32
30
|
*/
|
|
@@ -44,112 +42,8 @@ export interface PlayerState {
|
|
|
44
42
|
pitch: number;
|
|
45
43
|
/** Standing on a floor: a jump is allowed. */
|
|
46
44
|
ground: boolean;
|
|
47
|
-
/** Steps until the chaingun may fire again, 0 to FIRE_EVERY. */
|
|
48
|
-
cool: number;
|
|
49
45
|
}
|
|
50
|
-
/**
|
|
51
|
-
export interface Shot {
|
|
52
|
-
/** The shooter. */
|
|
53
|
-
id: number;
|
|
54
|
-
/** Where the shot stopped: a wall, a floor, a ceiling, a target, or RANGE away. */
|
|
55
|
-
x: number;
|
|
56
|
-
y: number;
|
|
57
|
-
z: number;
|
|
58
|
-
/** Id of the player or monster hit, -1 for the level or nothing. */
|
|
59
|
-
hit: number;
|
|
60
|
-
}
|
|
61
|
-
/** Monster kinds. */
|
|
62
|
-
export declare const MONSTER: {
|
|
63
|
-
/** Walks the floors like a player, shoots bullets from afar and hits up close. */
|
|
64
|
-
readonly WALKER: 0;
|
|
65
|
-
/** Hovers above the floor, flies over steps and pits, hits up close. */
|
|
66
|
-
readonly FLYER: 1;
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* A monster as the host runs it and the snapshot carries it. Ids run from MAX_PLAYERS up, so a
|
|
70
|
-
* Shot.hit or an event names a player or a monster with one u8.
|
|
71
|
-
*/
|
|
72
|
-
export interface Monster {
|
|
73
|
-
id: number;
|
|
74
|
-
/** MONSTER kind. */
|
|
75
|
-
kind: number;
|
|
76
|
-
/** Bottom of the body: the feet of a walker, the underside of a flyer. */
|
|
77
|
-
x: number;
|
|
78
|
-
y: number;
|
|
79
|
-
z: number;
|
|
80
|
-
/** Facing, as a player's yaw. */
|
|
81
|
-
yaw: number;
|
|
82
|
-
/** Hunting a player (it saw one, or was alerted), not patrolling. */
|
|
83
|
-
chase: boolean;
|
|
84
|
-
}
|
|
85
|
-
/** A monster's bullet in flight, host-simulated. Ids are a u8 counter that wraps. */
|
|
86
|
-
export interface Bullet {
|
|
87
|
-
id: number;
|
|
88
|
-
x: number;
|
|
89
|
-
y: number;
|
|
90
|
-
z: number;
|
|
91
|
-
}
|
|
92
|
-
/** What a GameEvent reports. */
|
|
93
|
-
export declare const EVENT: {
|
|
94
|
-
/** Monster `id` died, (x, y, z) the middle of its body: gibs and an explosion. */
|
|
95
|
-
readonly DIE: 0;
|
|
96
|
-
/** Player `id` was hit by a bullet or a blow at (x, y, z). Harmless until health (step 4). */
|
|
97
|
-
readonly HURT: 1;
|
|
98
|
-
/** A bullet burst on the level at (x, y, z); `id` is the bullet. */
|
|
99
|
-
readonly BOOM: 2;
|
|
100
|
-
/** Monster `id` swung at its target from (x, y, z), hit or miss. */
|
|
101
|
-
readonly SWING: 3;
|
|
102
|
-
};
|
|
103
|
-
export interface GameEvent {
|
|
104
|
-
/** EVENT type. */
|
|
105
|
-
type: number;
|
|
106
|
-
id: number;
|
|
107
|
-
x: number;
|
|
108
|
-
y: number;
|
|
109
|
-
z: number;
|
|
110
|
-
}
|
|
111
|
-
/** Something a shot can hit: an upright cylinder of radius r from y up to y + h. */
|
|
112
|
-
export interface Body {
|
|
113
|
-
id: number;
|
|
114
|
-
x: number;
|
|
115
|
-
y: number;
|
|
116
|
-
z: number;
|
|
117
|
-
r: number;
|
|
118
|
-
h: number;
|
|
119
|
-
}
|
|
120
|
-
/** Pickup kinds. A key is shared by the team: once anyone takes it, its gates open for all. */
|
|
121
|
-
export declare const ITEM: {
|
|
122
|
-
/** Gives HEAL health, up to HEALTH. Left in the level by every DROP_EVERY-th kill. */
|
|
123
|
-
readonly HEALTH: 0;
|
|
124
|
-
readonly KEY_RED: 1;
|
|
125
|
-
readonly KEY_BLUE: 2;
|
|
126
|
-
readonly KEY_YELLOW: 3;
|
|
127
|
-
};
|
|
128
|
-
/** A pickup lying in the level. Ids are unique within a level, u8. */
|
|
129
|
-
export interface Item {
|
|
130
|
-
id: number;
|
|
131
|
-
/** ITEM kind. */
|
|
132
|
-
kind: number;
|
|
133
|
-
/** Where it rests: on the floor of the sector under it. */
|
|
134
|
-
x: number;
|
|
135
|
-
y: number;
|
|
136
|
-
z: number;
|
|
137
|
-
}
|
|
138
|
-
/** A barred doorway: bodies cannot enter the sector until the team holds the key. */
|
|
139
|
-
export interface Gate {
|
|
140
|
-
/** Sector index, a thin doorway between two rooms. */
|
|
141
|
-
sector: number;
|
|
142
|
-
/** ITEM.KEY_* kind that opens it. */
|
|
143
|
-
key: number;
|
|
144
|
-
}
|
|
145
|
-
/** Where a level stands. */
|
|
146
|
-
export declare const PHASE: {
|
|
147
|
-
/** Find the goal: the exit sector is barred. */
|
|
148
|
-
readonly HUNT: 0;
|
|
149
|
-
/** The goal was touched: the exit sector is open; the level is won when every living player is in it. */
|
|
150
|
-
readonly RETURN: 1;
|
|
151
|
-
};
|
|
152
|
-
/** Procedural textures, generated by the client. A sector names one per surface. */
|
|
46
|
+
/** Procedural textures, generated by the client. A brush names one for its top and one for its sides. */
|
|
153
47
|
export declare const TEX: {
|
|
154
48
|
readonly BRICK: 0;
|
|
155
49
|
readonly TILE: 1;
|
|
@@ -164,74 +58,6 @@ export declare const TEX: {
|
|
|
164
58
|
/** Metal floor grating over darkness. */
|
|
165
59
|
readonly GRATE: 7;
|
|
166
60
|
};
|
|
167
|
-
/**
|
|
168
|
-
* A room, Doom style: a convex polygon on the floor plane with a flat floor and a flat ceiling.
|
|
169
|
-
* Two sectors are joined where one has the edge a→b and the other b→a with the very same
|
|
170
|
-
* coordinates (a portal); every other edge is a solid wall. Split an edge with collinear points
|
|
171
|
-
* when several sectors meet it (no T-junctions).
|
|
172
|
-
*/
|
|
173
|
-
export interface Sector {
|
|
174
|
-
/**
|
|
175
|
-
* Corners as (x, z), counter-clockwise: the signed area Σ (x_i z_{i+1} - x_{i+1} z_i) is positive.
|
|
176
|
-
* Collinear points are allowed.
|
|
177
|
-
*/
|
|
178
|
-
pts: [x: number, z: number][];
|
|
179
|
-
/** Heights in metres, ceil > floor. */
|
|
180
|
-
floor: number;
|
|
181
|
-
ceil: number;
|
|
182
|
-
/** TEX ids of the floor, the walls (and steps) on its edges, and the ceiling. */
|
|
183
|
-
ft: number;
|
|
184
|
-
wt: number;
|
|
185
|
-
ct: number;
|
|
186
|
-
/** Light level multiplied into the shading, 0 to 1. Absent: 1. */
|
|
187
|
-
light?: number;
|
|
188
|
-
/** Colour of the sector's ambient light, linear RGB 0 to 1 (a cold blue cellar, a warm furnace). Absent: white. */
|
|
189
|
-
tint?: [r: number, g: number, b: number];
|
|
190
|
-
}
|
|
191
|
-
export interface MapDef {
|
|
192
|
-
/** Shown on the title screen after the level number. */
|
|
193
|
-
name?: string;
|
|
194
|
-
/** Fog colour (linear RGB 0 to 1) and density per metre (0.02 is the default haze). Absent: the default. */
|
|
195
|
-
fog?: [r: number, g: number, b: number, density: number];
|
|
196
|
-
sectors: Sector[];
|
|
197
|
-
/** Spawn points: feet x, z (inside a sector, standing on its floor) and the yaw to face. */
|
|
198
|
-
spawns: [x: number, z: number, yaw: number][];
|
|
199
|
-
/** Monsters at the start: x, z inside a sector, the yaw they face, their MONSTER kind. Absent: none. */
|
|
200
|
-
monsters?: [x: number, z: number, yaw: number, kind: number][];
|
|
201
|
-
/** Pickups at the start: x, z inside a sector, their ITEM kind. Absent: none. */
|
|
202
|
-
items?: [x: number, z: number, kind: number][];
|
|
203
|
-
/** Barred doorways. Absent: none. */
|
|
204
|
-
gates?: Gate[];
|
|
205
|
-
/** The goal pad, far from the start: touching it (within GOAL_R) turns the level to RETURN. */
|
|
206
|
-
goal?: [x: number, z: number];
|
|
207
|
-
/**
|
|
208
|
-
* Sector index of the exit, barred until the goal is touched. Usually the start room: players
|
|
209
|
-
* spawn in it and can walk out, but not back in until RETURN.
|
|
210
|
-
*/
|
|
211
|
-
exit?: number;
|
|
212
|
-
}
|
|
213
|
-
/** One directed edge of a sector, see compile in level.ts. */
|
|
214
|
-
export interface Edge {
|
|
215
|
-
ax: number;
|
|
216
|
-
az: number;
|
|
217
|
-
bx: number;
|
|
218
|
-
bz: number;
|
|
219
|
-
/** Index of the sector the edge belongs to (the side it faces into). */
|
|
220
|
-
front: number;
|
|
221
|
-
/** Index of the sector across a portal, -1 for a solid wall. */
|
|
222
|
-
back: number;
|
|
223
|
-
}
|
|
224
|
-
/** A map ready for physics and drawing. */
|
|
225
|
-
export interface Level {
|
|
226
|
-
map: MapDef;
|
|
227
|
-
/** Every edge of every sector, in sector then point order. */
|
|
228
|
-
edges: Edge[];
|
|
229
|
-
/**
|
|
230
|
-
* Sectors that bodies cannot enter now: gates without their key, the exit before RETURN.
|
|
231
|
-
* Mutable: set it with bar() in level.ts (host and client alike); sight and shots ignore it.
|
|
232
|
-
*/
|
|
233
|
-
barred: Set<number>;
|
|
234
|
-
}
|
|
235
61
|
/** One player in a snapshot. */
|
|
236
62
|
export interface SnapPlayer {
|
|
237
63
|
id: number;
|
|
@@ -242,9 +68,6 @@ export interface SnapPlayer {
|
|
|
242
68
|
yaw: number;
|
|
243
69
|
pitch: number;
|
|
244
70
|
ground: boolean;
|
|
245
|
-
cool: number;
|
|
246
|
-
/** Health, HEALTH at most; 0 is dead, waiting PLAYER_RESPAWN ticks to respawn at the start. */
|
|
247
|
-
hp: number;
|
|
248
71
|
/** Seq of the last input of this player the host applied: the client replays the ones after. */
|
|
249
72
|
ack: number;
|
|
250
73
|
}
|
|
@@ -252,24 +75,6 @@ export interface Snapshot {
|
|
|
252
75
|
/** Host tick, u16, wraps. */
|
|
253
76
|
tick: number;
|
|
254
77
|
players: SnapPlayer[];
|
|
255
|
-
/** Shots fired since the previous snapshot, in order. */
|
|
256
|
-
shots: Shot[];
|
|
257
|
-
/** Living monsters. */
|
|
258
|
-
monsters: Monster[];
|
|
259
|
-
/** Bullets in flight. */
|
|
260
|
-
bullets: Bullet[];
|
|
261
|
-
/** Events since the previous snapshot, in order. */
|
|
262
|
-
events: GameEvent[];
|
|
263
|
-
/** Index of the level in LEVELS (levels.ts). A change means a new level: clients rebuild. */
|
|
264
|
-
level: number;
|
|
265
|
-
/** The second run and later: monsters are faster and fire more often. */
|
|
266
|
-
hard: boolean;
|
|
267
|
-
/** PHASE of the level. */
|
|
268
|
-
phase: number;
|
|
269
|
-
/** Keys the team holds: bit (1 << ITEM.KEY_*). */
|
|
270
|
-
keys: number;
|
|
271
|
-
/** Pickups lying in the level. */
|
|
272
|
-
items: Item[];
|
|
273
78
|
}
|
|
274
79
|
/** Room rules, set by the host. Defaults in constants.ts (RULES). */
|
|
275
80
|
export interface Rules {
|
|
@@ -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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@korial29/tiny-fps",
|
|
3
|
-
"description": "Tiny multiplayer first-person
|
|
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,24 +0,0 @@
|
|
|
1
|
-
import type { Vec3 } from './mesh';
|
|
2
|
-
/** Where the barrels end, on -z: the muzzle flash sits just past it. */
|
|
3
|
-
export declare const MUZZLE = 0.55;
|
|
4
|
-
/**
|
|
5
|
-
* Revolves a profile of [radius, length] points around the axis through `at` along -z: `length`
|
|
6
|
-
* runs forward from `at`. Returns triangles as x, y, z, nx, ny, nz per vertex, `sides` quads of 2
|
|
7
|
-
* triangles per profile segment. The profile goes from back to front and closes on the axis, so
|
|
8
|
-
* the normals (smooth around the ring, flat along the profile) point outward.
|
|
9
|
-
*/
|
|
10
|
-
export declare const lathe: (profile: [number, number][], sides: number, at?: Vec3) => number[];
|
|
11
|
-
/**
|
|
12
|
-
* The chaingun, built once per level of detail. Group by group, vertices as in lathe: `barrels` and
|
|
13
|
-
* `clamps` turn around the central axis (the caller spins them), the rest stays: `body`, `trim`
|
|
14
|
-
* (lighter metal), `holes` (dark) and `brass` (the belt). Past 6 sides it adds the fine parts:
|
|
15
|
-
* clamps, shroud with cooling holes, bolts, ammo box, belt, handle and ejection port.
|
|
16
|
-
*/
|
|
17
|
-
export declare const chaingun: (sides: number) => {
|
|
18
|
-
barrels: number[];
|
|
19
|
-
clamps: number[];
|
|
20
|
-
body: number[];
|
|
21
|
-
trim: number[];
|
|
22
|
-
holes: number[];
|
|
23
|
-
brass: number[];
|
|
24
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Item, Level } from '../shared/types';
|
|
2
|
-
/** Colour of each ITEM kind: the pickup, the bars of its gate, the HUD mark and the pickup fade. */
|
|
3
|
-
export declare const ITEM_COLOR: number[][];
|
|
4
|
-
/** A 0 to 1 colour as CSS, with alpha a. */
|
|
5
|
-
export declare const css: (c: number[], a?: number) => string;
|
|
6
|
-
/**
|
|
7
|
-
* A pickup, bobbing and spinning above its floor: HEALTH a white box with a red cross, a key a
|
|
8
|
-
* ring (glowing), a shaft and two teeth in its colour.
|
|
9
|
-
*/
|
|
10
|
-
export declare const item: (out: number[], { id, kind, x, y, z }: Item, t: number) => void;
|
|
11
|
-
/**
|
|
12
|
-
* Every barred gate gets upright bars across the portal edges of its sector, in its key's colour:
|
|
13
|
-
* they go with the key. The exit, once open, gets a glowing frame on its portals, pulsing.
|
|
14
|
-
*/
|
|
15
|
-
export declare const gates: (out: number[], lvl: Level, t: number) => void;
|
|
16
|
-
/** The goal: a pad on the floor that swells and fades with the clock, and a crystal above it. */
|
|
17
|
-
export declare const pad: (out: number[], lvl: Level, t: number) => void;
|
|
18
|
-
/** Items, gates, the exit frame and the goal pad. */
|
|
19
|
-
export declare const props: (out: number[], lvl: Level, items: Item[], t: number) => void;
|