@korial29/tiny-fps 0.192.4 → 0.194.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/dist/index.js +44 -44
- package/dist/local.js +1 -1
- package/dist/server.js +31 -19
- package/dist/targeting-Dia_z4Fw.js +1 -0
- package/dist/types/client/targeting-physics.d.ts +26 -0
- package/dist/types/client/targeting.d.ts +33 -0
- package/dist/types/shared/protocol.d.ts +3 -3
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -3668,11 +3668,16 @@ var { STONE, CONCRETE, METAL, STEEL, PAINT } = TEX;
|
|
|
3668
3668
|
/** The twin of a box across the centre line. */
|
|
3669
3669
|
var mirror$1 = ({ min, max }) => bx(min[0], min[1], 280 - max[2], max[0], max[1], 280 - min[2]);
|
|
3670
3670
|
/** The domes' centres, the landing pads (x, z, radius), the modules, the tubes and the masts (centres), red's then blue's: what the scenery draws on. */
|
|
3671
|
-
|
|
3671
|
+
/** Two a base (the user, 2026-11-20: a second ship a team), the second west of the first. */
|
|
3672
|
+
var PADS = [[
|
|
3672
3673
|
40,
|
|
3673
3674
|
220,
|
|
3674
3675
|
13
|
|
3675
|
-
]
|
|
3676
|
+
], [
|
|
3677
|
+
13.5,
|
|
3678
|
+
220,
|
|
3679
|
+
13
|
|
3680
|
+
]];
|
|
3676
3681
|
/** By the tubes. The four at the pad's corners went (the user, 2026-11-14): a ship hit them for nothing. */
|
|
3677
3682
|
var MASTS = [[106.2, 230.4], [103.2, 212.4]];
|
|
3678
3683
|
/** Red's flag: in the hall, 2 m from the dome's centre toward the door. */
|
|
@@ -3862,6 +3867,12 @@ var FLATS = [
|
|
|
3862
3867
|
53,
|
|
3863
3868
|
93
|
|
3864
3869
|
],
|
|
3870
|
+
[
|
|
3871
|
+
.5,
|
|
3872
|
+
67,
|
|
3873
|
+
26.5,
|
|
3874
|
+
93
|
|
3875
|
+
],
|
|
3865
3876
|
[
|
|
3866
3877
|
56,
|
|
3867
3878
|
74,
|
|
@@ -4604,11 +4615,11 @@ var LAYOUT = {
|
|
|
4604
4615
|
sites: SITES,
|
|
4605
4616
|
pillars: PILLARS,
|
|
4606
4617
|
domes: [DOME, [DOME[0], 280 - DOME[1]]],
|
|
4607
|
-
pads: [
|
|
4608
|
-
|
|
4609
|
-
280 -
|
|
4610
|
-
|
|
4611
|
-
]],
|
|
4618
|
+
pads: [...PADS, ...PADS.map(([x, z, r]) => [
|
|
4619
|
+
x,
|
|
4620
|
+
280 - z,
|
|
4621
|
+
r
|
|
4622
|
+
])],
|
|
4612
4623
|
modules: [...MODULES, ...MODULES.map(mirror$1)],
|
|
4613
4624
|
tubes: [...TUBES, ...TUBES.map(mirror$1)],
|
|
4614
4625
|
masts: [...MASTS, ...MASTS.map(([x, z]) => [x, 280 - z])]
|
|
@@ -4678,7 +4689,7 @@ var half = [
|
|
|
4678
4689
|
ghost: true
|
|
4679
4690
|
},
|
|
4680
4691
|
box$1(60, 0, 259, 70, 1.5, 265, STEEL, PAINT, RED),
|
|
4681
|
-
box$1(
|
|
4692
|
+
...PADS.map(([x, z, r]) => box$1(x - r, 0, z - r, x + r, .25, z + r, METAL)),
|
|
4682
4693
|
...MASTS.map(([x, z]) => box$1(x - .2, 0, z - .2, x + .2, 10, z + .2, STEEL)),
|
|
4683
4694
|
box$1(12, -30, 148 - 2.5 / 2, 24, 0, 148, PAINT, STONE, [
|
|
4684
4695
|
1,
|
|
@@ -4931,17 +4942,17 @@ var MOON = {
|
|
|
4931
4942
|
Math.PI
|
|
4932
4943
|
]
|
|
4933
4944
|
],
|
|
4934
|
-
ships: [[
|
|
4935
|
-
|
|
4945
|
+
ships: [...PADS.map(([x, z]) => [
|
|
4946
|
+
x,
|
|
4936
4947
|
.25,
|
|
4937
|
-
|
|
4948
|
+
z,
|
|
4938
4949
|
0
|
|
4939
|
-
], [
|
|
4940
|
-
|
|
4950
|
+
]), ...PADS.map(([x, z]) => [
|
|
4951
|
+
x,
|
|
4941
4952
|
.25,
|
|
4942
|
-
280 -
|
|
4953
|
+
280 - z,
|
|
4943
4954
|
Math.PI
|
|
4944
|
-
]],
|
|
4955
|
+
])],
|
|
4945
4956
|
doors: [
|
|
4946
4957
|
...DOORS,
|
|
4947
4958
|
...DOORS.map(mirror$1),
|
|
@@ -8577,8 +8588,8 @@ var decodeInput = (buf) => {
|
|
|
8577
8588
|
/** Bytes of a flag on the wire, by its state. */
|
|
8578
8589
|
var flagBytes = (state) => state === FLAG$1.CARRIED ? 2 : state === FLAG$1.DROPPED ? 8 : 1;
|
|
8579
8590
|
var encodeSnapshot = (s) => {
|
|
8580
|
-
const rovers = (s.rovers ?? []).slice(0,
|
|
8581
|
-
const mid =
|
|
8591
|
+
const rovers = (s.rovers ?? []).slice(0, 15);
|
|
8592
|
+
const mid = 5 + 62 * s.players.length;
|
|
8582
8593
|
const end = mid + 57 * rovers.length;
|
|
8583
8594
|
const balls = s.balls ?? [];
|
|
8584
8595
|
const tail = end + 10 + s.flags.reduce((n, f) => n + flagBytes(f.state), 0);
|
|
@@ -8588,9 +8599,10 @@ var encodeSnapshot = (s) => {
|
|
|
8588
8599
|
const v = new DataView(new ArrayBuffer(tail + (balls.length || gate ? 1 + 11 * balls.length : 0) + gate + (st ? 2 : 0)));
|
|
8589
8600
|
v.setUint8(0, 2);
|
|
8590
8601
|
v.setUint16(1, s.tick & 65535);
|
|
8591
|
-
v.setUint8(3, s.players.length
|
|
8602
|
+
v.setUint8(3, s.players.length);
|
|
8603
|
+
v.setUint8(4, rovers.length);
|
|
8592
8604
|
s.players.forEach((p, i) => {
|
|
8593
|
-
const o =
|
|
8605
|
+
const o = 5 + i * 62;
|
|
8594
8606
|
v.setUint8(o, p.id);
|
|
8595
8607
|
v.setFloat32(o + 1, p.x);
|
|
8596
8608
|
v.setFloat32(o + 5, p.y);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=(e,t,{vx:n,vy:r,vz:i},a,o)=>{let[s,c,l]=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],u=s*s+c*c+l*l,d=a**2-(n*n+r*r+i*i),f=s*n+c*r+l*i,p=u/(Math.sqrt(f*f+d*u)-f);if(p>0&&p<=o/a)return[t[0]+n*p,t[1]+r*p,t[2]+i*p]},t=e=>!!e&&e[0]>=0&&e[0]<=1&&e[1]>=0&&e[1]<=1,n=({world:n,camera:r,yaw:i,aspect:a,project:o,hostile:s},c,l,u,d,{BOLT_SPEED:f,PLAYER_R:p,range:m,MODE:h,NOBODY:g,hidden:_,heightOf:v,muzzleOf:y})=>{let b=o(...l),x={boxes:[],aim:b},S=y(c),[C,w,T]=l.map((e,t)=>e-S[t]),E=C*C+w*w+T*T,[D,O]=[Math.cos(i),-Math.sin(i)],k=n.def.seam,A=1/0,j=(i,s,c,l)=>{let u=[i.x,s,i.z],d=o(...u);if(!t(d)||_(n,r,u))return;let p=o(u[0]+D,s,u[2]+O)??d,h=2*Math.hypot((p[0]-d[0])*a,p[1]-d[1]);x.boxes.push({at:d,width:h*c/a,height:h*l});let g=b?Math.hypot((d[0]-b[0])*a,d[1]-b[1]):1/0;if(g>=A)return;let v=e(S,u,i,f,m);if(!v||k!==void 0&&v[1]>k!=S[1]>k)return;let y=o(...v);if(!t(y)||_(n,S,v))return;let j=((v[0]-S[0])*C+(v[1]-S[1])*w+(v[2]-S[2])*T)/E;j>0&&(A=g,x.lead=y,x.aim=o(S[0]+j*C,S[1]+j*w,S[2]+j*T))};for(let e of u){let t=e.driver===g?e.rider:e.driver;e!==c&&!e.wreck&&s(t)&&j(e,e.y,e.ship?7:2.8,e.ship?4:1.4)}for(let e of d)if(!e.down&&e.mode!==h.RIDE&&s(e.id)){let t=v(e)/2;j(e,e.y+t,p,t)}return x},r=(e,t,r)=>{let{PLAYER_R:i,MODE:a,NOBODY:o,aimOf:s,cylinder:c,heightOf:l,homeOf:u,ray:d,struck:f}=r;e.insertAdjacentHTML(`beforeend`,`<style>q{width:26px;height:26px;margin:-13px 0 0 -13px;border:2px solid #5f8;border-radius:50%;box-shadow:0 0 6px #3f6,inset 0 0 4px #3f6;background:radial-gradient(#afc 0 1.5px,#0000 2px)}q::before,q::after{content:none}.targets{position:absolute;inset:0;pointer-events:none}.target,.lead{position:absolute;transform:translate(-50%,-50%);box-sizing:border-box;border:2px solid #ff514d;box-shadow:0 0 3px #000}.target{min-width:26px;min-height:26px;max-width:90%;max-height:90%}.lead{width:18px;height:18px;border-radius:50%;border-style:dashed;background:radial-gradient(#ff514d 0 1px,transparent 2px)}</style><span class="targets" aria-hidden="true" hidden><span class="lead" hidden></span></span>`);let p=e.querySelector(`.targets`),m=p.querySelector(`.lead`),h=[],g=(e,[t,n])=>{e.style.left=`${t*100}%`,e.style.top=`${n*100}%`};return{frame(e,{yaw:_,pitch:v},y,b,x,S,C,w,T){if(p.hidden=!e?.ship,!e)return;let E=e=>{let t=T(e);return t!==void 0&&t!==w},D=S.filter((n,r)=>{let i=n.driver===o?n.rider:n.driver;return n!==e&&!n.wreck&&(!e.ship||(T(i)??u(t,r))!==w)}),O=C.filter(t=>!t.down&&t.mode!==a.RIDE&&(!e.ship||E(t.id))),k=s(e,_,v,(e,n,r)=>Math.min(d(t,e,n,r),...D.map(t=>f(t,e,n,r)),...O.map(t=>c(e,n,t,i,l(t)))));if(!e.ship)return x(...k);let{boxes:A,aim:j,lead:M}=n({world:t,camera:y,yaw:_,aspect:b,project:x,hostile:E},e,k,D,O,r);for(let e=0;e<A.length;e++){let{at:t,width:n,height:r}=A[e],i=h[e];i||(i=h[e]=document.createElement(`span`),i.className=`target`,p.prepend(i)),i.hidden=!1,g(i,t),i.style.width=`${n*100}%`,i.style.height=`${r*100}%`}for(let e=A.length;e<h.length;e++)h[e].hidden=!0;return m.hidden=!M,M&&g(m,M),j}}};export{r as createTargeting};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Rover } from '../shared/types';
|
|
2
|
+
export declare const targetingPhysics: {
|
|
3
|
+
BOLT_SPEED: number;
|
|
4
|
+
PLAYER_R: number;
|
|
5
|
+
range: 160;
|
|
6
|
+
MODE: {
|
|
7
|
+
readonly GROUND: 0;
|
|
8
|
+
readonly AIR: 1;
|
|
9
|
+
readonly WALLRUN: 2;
|
|
10
|
+
readonly HANG: 3;
|
|
11
|
+
readonly CLIMB: 4;
|
|
12
|
+
readonly SLIDE: 5;
|
|
13
|
+
readonly CROUCH: 6;
|
|
14
|
+
readonly RIDE: 7;
|
|
15
|
+
readonly CLING: 8;
|
|
16
|
+
};
|
|
17
|
+
NOBODY: number;
|
|
18
|
+
aimOf: (r: Rover, yaw: number, pitch: number, sight?: import("../shared/rover").Sight) => [number, number, number];
|
|
19
|
+
cylinder: (o: [number, number, number], d: [number, number, number], c: Pick<import("../shared/types").PlayerState, "x" | "y" | "z">, r: number, h: number) => number;
|
|
20
|
+
heightOf: (p: Pick<import("../shared/types").PlayerState, "mode">) => number;
|
|
21
|
+
homeOf: (w: import("../shared/world").World, k: number) => number;
|
|
22
|
+
hidden: (w: import("../shared/world").World, a: [number, number, number], b: [number, number, number]) => boolean;
|
|
23
|
+
ray: (w: import("../shared/world").World, o: [number, number, number], d: [number, number, number], max: number, grow?: number) => number;
|
|
24
|
+
struck: (r: Rover, o: [x: number, y: number, z: number], d: [x: number, y: number, z: number], m: number) => number;
|
|
25
|
+
muzzleOf: (ship: Rover) => [x: number, y: number, z: number];
|
|
26
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PlayerState, Rover } from '../shared/types';
|
|
2
|
+
import type { World } from '../shared/world';
|
|
3
|
+
import type { Renderer } from './render';
|
|
4
|
+
import type { targetingPhysics } from './targeting-physics';
|
|
5
|
+
type Vec3 = [number, number, number];
|
|
6
|
+
type ScreenPoint = [number, number];
|
|
7
|
+
type Target = Pick<Rover, 'x' | 'y' | 'z' | 'vx' | 'vy' | 'vz'>;
|
|
8
|
+
interface ShipTargeting {
|
|
9
|
+
boxes: {
|
|
10
|
+
at: ScreenPoint;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
}[];
|
|
14
|
+
lead?: ScreenPoint;
|
|
15
|
+
aim?: ScreenPoint;
|
|
16
|
+
}
|
|
17
|
+
/** Intercept at constant target velocity. The ship's bolts do not inherit its velocity. */
|
|
18
|
+
export declare const intercept: (from: Vec3, at: Vec3, { vx, vy, vz }: Target, speed: number, range: number) => Vec3 | undefined;
|
|
19
|
+
type Physics = typeof targetingPhysics;
|
|
20
|
+
interface View {
|
|
21
|
+
world: World;
|
|
22
|
+
camera: Vec3;
|
|
23
|
+
yaw: number;
|
|
24
|
+
aspect: number;
|
|
25
|
+
project: Renderer['project'];
|
|
26
|
+
hostile(id: number): boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare const shipTargeting: ({ world, camera, yaw, aspect, project, hostile }: View, ship: Rover, convergence: Vec3, rovers: Rover[], players: PlayerState[], { BOLT_SPEED, PLAYER_R, range, MODE, NOBODY, hidden, heightOf, muzzleOf }: Physics) => ShipTargeting;
|
|
29
|
+
/** The overlay is loaded only on maps with vehicles. */
|
|
30
|
+
export declare const createTargeting: (screen: HTMLElement, world: World, physics: Physics) => {
|
|
31
|
+
frame(car: Rover | undefined, { yaw, pitch }: Pick<Rover, "yaw" | "pitch">, camera: Vec3, aspect: number, project: Renderer["project"], rovers: Rover[], players: PlayerState[], ownTeam: number, team: (id: number) => number | undefined): ScreenPoint | undefined;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
@@ -83,12 +83,12 @@ export type ServerText =
|
|
|
83
83
|
export declare const MSG_INPUT = 1;
|
|
84
84
|
export declare const MSG_SNAPSHOT = 2;
|
|
85
85
|
export declare const INPUT_BYTES = 12;
|
|
86
|
-
export declare const SNAP_HEAD =
|
|
86
|
+
export declare const SNAP_HEAD = 5;
|
|
87
87
|
export declare const SNAP_PLAYER = 62;
|
|
88
88
|
/** Bytes of a rover: thirteen float32, the two seats, then the kind and health, the wreck's time and a ship's missiles. */
|
|
89
89
|
export declare const SNAP_ROVER = 57;
|
|
90
|
-
/** The
|
|
91
|
-
export declare const MAX_ROVERS =
|
|
90
|
+
/** The most rovers and ships a snapshot carries (Tranquility has eight: four rovers, four ships). */
|
|
91
|
+
export declare const MAX_ROVERS = 15;
|
|
92
92
|
/** The match block after the players and the rovers: the captures, the clock, the packs; the flags follow (2 to 16 bytes). */
|
|
93
93
|
export declare const SNAP_MATCH = 10;
|
|
94
94
|
/** Bytes of a plasma ball. */
|
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.194.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|