@korial29/tiny-fps 0.109.0 → 0.110.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 +2 -2
- package/dist/index.js +15 -15
- package/dist/local.js +1 -1
- package/dist/server.js +406 -30
- package/dist/types/shared/moon.d.ts +43 -0
- package/dist/types/shared/relief.d.ts +2 -0
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -213,6 +213,8 @@ var raise = (def) => {
|
|
|
213
213
|
h[i + j * nx] = at(x0 + i * cell, z0 + j * cell);
|
|
214
214
|
top = Math.max(top, h[i + j * nx]);
|
|
215
215
|
}
|
|
216
|
+
const pitted = new Uint8Array(nx * nz);
|
|
217
|
+
for (const [px0, pz0, px1, pz1] of pits) for (let j = Math.floor((pz0 - z0) / cell) - 1; j <= Math.floor((pz1 - z0) / cell) + 1; j++) for (let i = Math.floor((px0 - x0) / cell) - 1; i <= Math.floor((px1 - x0) / cell) + 1; i++) if (i >= 0 && j >= 0 && i < nx && j < nz) pitted[i + j * nx] = 1;
|
|
216
218
|
const r = {
|
|
217
219
|
x0,
|
|
218
220
|
z0,
|
|
@@ -222,6 +224,7 @@ var raise = (def) => {
|
|
|
222
224
|
h,
|
|
223
225
|
hole,
|
|
224
226
|
pits,
|
|
227
|
+
pitted,
|
|
225
228
|
box,
|
|
226
229
|
bound,
|
|
227
230
|
top
|
|
@@ -235,12 +238,12 @@ var raise = (def) => {
|
|
|
235
238
|
*/
|
|
236
239
|
var ground = (w, x, z) => {
|
|
237
240
|
const r = w.relief;
|
|
238
|
-
|
|
239
|
-
if (!r || x > r.hole[0] && x < r.hole[2] && z > r.hole[1] && z < r.hole[3] || pit(r.box) && r.pits.some(pit)) return -Infinity;
|
|
241
|
+
if (!r || x > r.hole[0] && x < r.hole[2] && z > r.hole[1] && z < r.hole[3]) return -Infinity;
|
|
240
242
|
const u = Math.min(Math.max((x - r.x0) / r.cell, 0), r.nx - 1);
|
|
241
243
|
const v = Math.min(Math.max((z - r.z0) / r.cell, 0), r.nz - 1);
|
|
242
244
|
const i = Math.min(Math.floor(u), r.nx - 2);
|
|
243
245
|
const j = Math.min(Math.floor(v), r.nz - 2);
|
|
246
|
+
if (r.pitted[i + j * r.nx] && r.pits.some((q) => x >= q[0] && x <= q[2] && z >= q[1] && z <= q[3])) return -Infinity;
|
|
244
247
|
const [fu, fv] = [u - i, v - j];
|
|
245
248
|
const n = i + j * r.nx;
|
|
246
249
|
const [a, b, c, d] = [
|
|
@@ -3322,17 +3325,27 @@ var FLAG = DOME[1] - 2;
|
|
|
3322
3325
|
var c1 = (t) => Math.min(Math.max(t, 0), 1);
|
|
3323
3326
|
var sm = (t) => c1(t) * c1(t) * (3 - 2 * c1(t));
|
|
3324
3327
|
var far = (a, b) => Math.sqrt(a * a + b * b);
|
|
3325
|
-
/**
|
|
3328
|
+
/**
|
|
3329
|
+
* Craters, x, z, radius and how deep as a share of the radius: a bowl under a rim, both wandering
|
|
3330
|
+
* with the bearing (the rim is 0.03 to 0.075 of the radius high and up to 10 % nearer or further),
|
|
3331
|
+
* flat for 4 m. With a fifth number, a pit's crater: a level terrace out to that share of the
|
|
3332
|
+
* radius (22 m and more), then one wall up to the rim; the pit is cut in the terrace (PITS). The
|
|
3333
|
+
* first is the Bowl; the small ones by a big one's rim are its secondaries.
|
|
3334
|
+
*/
|
|
3326
3335
|
var BOWLS = [
|
|
3327
3336
|
[
|
|
3328
3337
|
-100,
|
|
3329
3338
|
0,
|
|
3330
|
-
46
|
|
3339
|
+
46,
|
|
3340
|
+
.13,
|
|
3341
|
+
.52
|
|
3331
3342
|
],
|
|
3332
3343
|
[
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3344
|
+
-4,
|
|
3345
|
+
224,
|
|
3346
|
+
36,
|
|
3347
|
+
.12,
|
|
3348
|
+
.67
|
|
3336
3349
|
],
|
|
3337
3350
|
[
|
|
3338
3351
|
110,
|
|
@@ -3350,9 +3363,59 @@ var BOWLS = [
|
|
|
3350
3363
|
13
|
|
3351
3364
|
],
|
|
3352
3365
|
[
|
|
3353
|
-
-
|
|
3354
|
-
|
|
3366
|
+
-52,
|
|
3367
|
+
230,
|
|
3368
|
+
10
|
|
3369
|
+
],
|
|
3370
|
+
[
|
|
3371
|
+
80,
|
|
3372
|
+
184,
|
|
3373
|
+
14
|
|
3374
|
+
],
|
|
3375
|
+
[
|
|
3376
|
+
150,
|
|
3377
|
+
250,
|
|
3378
|
+
13
|
|
3379
|
+
],
|
|
3380
|
+
[
|
|
3381
|
+
-36,
|
|
3382
|
+
168,
|
|
3383
|
+
10
|
|
3384
|
+
],
|
|
3385
|
+
[
|
|
3386
|
+
200,
|
|
3387
|
+
152,
|
|
3355
3388
|
12
|
|
3389
|
+
],
|
|
3390
|
+
[
|
|
3391
|
+
262,
|
|
3392
|
+
134,
|
|
3393
|
+
14
|
|
3394
|
+
],
|
|
3395
|
+
[
|
|
3396
|
+
240,
|
|
3397
|
+
150,
|
|
3398
|
+
9
|
|
3399
|
+
],
|
|
3400
|
+
[
|
|
3401
|
+
-140,
|
|
3402
|
+
60,
|
|
3403
|
+
12
|
|
3404
|
+
],
|
|
3405
|
+
[
|
|
3406
|
+
-66,
|
|
3407
|
+
60,
|
|
3408
|
+
9
|
|
3409
|
+
],
|
|
3410
|
+
[
|
|
3411
|
+
40,
|
|
3412
|
+
262,
|
|
3413
|
+
10
|
|
3414
|
+
],
|
|
3415
|
+
[
|
|
3416
|
+
118,
|
|
3417
|
+
200,
|
|
3418
|
+
11
|
|
3356
3419
|
]
|
|
3357
3420
|
];
|
|
3358
3421
|
/** Jump ramps, where the rise starts and the unit way up: 16 m long, 5.6 m high (19 degrees), 12 m wide, the lip flat for 4 m (no knife edge under a rover). */
|
|
@@ -3599,7 +3662,7 @@ var DISHES = [
|
|
|
3599
3662
|
[173, 346],
|
|
3600
3663
|
[186, 347]
|
|
3601
3664
|
];
|
|
3602
|
-
var WRECK = [BOWLS[0][0], 140];
|
|
3665
|
+
var WRECK = [BOWLS[0][0] - 4.5, 140];
|
|
3603
3666
|
/** Boulders in the arena's field, red's (x, z, width, depth, height): drawn as rocks round their box. */
|
|
3604
3667
|
var STONES = [
|
|
3605
3668
|
[
|
|
@@ -3647,9 +3710,11 @@ var STONES = [
|
|
|
3647
3710
|
];
|
|
3648
3711
|
/**
|
|
3649
3712
|
* Boulders along the three walls of red's half (x, z, radius), not on the field's first stone
|
|
3650
|
-
* (4..8, 172..176). Each stands in
|
|
3713
|
+
* (4..8, 172..176). Each stands in the boxes of a crag reaching REACH r (the brushes below); one whose box
|
|
3651
3714
|
* would leave a crack a player could not get out of next to an earlier one is left out.
|
|
3652
3715
|
*/
|
|
3716
|
+
/** How far a boulder of radius r reaches from its middle, in r: its boxes' footprint. */
|
|
3717
|
+
var REACH = .85;
|
|
3653
3718
|
var BOULDERS = Array.from({ length: 36 }, (_, i) => {
|
|
3654
3719
|
const h = (k) => hash(i, k, 41);
|
|
3655
3720
|
const b = Math.floor(h(1) * 3);
|
|
@@ -3660,9 +3725,24 @@ var BOULDERS = Array.from({ length: 36 }, (_, i) => {
|
|
|
3660
3725
|
.6 + 2.4 * h(4) * h(4)
|
|
3661
3726
|
];
|
|
3662
3727
|
}).filter(([x, z, r], i, l) => !l.slice(0, i).some(([u, w, q]) => {
|
|
3663
|
-
const gap = Math.max(Math.abs(x - u), Math.abs(z - w)) -
|
|
3728
|
+
const gap = Math.max(Math.abs(x - u), Math.abs(z - w)) - REACH * (r + q);
|
|
3664
3729
|
return gap > 0 && gap < 1;
|
|
3665
3730
|
}));
|
|
3731
|
+
/** What the craters dig and raise at (x, z from the centre line), and how far in a pit's crater it is (1 on its terrace, 0 well clear): the hills fade out there. */
|
|
3732
|
+
var bowls = (x, z) => {
|
|
3733
|
+
let [h, m] = [0, 0];
|
|
3734
|
+
for (const [cx, cz, r, k = .17, flat = 0] of BOWLS) {
|
|
3735
|
+
const d = far(x - cx, z - cz);
|
|
3736
|
+
const [ux, uz] = d ? [(x - cx) / d, (z - cz) / d] : [1, 0];
|
|
3737
|
+
const q = d / r * (.9 + .2 * noise(2.5 * ux + .37 * cx, 2.5 * uz + .21 * cz, 9));
|
|
3738
|
+
const rim = .03 + .045 * noise(4 * ux - .1 * cz, 4 * uz + .1 * cx, 10);
|
|
3739
|
+
const s = 1 - c1((q - 1 - 4 / r) / .6);
|
|
3740
|
+
const wall = flat ? (k + rim) * c1((q - flat) / (1 - flat)) - k : (k + rim) * q * q - k;
|
|
3741
|
+
h += r * (q < 1 ? wall : rim * s * s);
|
|
3742
|
+
m = Math.max(m, flat ? c1((1.6 - q) / (1.5 - flat)) : 0);
|
|
3743
|
+
}
|
|
3744
|
+
return [h, m];
|
|
3745
|
+
};
|
|
3666
3746
|
/**
|
|
3667
3747
|
* How much of a mound's height there is at x, across it: all of it for 4 m each side of its
|
|
3668
3748
|
* middle cx, none 8 m further, and none over the spurs that close the rille's east end. Straight
|
|
@@ -3685,6 +3765,7 @@ var at$1 = (x, z) => {
|
|
|
3685
3765
|
z = Math.abs(z - 140);
|
|
3686
3766
|
const k = far((x - 80) / 300, z / 360);
|
|
3687
3767
|
const t = Math.max((k - .78) / .22, 0);
|
|
3768
|
+
const dug = bowls(x, z);
|
|
3688
3769
|
const out = Math.max(Math.abs(x - 80) - 80, z - 140);
|
|
3689
3770
|
let h = sm((out - 12) / 48) * (1 - .7 * sm(t)) * (16 * noise(x / 96, z / 96, 1) + 6 * noise(x / 52, z / 52, 4) + 5 * noise(x / 36, z / 36, 2) + 1.4 * noise(x / 22, z / 22, 3) - 14.2);
|
|
3690
3771
|
if (out < 0) {
|
|
@@ -3696,11 +3777,7 @@ var at$1 = (x, z) => {
|
|
|
3696
3777
|
for (const cx of MOUNDS) h += MOUND * c1((8 + RISE - z) / RISE) * across(cx, x);
|
|
3697
3778
|
h = z < 8 ? 0 : h;
|
|
3698
3779
|
}
|
|
3699
|
-
|
|
3700
|
-
const q = far(x - cx, z - cz) / r;
|
|
3701
|
-
const s = 1 - c1((q - 1 - 4 / r) / .6);
|
|
3702
|
-
h += r * (q < 1 ? .25 * q * q - .19 : .06 * s * s);
|
|
3703
|
-
}
|
|
3780
|
+
h = (out < 0 ? h : h * (1 - dug[1])) + dug[0];
|
|
3704
3781
|
for (const [rx, rz, ax, az] of RAMPS) {
|
|
3705
3782
|
const [p, q] = [x - rx, z - rz];
|
|
3706
3783
|
const a = p * ax + q * az;
|
|
@@ -3712,6 +3789,282 @@ var at$1 = (x, z) => {
|
|
|
3712
3789
|
if (k > 1) w = (w + (k - 1) * 60 * (Math.abs(2 * noise(x / 45, z / 45, 5) - 1) - .5)) * (1 + (k - 1) * (1.2 * noise(x / 90, z / 90, 7) - .6)) * (1 - sm((k - 1.25) / .4));
|
|
3713
3790
|
return Math.max(h, -14.5) + w;
|
|
3714
3791
|
};
|
|
3792
|
+
/** Five bearings a fifth of a turn apart, as unit vectors: no Math.cos in what the host and the clients must agree on. */
|
|
3793
|
+
var FIFTHS = [
|
|
3794
|
+
[1, 0],
|
|
3795
|
+
[.309, .951],
|
|
3796
|
+
[-.809, .588],
|
|
3797
|
+
[-.809, -.588],
|
|
3798
|
+
[.309, -.951]
|
|
3799
|
+
];
|
|
3800
|
+
/**
|
|
3801
|
+
* The form of a boulder of radius R and height H from a seed: how far it reaches from its middle
|
|
3802
|
+
* (a quarter of its height over the ground) along a unit vector. One to three lobes, each a block
|
|
3803
|
+
* cut by five leaning planes round it and a nearly level one on top, its corners rounded by an
|
|
3804
|
+
* ellipsoid: a main mass, a shoulder beside it half as high from 1.3 m of radius, a low one from
|
|
3805
|
+
* 3.2 m. One plane cuts under a side (an overhang), and the whole swells and shrinks by 6 % with
|
|
3806
|
+
* the bearing. Only + - * /, Math.sqrt and the hash: the boxes below come from it on every side.
|
|
3807
|
+
* `tops` are the lobes' middles (x, z) and the height of their top over the rock's middle.
|
|
3808
|
+
*/
|
|
3809
|
+
var rockOf = (s, R, H) => {
|
|
3810
|
+
const h = (k) => hash(s, k, 131);
|
|
3811
|
+
const flat = (k) => {
|
|
3812
|
+
const [a, b] = [2 * h(k) - 1, 2 * h(k + 1) - 1];
|
|
3813
|
+
const l = Math.sqrt(a * a + b * b) || 1;
|
|
3814
|
+
return [a / l, b / l];
|
|
3815
|
+
};
|
|
3816
|
+
const lobes = [
|
|
3817
|
+
0,
|
|
3818
|
+
1,
|
|
3819
|
+
2
|
|
3820
|
+
].slice(0, R < 1.3 ? 1 : R < 3.2 ? 2 : 3).map((k) => {
|
|
3821
|
+
const [fx, fz] = flat(20 * k + 1);
|
|
3822
|
+
const [off, rad] = [[
|
|
3823
|
+
.1,
|
|
3824
|
+
.45,
|
|
3825
|
+
.42
|
|
3826
|
+
][k] * R, [
|
|
3827
|
+
.8,
|
|
3828
|
+
.75,
|
|
3829
|
+
.65
|
|
3830
|
+
][k] * R];
|
|
3831
|
+
const o = [fx * off, fz * off];
|
|
3832
|
+
const top = [
|
|
3833
|
+
H,
|
|
3834
|
+
(.5 + .15 * h(20 * k + 3)) * H,
|
|
3835
|
+
.34 * H
|
|
3836
|
+
][k] - .25 * H;
|
|
3837
|
+
const tilt = Math.min(.06, .06 / rad);
|
|
3838
|
+
const [tx, tz] = [(2 * h(20 * k + 4) - 1) * tilt, (2 * h(20 * k + 5) - 1) * tilt];
|
|
3839
|
+
const tl = Math.sqrt(tx * tx + 1 + tz * tz);
|
|
3840
|
+
return {
|
|
3841
|
+
o,
|
|
3842
|
+
rad,
|
|
3843
|
+
top,
|
|
3844
|
+
planes: [[
|
|
3845
|
+
tx / tl,
|
|
3846
|
+
1 / tl,
|
|
3847
|
+
tz / tl,
|
|
3848
|
+
(tx * o[0] + top + tz * o[1]) / tl
|
|
3849
|
+
], ...FIFTHS.map(([px, pz], j) => {
|
|
3850
|
+
const [ax, az] = [px + h(20 * k + 6 + j) - .5, pz + h(20 * k + 11 + j) - .5];
|
|
3851
|
+
const l = Math.sqrt(ax * ax + az * az);
|
|
3852
|
+
const y = -.15 + .5 * h(20 * k + 16 + j);
|
|
3853
|
+
const c = Math.sqrt(1 - y * y);
|
|
3854
|
+
const [nx, nz] = [c * ax / l, c * az / l];
|
|
3855
|
+
return [
|
|
3856
|
+
nx,
|
|
3857
|
+
y,
|
|
3858
|
+
nz,
|
|
3859
|
+
nx * o[0] + nz * o[1] + rad * (.72 + .22 * h(20 * k + 21 + j))
|
|
3860
|
+
];
|
|
3861
|
+
})]
|
|
3862
|
+
};
|
|
3863
|
+
});
|
|
3864
|
+
const [ux, uz] = flat(91);
|
|
3865
|
+
const under = [
|
|
3866
|
+
.866 * ux,
|
|
3867
|
+
-.5,
|
|
3868
|
+
.866 * uz,
|
|
3869
|
+
.72 * R
|
|
3870
|
+
];
|
|
3871
|
+
const reach = (u) => {
|
|
3872
|
+
let far = 0;
|
|
3873
|
+
for (const { o, rad, planes } of lobes) {
|
|
3874
|
+
const [a, c] = [1.2 * rad, 1.15 * H];
|
|
3875
|
+
const A = (u[0] * u[0] + u[2] * u[2]) / (a * a) + u[1] * u[1] / (c * c);
|
|
3876
|
+
const B = -2 * (u[0] * o[0] + u[2] * o[1]) / (a * a);
|
|
3877
|
+
const C = (o[0] * o[0] + o[1] * o[1]) / (a * a) - 1;
|
|
3878
|
+
let t = (-B + Math.sqrt(B * B - 4 * A * C)) / (2 * A);
|
|
3879
|
+
for (const [nx, ny, nz, d] of [...planes, under]) {
|
|
3880
|
+
const k = u[0] * nx + u[1] * ny + u[2] * nz;
|
|
3881
|
+
t = k > 1e-9 ? Math.min(t, d / k) : t;
|
|
3882
|
+
}
|
|
3883
|
+
far = Math.max(far, t);
|
|
3884
|
+
}
|
|
3885
|
+
return far * (.94 + .12 * noise(1.5 * u[0] + s, 1.5 * u[2] + 2 * u[1], s));
|
|
3886
|
+
};
|
|
3887
|
+
return {
|
|
3888
|
+
reach,
|
|
3889
|
+
tops: lobes.map(({ o, top }) => [
|
|
3890
|
+
o[0],
|
|
3891
|
+
o[1],
|
|
3892
|
+
top
|
|
3893
|
+
])
|
|
3894
|
+
};
|
|
3895
|
+
};
|
|
3896
|
+
/**
|
|
3897
|
+
* The boxes inside a boulder, one for each lobe, each x0, y0, z0, x1, y1, z1 round its middle
|
|
3898
|
+
* (y from the middle's height): the widest box under the lobe's top, standing from `foot` under
|
|
3899
|
+
* the middle, whose corners and the middles of its sides are all in the rock at its foot, half
|
|
3900
|
+
* way up and on top. A body is stopped a little inside what is drawn, never outside it.
|
|
3901
|
+
*/
|
|
3902
|
+
var inside = ({ reach, tops }, R, foot) => {
|
|
3903
|
+
const holds = (x, y, z, slack = .09) => {
|
|
3904
|
+
const l = Math.sqrt(x * x + y * y + z * z);
|
|
3905
|
+
return l < 1e-6 || l <= reach([
|
|
3906
|
+
x / l,
|
|
3907
|
+
y / l,
|
|
3908
|
+
z / l
|
|
3909
|
+
]) + slack;
|
|
3910
|
+
};
|
|
3911
|
+
const grid = [
|
|
3912
|
+
-1,
|
|
3913
|
+
0,
|
|
3914
|
+
1
|
|
3915
|
+
];
|
|
3916
|
+
/** A box of half sides p and q round (cx, cz) from the foot up to t: in the rock at its foot, half way up and on top, and with no rock 0.2 m over its top (what stands on it is not in the rock). */
|
|
3917
|
+
const fits = (cx, cz, p, q, t) => [
|
|
3918
|
+
foot + .05,
|
|
3919
|
+
(foot + t) / 2,
|
|
3920
|
+
t
|
|
3921
|
+
].every((y) => grid.every((i) => grid.every((j) => holds(cx + i * p, y, cz + j * q)))) && grid.every((i) => grid.every((j) => !holds(cx + i * p, t + .2, cz + j * q, 0)));
|
|
3922
|
+
return tops.flatMap(([ox, oz, top], k) => {
|
|
3923
|
+
let best = [
|
|
3924
|
+
0,
|
|
3925
|
+
0,
|
|
3926
|
+
0,
|
|
3927
|
+
0,
|
|
3928
|
+
0,
|
|
3929
|
+
0
|
|
3930
|
+
];
|
|
3931
|
+
const l = Math.sqrt(ox * ox + oz * oz) || 1;
|
|
3932
|
+
for (const a of k ? [
|
|
3933
|
+
.1,
|
|
3934
|
+
.3,
|
|
3935
|
+
.5
|
|
3936
|
+
] : [
|
|
3937
|
+
-.15,
|
|
3938
|
+
0,
|
|
3939
|
+
.15
|
|
3940
|
+
]) for (const b of [
|
|
3941
|
+
-.15,
|
|
3942
|
+
0,
|
|
3943
|
+
.15
|
|
3944
|
+
]) {
|
|
3945
|
+
const [cx, cz] = k ? [ox + (a * ox - b * oz) * (R / l), oz + (a * oz + b * ox) * (R / l)] : [ox + a * R, oz + b * R];
|
|
3946
|
+
let t = 0;
|
|
3947
|
+
for (let y = top + .1; !t && y > foot + .3; y -= .1) t = fits(cx, cz, .08 * R, .08 * R, y) ? y : 0;
|
|
3948
|
+
let [p, q] = [.08 * R, .08 * R];
|
|
3949
|
+
for (const [fa, fb] of t ? [
|
|
3950
|
+
[1, 1],
|
|
3951
|
+
[1, 0],
|
|
3952
|
+
[0, 1]
|
|
3953
|
+
] : []) for (let step = .5 * R; step > .03; step /= 2) [p, q] = fits(cx, cz, p + fa * step, q + fb * step, t) ? [p + fa * step, q + fb * step] : [p, q];
|
|
3954
|
+
if (t && p * q * (t - foot) > best[0]) best = [
|
|
3955
|
+
p * q * (t - foot),
|
|
3956
|
+
cx,
|
|
3957
|
+
cz,
|
|
3958
|
+
p,
|
|
3959
|
+
q,
|
|
3960
|
+
t
|
|
3961
|
+
];
|
|
3962
|
+
}
|
|
3963
|
+
const [, cx, cz, p, q, t] = best;
|
|
3964
|
+
return Math.min(p, q) < (k ? .25 : 0) ? [] : [[
|
|
3965
|
+
cx - p,
|
|
3966
|
+
foot,
|
|
3967
|
+
cz - q,
|
|
3968
|
+
cx + p,
|
|
3969
|
+
t,
|
|
3970
|
+
cz + q
|
|
3971
|
+
]];
|
|
3972
|
+
});
|
|
3973
|
+
};
|
|
3974
|
+
/** A rock of the map: where its middle is over the ground (x, the ground's height, z), its radius, height and seed, and the boxes it collides with (x0, y0, z0, x1, y1, z1), inside what rockOf() draws. */
|
|
3975
|
+
var crag = (x, z, R, H, s, deep = 0) => {
|
|
3976
|
+
const g = at$1(x, z);
|
|
3977
|
+
const y = g + .25 * H;
|
|
3978
|
+
return {
|
|
3979
|
+
at: [
|
|
3980
|
+
x,
|
|
3981
|
+
g,
|
|
3982
|
+
z
|
|
3983
|
+
],
|
|
3984
|
+
R,
|
|
3985
|
+
H,
|
|
3986
|
+
s,
|
|
3987
|
+
parts: inside(rockOf(s, R, H), R, -.25 * H).filter((b, k, l) => {
|
|
3988
|
+
const gap = Math.max(b[0] - l[0][3], l[0][0] - b[3], b[2] - l[0][5], l[0][2] - b[5]);
|
|
3989
|
+
return !k || gap <= 0 || gap > 1.2;
|
|
3990
|
+
}).map(([x0, , z0, x1, y1, z1]) => [
|
|
3991
|
+
x + x0,
|
|
3992
|
+
deep,
|
|
3993
|
+
z + z0,
|
|
3994
|
+
x + x1,
|
|
3995
|
+
y + y1,
|
|
3996
|
+
z + z1
|
|
3997
|
+
])
|
|
3998
|
+
};
|
|
3999
|
+
};
|
|
4000
|
+
/** Red's rocks: in the arena the field's stones (as wide as their old box was long, a fifth higher) and the boulders along the walls, then the boulder field's. */
|
|
4001
|
+
var CRAGS = {
|
|
4002
|
+
arena: [...STONES.map(([x, z, w, d, h], i) => crag(x + w / 2, z + d / 2, .31 * (w + d), 1.15 * h, i + 61)), ...BOULDERS.map(([x, z, r], i) => crag(x, z, r, .8 * r, i))],
|
|
4003
|
+
field: FIELD.map(([x, z, r], i) => crag(x, z, r, .75 * r, i + 100, at$1(x, z) - 6))
|
|
4004
|
+
};
|
|
4005
|
+
var ghosts = (l) => l.flatMap((c) => c.parts).map(([x0, y0, z0, x1, y1, z1]) => ({
|
|
4006
|
+
...box(x0, y0, z0, x1, y1, z1, STONE),
|
|
4007
|
+
ghost: true
|
|
4008
|
+
}));
|
|
4009
|
+
/** A pit: PIT_R in radius, cut in a square of half side PIT_S of its crater's terrace, its floor at PIT_FLOOR, 7 m over the kill floor; a flight of PIT_STEPS steps up its east wall. */
|
|
4010
|
+
var [PIT_R, PIT_S, PIT_FLOOR, PIT_STEPS] = [
|
|
4011
|
+
9,
|
|
4012
|
+
12,
|
|
4013
|
+
-19,
|
|
4014
|
+
7
|
|
4015
|
+
];
|
|
4016
|
+
/**
|
|
4017
|
+
* The pits of red's side and of the centre line (the Bowl's): the middle, the terrace's level and
|
|
4018
|
+
* the rows, a metre of z each: z0, z1 and how far the void goes west and east of the middle. A
|
|
4019
|
+
* circle that wanders by 12 % with z, the same north and south of the middle, rounded up to half
|
|
4020
|
+
* a metre: the void is never narrower than the outline the scenery draws.
|
|
4021
|
+
*/
|
|
4022
|
+
var PITS = BOWLS.filter((b) => b[4]).map(([x, zf], n) => {
|
|
4023
|
+
const z = 140 + zf;
|
|
4024
|
+
const rows = Array.from({ length: 2 * PIT_R }, (_, i) => {
|
|
4025
|
+
const dz = Math.abs(i + .5 - PIT_R);
|
|
4026
|
+
const half = Math.sqrt(PIT_R * PIT_R - dz * dz);
|
|
4027
|
+
const w = (side) => Math.ceil(2 * half * (.88 + .24 * noise(dz / 4, side + .5, 60 + n))) / 2;
|
|
4028
|
+
return [
|
|
4029
|
+
z - PIT_R + i,
|
|
4030
|
+
z - PIT_R + i + 1,
|
|
4031
|
+
w(0),
|
|
4032
|
+
w(1)
|
|
4033
|
+
];
|
|
4034
|
+
});
|
|
4035
|
+
return {
|
|
4036
|
+
x,
|
|
4037
|
+
z,
|
|
4038
|
+
level: at$1(x, z),
|
|
4039
|
+
rows
|
|
4040
|
+
};
|
|
4041
|
+
});
|
|
4042
|
+
/** What a pit collides with: its square of terrace in pieces round the void (two caps and, for each run of rows of one width, a box each side), its floor, and the steps: each as high again as a body jumps at half gravity, 1.3 m deep, up to the terrace at the east wall. */
|
|
4043
|
+
var pit = ({ x, z, level, rows }) => {
|
|
4044
|
+
const runs = rows.reduce((l, [z0, z1, a, b]) => {
|
|
4045
|
+
const last = l.at(-1);
|
|
4046
|
+
if (last && last[2] === a && last[3] === b) last[1] = z1;
|
|
4047
|
+
else l.push([
|
|
4048
|
+
z0,
|
|
4049
|
+
z1,
|
|
4050
|
+
a,
|
|
4051
|
+
b
|
|
4052
|
+
]);
|
|
4053
|
+
return l;
|
|
4054
|
+
}, []);
|
|
4055
|
+
const east = rows[PIT_R][3];
|
|
4056
|
+
const rise = (level - PIT_FLOOR) / PIT_STEPS;
|
|
4057
|
+
return [
|
|
4058
|
+
box(x - PIT_S, -30, z - PIT_S, x + PIT_S, level, z - PIT_R, STONE),
|
|
4059
|
+
box(x - PIT_S, -30, z + PIT_R, x + PIT_S, level, z + PIT_S, STONE),
|
|
4060
|
+
...runs.flatMap(([z0, z1, a, b]) => [box(x - PIT_S, -30, z0, x - a, level, z1, STONE), box(x + b, -30, z0, x + PIT_S, level, z1, STONE)]),
|
|
4061
|
+
box(x - PIT_R - 1.5, -30, z - PIT_R, x + PIT_R + 1.5, PIT_FLOOR, z + PIT_R, STONE),
|
|
4062
|
+
...Array.from({ length: PIT_STEPS - 1 }, (_, k) => box(x + east - 1.3 * (PIT_STEPS - 1 - k), PIT_FLOOR, z - 1, x + east - 1.3 * (PIT_STEPS - 2 - k), PIT_FLOOR + rise * (k + 1), z + 1, STONE))
|
|
4063
|
+
].map((b) => ({
|
|
4064
|
+
...b,
|
|
4065
|
+
ghost: true
|
|
4066
|
+
}));
|
|
4067
|
+
};
|
|
3715
4068
|
/** The ghost under a drawn rock or mast: a box of half side s from under the ground to h above it. */
|
|
3716
4069
|
var lump = (x, z, s, h) => ({
|
|
3717
4070
|
...box(x - s, at$1(x, z) - 6, z - s, x + s, at$1(x, z) + h, z + s, STONE),
|
|
@@ -3732,8 +4085,28 @@ var LAYOUT = {
|
|
|
3732
4085
|
m * az + 0
|
|
3733
4086
|
])),
|
|
3734
4087
|
wreck: WRECK,
|
|
4088
|
+
/** The pits, both sides: the middle, the terrace's level and the rows (z0, z1, the void's reach west and east). */
|
|
4089
|
+
pits: PITS.flatMap((p) => p.z === 140 ? [p] : [p, {
|
|
4090
|
+
...p,
|
|
4091
|
+
z: 280 - p.z,
|
|
4092
|
+
rows: p.rows.map(([z0, z1, a, b]) => [
|
|
4093
|
+
280 - z1,
|
|
4094
|
+
280 - z0,
|
|
4095
|
+
a,
|
|
4096
|
+
b
|
|
4097
|
+
]).reverse()
|
|
4098
|
+
}]),
|
|
3735
4099
|
/** Red's boulders along its walls and the field's stones; blue's are their mirrors, drawn by the scenery's flip. */
|
|
4100
|
+
/** The craters of the relief, both sides: x, z, radius, depth as a share of it. */
|
|
4101
|
+
bowls: BOWLS.flatMap(([x, z, r, k = .17]) => (z ? [1, -1] : [1]).map((m) => [
|
|
4102
|
+
x,
|
|
4103
|
+
140 + m * z,
|
|
4104
|
+
r,
|
|
4105
|
+
k
|
|
4106
|
+
])),
|
|
3736
4107
|
boulders: BOULDERS,
|
|
4108
|
+
/** Red's rocks, in the arena and in the boulder field: blue's are their mirrors. */
|
|
4109
|
+
crags: CRAGS,
|
|
3737
4110
|
stones: STONES,
|
|
3738
4111
|
pillars: PILLARS,
|
|
3739
4112
|
domes: [DOME, [DOME[0], 280 - DOME[1]]],
|
|
@@ -3839,15 +4212,9 @@ var half = [
|
|
|
3839
4212
|
.42,
|
|
3840
4213
|
.08
|
|
3841
4214
|
]),
|
|
3842
|
-
...
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
})),
|
|
3846
|
-
...BOULDERS.map(([x, z, r]) => ({
|
|
3847
|
-
...box(x - .6 * r, 0, z - .6 * r, x + .6 * r, at$1(x, z) + .75 * r, z + .6 * r, STONE),
|
|
3848
|
-
ghost: true
|
|
3849
|
-
})),
|
|
3850
|
-
...FIELD.map(([x, z, r]) => lump(x, z, .6 * r, .6 * r)),
|
|
4215
|
+
...PITS.filter((p) => p.z !== 140).flatMap(pit),
|
|
4216
|
+
...ghosts(CRAGS.arena),
|
|
4217
|
+
...ghosts(CRAGS.field),
|
|
3851
4218
|
...DISHES.map(([x, z]) => lump(x, z, .4, 6))
|
|
3852
4219
|
];
|
|
3853
4220
|
/** What stands on the centre line, symmetric as written: the bridge, the stones, the rille's plugs and the wreck. */
|
|
@@ -3867,7 +4234,11 @@ var centre = [
|
|
|
3867
4234
|
...box(160, -30, 132, 170, 0, 148, STONE),
|
|
3868
4235
|
ghost: true
|
|
3869
4236
|
},
|
|
3870
|
-
|
|
4237
|
+
{
|
|
4238
|
+
...box(WRECK[0] - 3.6, -30, WRECK[1] - 3.6, WRECK[0] + 3.6, PIT_FLOOR + 3.5, WRECK[1] + 3.6, STONE),
|
|
4239
|
+
ghost: true
|
|
4240
|
+
},
|
|
4241
|
+
...PITS.filter((p) => p.z === 140).flatMap(pit),
|
|
3871
4242
|
...LAYOUT.ramps.flatMap(([x, z, ax, az]) => [-8, 8].map((c) => lump(x + c * az, z - c * ax, .2, 2.2)))
|
|
3872
4243
|
];
|
|
3873
4244
|
/** Red's spawns behind the dome facing blue (yaw 0 looks toward -z): five in a row, three in front. */
|
|
@@ -3996,7 +4367,7 @@ var MAPS = {
|
|
|
3996
4367
|
0,
|
|
3997
4368
|
140
|
|
3998
4369
|
]),
|
|
3999
|
-
floor: -
|
|
4370
|
+
floor: -26,
|
|
4000
4371
|
relief: {
|
|
4001
4372
|
hole: [
|
|
4002
4373
|
0,
|
|
@@ -4004,7 +4375,7 @@ var MAPS = {
|
|
|
4004
4375
|
160,
|
|
4005
4376
|
148
|
|
4006
4377
|
],
|
|
4007
|
-
pits: RUNS.flatMap(([x, w, n]) => n > 0 ? [[
|
|
4378
|
+
pits: [...RUNS.flatMap(([x, w, n]) => n > 0 ? [[
|
|
4008
4379
|
x,
|
|
4009
4380
|
148,
|
|
4010
4381
|
x + w,
|
|
@@ -4014,7 +4385,12 @@ var MAPS = {
|
|
|
4014
4385
|
132 - n,
|
|
4015
4386
|
x + w,
|
|
4016
4387
|
132
|
|
4017
|
-
]] : []),
|
|
4388
|
+
]] : []), ...LAYOUT.pits.flatMap(({ x, rows }) => rows.map(([z0, z1, a, b]) => [
|
|
4389
|
+
x - a,
|
|
4390
|
+
z0,
|
|
4391
|
+
x + b,
|
|
4392
|
+
z1
|
|
4393
|
+
]))],
|
|
4018
4394
|
bound: [
|
|
4019
4395
|
80,
|
|
4020
4396
|
140,
|
|
@@ -33,14 +33,56 @@ export declare const MOUND: number, RISE: number;
|
|
|
33
33
|
* starts 12 m behind them.
|
|
34
34
|
*/
|
|
35
35
|
export declare const FLATS: number[][];
|
|
36
|
+
type V3 = [number, number, number];
|
|
37
|
+
/**
|
|
38
|
+
* The form of a boulder of radius R and height H from a seed: how far it reaches from its middle
|
|
39
|
+
* (a quarter of its height over the ground) along a unit vector. One to three lobes, each a block
|
|
40
|
+
* cut by five leaning planes round it and a nearly level one on top, its corners rounded by an
|
|
41
|
+
* ellipsoid: a main mass, a shoulder beside it half as high from 1.3 m of radius, a low one from
|
|
42
|
+
* 3.2 m. One plane cuts under a side (an overhang), and the whole swells and shrinks by 6 % with
|
|
43
|
+
* the bearing. Only + - * /, Math.sqrt and the hash: the boxes below come from it on every side.
|
|
44
|
+
* `tops` are the lobes' middles (x, z) and the height of their top over the rock's middle.
|
|
45
|
+
*/
|
|
46
|
+
export declare const rockOf: (s: number, R: number, H: number) => {
|
|
47
|
+
reach: (u: V3) => number;
|
|
48
|
+
tops: number[][];
|
|
49
|
+
};
|
|
50
|
+
/** A pit: PIT_R in radius, cut in a square of half side PIT_S of its crater's terrace, its floor at PIT_FLOOR, 7 m over the kill floor; a flight of PIT_STEPS steps up its east wall. */
|
|
51
|
+
export declare const PIT_R: number, PIT_S: number, PIT_FLOOR: number, PIT_STEPS: number;
|
|
36
52
|
export declare const LAYOUT: {
|
|
37
53
|
/** Outside the arena: the boulders (x, z, radius), the dishes, the ramps (the middle of the lip and the unit way up it), the wreck. */
|
|
38
54
|
rocks: number[][];
|
|
39
55
|
dishes: number[][];
|
|
40
56
|
ramps: number[][];
|
|
41
57
|
wreck: number[];
|
|
58
|
+
/** The pits, both sides: the middle, the terrace's level and the rows (z0, z1, the void's reach west and east). */
|
|
59
|
+
pits: {
|
|
60
|
+
x: number;
|
|
61
|
+
z: number;
|
|
62
|
+
level: number;
|
|
63
|
+
rows: number[][];
|
|
64
|
+
}[];
|
|
42
65
|
/** Red's boulders along its walls and the field's stones; blue's are their mirrors, drawn by the scenery's flip. */
|
|
66
|
+
/** The craters of the relief, both sides: x, z, radius, depth as a share of it. */
|
|
67
|
+
bowls: number[][];
|
|
43
68
|
boulders: number[][];
|
|
69
|
+
/** Red's rocks, in the arena and in the boulder field: blue's are their mirrors. */
|
|
70
|
+
crags: {
|
|
71
|
+
arena: {
|
|
72
|
+
at: number[];
|
|
73
|
+
R: number;
|
|
74
|
+
H: number;
|
|
75
|
+
s: number;
|
|
76
|
+
parts: number[][];
|
|
77
|
+
}[];
|
|
78
|
+
field: {
|
|
79
|
+
at: number[];
|
|
80
|
+
R: number;
|
|
81
|
+
H: number;
|
|
82
|
+
s: number;
|
|
83
|
+
parts: number[][];
|
|
84
|
+
}[];
|
|
85
|
+
};
|
|
44
86
|
stones: number[][];
|
|
45
87
|
pillars: number[][];
|
|
46
88
|
domes: number[][];
|
|
@@ -51,3 +93,4 @@ export declare const LAYOUT: {
|
|
|
51
93
|
masts: number[][];
|
|
52
94
|
};
|
|
53
95
|
export declare const MOON: WorldDef;
|
|
96
|
+
export {};
|
|
@@ -28,6 +28,8 @@ export interface Relief {
|
|
|
28
28
|
/** The definition's pits and the box round them all (none: an empty box). */
|
|
29
29
|
pits: Quad[];
|
|
30
30
|
box: Quad;
|
|
31
|
+
/** 1 for each lattice square a pit touches or is next to, by its low node. */
|
|
32
|
+
pitted: Uint8Array;
|
|
31
33
|
bound: Quad;
|
|
32
34
|
/** The highest node: a ray above it meets no ground. */
|
|
33
35
|
top: number;
|
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.110.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|