@korial29/tiny-fps 0.119.0 → 0.121.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 +218 -171
- package/dist/types/client/moonscape.d.ts +10 -0
- package/dist/types/shared/moon.d.ts +7 -7
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -7,6 +7,8 @@ var PLAYER_H = 1.8;
|
|
|
7
7
|
var EYE = 1.6;
|
|
8
8
|
/** Pitch is clamped to ±MAX_PITCH radians, just short of straight up or down. */
|
|
9
9
|
var MAX_PITCH = 1.55;
|
|
10
|
+
/** A floor at most this much higher is walked onto; a higher one needs a jump. */
|
|
11
|
+
var STEP_H = .5;
|
|
10
12
|
/** Height of the cylinder when sliding or crouching, and the eye in it. */
|
|
11
13
|
var LOW_H = .9;
|
|
12
14
|
var LOW_EYE = .7;
|
|
@@ -3115,7 +3117,7 @@ var stairs = (axis, a, b, w0, w1, y, top) => {
|
|
|
3115
3117
|
* The mezzanine 3.5 m up along the walls (not over the door), the stairs up to it facing the door,
|
|
3116
3118
|
* a console and two parapets on it, three crates on the floor clear of the flag's dais (moon.ts).
|
|
3117
3119
|
*/
|
|
3118
|
-
var FIT = [
|
|
3120
|
+
var FIT$1 = [
|
|
3119
3121
|
...turns([[
|
|
3120
3122
|
12,
|
|
3121
3123
|
-D1,
|
|
@@ -3363,7 +3365,7 @@ var BASE = [
|
|
|
3363
3365
|
TZ0 - DOME[1]
|
|
3364
3366
|
]
|
|
3365
3367
|
].map((p) => ghost(p, 0, BANDS[1])),
|
|
3366
|
-
...FIT,
|
|
3368
|
+
...FIT$1,
|
|
3367
3369
|
...KIT.map(([, x0, z0, x1, z1, y0, y1]) => ({
|
|
3368
3370
|
...box(x0, y0, z0, x1, y1, z1, STEEL$1),
|
|
3369
3371
|
ghost: true
|
|
@@ -3839,8 +3841,8 @@ var across = (cx, x) => {
|
|
|
3839
3841
|
* and the integer hash: every engine builds the same lattice. In the arena, the field (see FLATS)
|
|
3840
3842
|
* and the mounds; exactly 0 for 12 m round it (a rectangle on lattice lines, so between the nodes
|
|
3841
3843
|
* too); then rolling hills, the pieces above, then the crater wall: it starts 0.78 of the way to the bound,
|
|
3842
|
-
* is 20 m high on it and, past it where nobody goes,
|
|
3843
|
-
* falls to the plain at 1.65 of the bound.
|
|
3844
|
+
* is 20 m high on it and, past it where nobody goes, rounds off under a crest of 28 to 48 m that
|
|
3845
|
+
* rolls slowly and falls to the plain at 1.65 of the bound. Lower than the ranges drawn far behind it.
|
|
3844
3846
|
*/
|
|
3845
3847
|
var at$1 = (x, z) => {
|
|
3846
3848
|
z = Math.abs(z - 140);
|
|
@@ -3867,25 +3869,22 @@ var at$1 = (x, z) => {
|
|
|
3867
3869
|
const d = c1(far(x - RIDGE[0], Math.max(z - RIDGE[1], 0)) / 36);
|
|
3868
3870
|
h += 12 * (1 - d * d) * (1 - d * d) + 8 * sm((36 - far(x - HILL[0], z - HILL[1])) / 24);
|
|
3869
3871
|
let w = 10 * t * (1 + t);
|
|
3870
|
-
if (k > 1)
|
|
3872
|
+
if (k > 1) {
|
|
3873
|
+
const crest = 28 + 14 * noise(x / 170, z / 170, 5) + 6 * noise(x / 70, z / 70, 7);
|
|
3874
|
+
const soft = 10 * sm((k - 1) / .1);
|
|
3875
|
+
w = (w + crest - Math.sqrt((w - crest) * (w - crest) + soft * soft)) / 2 * (1 - sm((k - 1.3) / .35));
|
|
3876
|
+
}
|
|
3871
3877
|
return Math.max(h, -14.5) + w;
|
|
3872
3878
|
};
|
|
3873
|
-
/**
|
|
3874
|
-
var
|
|
3875
|
-
[1, 0],
|
|
3876
|
-
[.309, .951],
|
|
3877
|
-
[-.809, .588],
|
|
3878
|
-
[-.809, -.588],
|
|
3879
|
-
[.309, -.951]
|
|
3880
|
-
];
|
|
3879
|
+
/** How high a rock's middle is over the ground: three tenths of its height, and 0.6 m or half its height if less. Its widest is there, its flank steep down to the ground: a body is stopped at its foot. */
|
|
3880
|
+
var rockMid = (H) => Math.max(.3 * H, Math.min(.5 * H, .8));
|
|
3881
3881
|
/**
|
|
3882
3882
|
* The form of a boulder of radius R and height H from a seed: how far it reaches from its middle
|
|
3883
|
-
* (
|
|
3884
|
-
*
|
|
3885
|
-
*
|
|
3886
|
-
*
|
|
3887
|
-
*
|
|
3888
|
-
* `tops` are the lobes' middles (x, z) and the height of their top over the rock's middle.
|
|
3883
|
+
* (rockMid() over the ground) along a unit vector. A rounded solid, no plane in it:
|
|
3884
|
+
* an ellipsoid stretched unevenly on its three axes and turned by the seed, upright under its
|
|
3885
|
+
* middle (it stands in the regolith, as wide at the ground as at its middle) and a dome over it, swollen and shrunk by two low octaves
|
|
3886
|
+
* of noise with the bearing (large soft lobes), with one gentle hollow and one flatter side. Only
|
|
3887
|
+
* + - * /, Math.sqrt and the hash: the boxes below come from it on every side.
|
|
3889
3888
|
*/
|
|
3890
3889
|
var rockOf = (s, R, H) => {
|
|
3891
3890
|
const h = (k) => hash(s, k, 131);
|
|
@@ -3894,168 +3893,219 @@ var rockOf = (s, R, H) => {
|
|
|
3894
3893
|
const l = Math.sqrt(a * a + b * b) || 1;
|
|
3895
3894
|
return [a / l, b / l];
|
|
3896
3895
|
};
|
|
3897
|
-
const
|
|
3896
|
+
const [cx, sx] = flat(1);
|
|
3897
|
+
const [a, b] = [R * (.9 + .25 * h(3)), R * (.68 + .22 * h(4))];
|
|
3898
|
+
const lean = .3 * h(9) - .15;
|
|
3899
|
+
const [hx, hz] = flat(5);
|
|
3900
|
+
const [fx, fz] = flat(7);
|
|
3901
|
+
const swell = (u) => {
|
|
3902
|
+
const n = .8 + .28 * noise(1.1 * u[0] + s, 1.1 * u[2] + .9 * u[1], s) + .1 * noise(2.3 * u[0] - s, 2.3 * u[2] + 1.7 * u[1], s + 1);
|
|
3903
|
+
const hollow = c1((.8 * (u[0] * hx + u[2] * hz) + .6 * u[1] - .55) / .45);
|
|
3904
|
+
const side = c1((.954 * (u[0] * fx + u[2] * fz) + .3 * u[1] - .4) / .6);
|
|
3905
|
+
return n * (1 - .14 * hollow * hollow) * (1 - .16 * side * side);
|
|
3906
|
+
};
|
|
3907
|
+
const cu = (H - rockMid(H)) / swell([
|
|
3898
3908
|
0,
|
|
3899
3909
|
1,
|
|
3900
|
-
|
|
3901
|
-
]
|
|
3902
|
-
|
|
3903
|
-
const [off, rad] = [[
|
|
3904
|
-
.1,
|
|
3905
|
-
.45,
|
|
3906
|
-
.42
|
|
3907
|
-
][k] * R, [
|
|
3908
|
-
.8,
|
|
3909
|
-
.75,
|
|
3910
|
-
.65
|
|
3911
|
-
][k] * R];
|
|
3912
|
-
const o = [fx * off, fz * off];
|
|
3913
|
-
const top = [
|
|
3914
|
-
H,
|
|
3915
|
-
(.5 + .15 * h(20 * k + 3)) * H,
|
|
3916
|
-
.34 * H
|
|
3917
|
-
][k] - .25 * H;
|
|
3918
|
-
const tilt = Math.min(.06, .06 / rad);
|
|
3919
|
-
const [tx, tz] = [(2 * h(20 * k + 4) - 1) * tilt, (2 * h(20 * k + 5) - 1) * tilt];
|
|
3920
|
-
const tl = Math.sqrt(tx * tx + 1 + tz * tz);
|
|
3921
|
-
return {
|
|
3922
|
-
o,
|
|
3923
|
-
rad,
|
|
3924
|
-
top,
|
|
3925
|
-
planes: [[
|
|
3926
|
-
tx / tl,
|
|
3927
|
-
1 / tl,
|
|
3928
|
-
tz / tl,
|
|
3929
|
-
(tx * o[0] + top + tz * o[1]) / tl
|
|
3930
|
-
], ...FIFTHS.map(([px, pz], j) => {
|
|
3931
|
-
const [ax, az] = [px + h(20 * k + 6 + j) - .5, pz + h(20 * k + 11 + j) - .5];
|
|
3932
|
-
const l = Math.sqrt(ax * ax + az * az);
|
|
3933
|
-
const y = -.15 + .5 * h(20 * k + 16 + j);
|
|
3934
|
-
const c = Math.sqrt(1 - y * y);
|
|
3935
|
-
const [nx, nz] = [c * ax / l, c * az / l];
|
|
3936
|
-
return [
|
|
3937
|
-
nx,
|
|
3938
|
-
y,
|
|
3939
|
-
nz,
|
|
3940
|
-
nx * o[0] + nz * o[1] + rad * (.72 + .22 * h(20 * k + 21 + j))
|
|
3941
|
-
];
|
|
3942
|
-
})]
|
|
3943
|
-
};
|
|
3944
|
-
});
|
|
3945
|
-
const [ux, uz] = flat(91);
|
|
3946
|
-
const under = [
|
|
3947
|
-
.866 * ux,
|
|
3948
|
-
-.5,
|
|
3949
|
-
.866 * uz,
|
|
3950
|
-
.72 * R
|
|
3951
|
-
];
|
|
3910
|
+
0
|
|
3911
|
+
]);
|
|
3912
|
+
const deep = rockMid(H) + .7 * H;
|
|
3952
3913
|
const reach = (u) => {
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
for (const [nx, ny, nz, d] of [...planes, under]) {
|
|
3961
|
-
const k = u[0] * nx + u[1] * ny + u[2] * nz;
|
|
3962
|
-
t = k > 1e-9 ? Math.min(t, d / k) : t;
|
|
3963
|
-
}
|
|
3964
|
-
far = Math.max(far, t);
|
|
3914
|
+
if (u[1] < 0) {
|
|
3915
|
+
const l = Math.sqrt(u[0] * u[0] + u[2] * u[2]);
|
|
3916
|
+
return l < 1e-6 ? deep : Math.min(reach([
|
|
3917
|
+
u[0] / l,
|
|
3918
|
+
0,
|
|
3919
|
+
u[2] / l
|
|
3920
|
+
]) / l, deep / -u[1]);
|
|
3965
3921
|
}
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
o[1],
|
|
3973
|
-
top
|
|
3974
|
-
])
|
|
3922
|
+
const x = (u[0] * cx + u[2] * sx - lean * u[1]) / a;
|
|
3923
|
+
const z = (u[2] * cx - u[0] * sx - (.15 - lean) * u[1]) / b;
|
|
3924
|
+
const q = u[1] * u[1] / (cu * cu);
|
|
3925
|
+
const [D, E] = [x * x + z * z + .65 * q, .35 * q * q];
|
|
3926
|
+
const T = E < 1e-12 ? 1 / D : (Math.sqrt(D * D + 4 * E) - D) / (2 * E);
|
|
3927
|
+
return Math.sqrt(T) * swell(u);
|
|
3975
3928
|
};
|
|
3929
|
+
return { reach };
|
|
3976
3930
|
};
|
|
3977
3931
|
/**
|
|
3978
|
-
* The boxes
|
|
3979
|
-
*
|
|
3980
|
-
*
|
|
3981
|
-
*
|
|
3932
|
+
* The boxes a boulder collides with, x0, y0, z0, x1, y1, z1 round its middle: what stops a body is
|
|
3933
|
+
* where the rock is drawn. From `lo` (the ground round it) to its top it is cut in layers: up to
|
|
3934
|
+
* `band` (a body's height over the ground) a layer ends where the rock has moved in or out by
|
|
3935
|
+
* FIT[0] on a bearing, or at 0.9 m; over it by FIT[1], or at 1.5 m; none thinner than 0.25 m. In
|
|
3936
|
+
* each a grid of points says where the rock is at the layer's foot and top (a box may stand 7 cm
|
|
3937
|
+
* out of it), and boxes are picked on it one after the other: the largest first, then the one
|
|
3938
|
+
* that brings the most of the outline within FIT[2] (FIT[3] over the band) of a box, overlapping
|
|
3939
|
+
* one already there, until the whole outline is. No crack between them.
|
|
3982
3940
|
*/
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
foot + .05,
|
|
4000
|
-
(foot + t) / 2,
|
|
4001
|
-
t
|
|
4002
|
-
].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)));
|
|
4003
|
-
return tops.flatMap(([ox, oz, top], k) => {
|
|
4004
|
-
let best = [
|
|
4005
|
-
0,
|
|
4006
|
-
0,
|
|
4007
|
-
0,
|
|
3941
|
+
/** How far over the ground a rock's first layer of boxes goes: more than a body steps up, from ground a little higher. */
|
|
3942
|
+
var WALL = STEP_H + .2;
|
|
3943
|
+
var FIT = [
|
|
3944
|
+
.16,
|
|
3945
|
+
.3,
|
|
3946
|
+
.16,
|
|
3947
|
+
.3
|
|
3948
|
+
];
|
|
3949
|
+
var fitted = ({ reach }, R, lo, band, foot) => {
|
|
3950
|
+
/**
|
|
3951
|
+
* The rock's outline at a height: how far it goes from its axis on 8 m bearings, m to each side
|
|
3952
|
+
* of a square round it (no Math.cos), 7 cm out of it; then whether a point is in that outline.
|
|
3953
|
+
*/
|
|
3954
|
+
const outline = (y, m) => {
|
|
3955
|
+
const o = new Float64Array(8 * m);
|
|
3956
|
+
const u = [
|
|
4008
3957
|
0,
|
|
4009
3958
|
0,
|
|
4010
3959
|
0
|
|
4011
3960
|
];
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
.
|
|
4015
|
-
.
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
3961
|
+
for (let k = 0; k < 8 * m; k++) {
|
|
3962
|
+
const t = (k % (2 * m) + .5) / m - 1;
|
|
3963
|
+
const side = Math.floor(k / (2 * m));
|
|
3964
|
+
const l = Math.sqrt(1 + t * t) * (side > 1 ? -1 : 1);
|
|
3965
|
+
const dx = (side % 2 ? -t : 1) / l;
|
|
3966
|
+
const dz = (side % 2 ? 1 : t) / l;
|
|
3967
|
+
let p = 0;
|
|
3968
|
+
let q = 1.6 * R;
|
|
3969
|
+
for (let it = 0; it < 8; it++) {
|
|
3970
|
+
const r = (p + q) / 2;
|
|
3971
|
+
const d = Math.sqrt(r * r + y * y);
|
|
3972
|
+
u[0] = r * dx / d;
|
|
3973
|
+
u[1] = y / d;
|
|
3974
|
+
u[2] = r * dz / d;
|
|
3975
|
+
if (d <= reach(u) + .07) p = r;
|
|
3976
|
+
else q = r;
|
|
3977
|
+
}
|
|
3978
|
+
o[k] = p;
|
|
3979
|
+
}
|
|
3980
|
+
return o;
|
|
3981
|
+
};
|
|
3982
|
+
const within = (o, x, z) => {
|
|
3983
|
+
const m = o.length / 8;
|
|
3984
|
+
const wide = Math.abs(x) >= Math.abs(z);
|
|
3985
|
+
if (Math.abs(x) + Math.abs(z) < 1e-9) return true;
|
|
3986
|
+
const side = wide ? x > 0 ? 0 : 2 : z > 0 ? 1 : 3;
|
|
3987
|
+
const f = ((wide ? z / x : -x / z) + 1) * m - .5 + side * 2 * m;
|
|
3988
|
+
const k = Math.floor(f);
|
|
3989
|
+
const r = o[(k + 8 * m) % (8 * m)] * (1 - (f - k)) + o[(k + 1) % (8 * m)] * (f - k);
|
|
3990
|
+
return x * x + z * z <= r * r;
|
|
3991
|
+
};
|
|
3992
|
+
const top = reach([
|
|
3993
|
+
0,
|
|
3994
|
+
1,
|
|
3995
|
+
0
|
|
3996
|
+
]) - .1;
|
|
3997
|
+
const c = Math.max(.07, Math.min(.12, R / 12));
|
|
3998
|
+
const out = [];
|
|
3999
|
+
const wall = band - PLAYER_H + WALL;
|
|
4000
|
+
const cuts = [lo];
|
|
4001
|
+
for (let a = lo; a < top - 1e-9;) {
|
|
4002
|
+
const shift = a < band - 1e-9 ? FIT[0] : FIT[1];
|
|
4003
|
+
const base = outline(a + .03, 2);
|
|
4004
|
+
let b = Math.min(a === lo && wall < top - .3 ? wall : a + .25, top);
|
|
4005
|
+
while (b < top && b - a < .9 && outline(Math.min(b + .1, top), 2).every((r, k) => Math.abs(r - base[k]) <= shift)) b = Math.min(b + .1, top);
|
|
4006
|
+
a = top - b < .15 ? top : b;
|
|
4007
|
+
cuts.push(a);
|
|
4008
|
+
}
|
|
4009
|
+
const lines = cuts.map((y, k) => outline(k ? y : y + .03, 8));
|
|
4010
|
+
for (let l = 0; l + 1 < cuts.length; l++) {
|
|
4011
|
+
const [a, b] = [cuts[l], cuts[l + 1]];
|
|
4012
|
+
const near = a < band - 1e-9 ? FIT[2] : FIT[3];
|
|
4013
|
+
const n = Math.ceil(Math.min(Math.max(...lines[l]), Math.max(...lines[l + 1])) / c) + 1;
|
|
4014
|
+
const N = 2 * n + 1;
|
|
4015
|
+
const inl = new Uint8Array(N * N);
|
|
4016
|
+
for (let i = 0; i < N; i++) for (let j = 0; j < N; j++) {
|
|
4017
|
+
const [x, z] = [(i - n) * c, (j - n) * c];
|
|
4018
|
+
inl[i + j * N] = within(lines[l], x, z) && within(lines[l + 1], x, z) ? 1 : 0;
|
|
4019
|
+
}
|
|
4020
|
+
const NEAR = Math.max(1, Math.round(near / c));
|
|
4021
|
+
const on = (i, j) => i >= 0 && i < N && j >= 0 && j < N && inl[i + j * N] > 0;
|
|
4022
|
+
const edge = new Uint8Array(N * N);
|
|
4023
|
+
for (let i = 0; i < N; i++) for (let j = 0; j < N; j++) edge[i + j * N] = on(i, j) && !(on(i - 1, j) && on(i + 1, j) && on(i, j - 1) && on(i, j + 1)) ? 1 : 0;
|
|
4024
|
+
const rects = [];
|
|
4025
|
+
const all = new Uint8Array(N);
|
|
4026
|
+
const hop = N > 48 ? 2 : 1;
|
|
4027
|
+
for (let i0 = 0; i0 < N; i0 += hop) {
|
|
4028
|
+
all.fill(1);
|
|
4029
|
+
for (let i1 = i0; i1 < N; i1++) {
|
|
4030
|
+
let any = false;
|
|
4031
|
+
for (let j = 0, from = 0; j <= N; j++) {
|
|
4032
|
+
all[j] = j < N && all[j] && inl[i1 + j * N] ? 1 : 0;
|
|
4033
|
+
if (!all[j]) {
|
|
4034
|
+
if (j - 1 - from >= 2 && i1 - i0 >= 2 && (i1 - i0) % hop === 0) rects.push([
|
|
4035
|
+
i0,
|
|
4036
|
+
from,
|
|
4037
|
+
i1,
|
|
4038
|
+
j - 1
|
|
4039
|
+
]);
|
|
4040
|
+
any ||= j - 1 > from;
|
|
4041
|
+
from = j + 1;
|
|
4042
|
+
}
|
|
4043
|
+
}
|
|
4044
|
+
if (!any) break;
|
|
4045
|
+
}
|
|
4046
|
+
}
|
|
4047
|
+
const sum = new Int32Array((N + 1) * (N + 1));
|
|
4048
|
+
const count = (i0, j0, i1, j1) => {
|
|
4049
|
+
const [a0, b0, a1, b1] = [
|
|
4050
|
+
Math.max(i0, 0),
|
|
4051
|
+
Math.max(j0, 0),
|
|
4052
|
+
Math.min(i1, N - 1) + 1,
|
|
4053
|
+
Math.min(j1, N - 1) + 1
|
|
4042
4054
|
];
|
|
4055
|
+
return sum[a1 + b1 * (N + 1)] - sum[a0 + b1 * (N + 1)] - sum[a1 + b0 * (N + 1)] + sum[a0 + b0 * (N + 1)];
|
|
4056
|
+
};
|
|
4057
|
+
const picked = [];
|
|
4058
|
+
for (let k = 0; k < 40 && rects.length; k++) {
|
|
4059
|
+
for (let j = 0; j < N; j++) for (let i = 0; i < N; i++) sum[i + 1 + (j + 1) * (N + 1)] = edge[i + j * N] + sum[i + (j + 1) * (N + 1)] + sum[i + 1 + j * (N + 1)] - sum[i + j * (N + 1)];
|
|
4060
|
+
let [best, score] = [-1, 0];
|
|
4061
|
+
for (let m = 0; m < rects.length; m++) {
|
|
4062
|
+
const q = rects[m];
|
|
4063
|
+
if (k && !picked.some((p) => q[0] < p[2] && p[0] < q[2] && q[1] < p[3] && p[1] < q[3])) continue;
|
|
4064
|
+
const area = (q[2] - q[0]) * (q[3] - q[1]);
|
|
4065
|
+
const gain = k ? count(q[0] - NEAR, q[1] - NEAR, q[2] + NEAR, q[3] + NEAR) : 2;
|
|
4066
|
+
const v = k ? gain * 1e6 + area : area;
|
|
4067
|
+
if (gain >= 2 && v > score) [best, score] = [m, v];
|
|
4068
|
+
}
|
|
4069
|
+
if (best < 0) break;
|
|
4070
|
+
const [i0, j0, i1, j1] = rects[best];
|
|
4071
|
+
picked.push(rects[best]);
|
|
4072
|
+
for (let i = Math.max(i0 - NEAR, 0); i <= Math.min(i1 + NEAR, N - 1); i++) for (let j = Math.max(j0 - NEAR, 0); j <= Math.min(j1 + NEAR, N - 1); j++) edge[i + j * N] = 0;
|
|
4073
|
+
out.push([
|
|
4074
|
+
(i0 - n) * c,
|
|
4075
|
+
l ? a : foot,
|
|
4076
|
+
(j0 - n) * c,
|
|
4077
|
+
(i1 - n) * c,
|
|
4078
|
+
b,
|
|
4079
|
+
(j1 - n) * c
|
|
4080
|
+
]);
|
|
4043
4081
|
}
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4082
|
+
}
|
|
4083
|
+
return out;
|
|
4084
|
+
};
|
|
4085
|
+
/** The ground as it is walked on: at()'s 4 m lattice, each square two triangles, as ground() in relief.ts reads it. */
|
|
4086
|
+
var walked = (x, z) => {
|
|
4087
|
+
const [i, j] = [Math.floor(x / 4), Math.floor(z / 4)];
|
|
4088
|
+
const [fu, fv] = [x / 4 - i, z / 4 - j];
|
|
4089
|
+
const h = (u, v) => at$1(4 * (i + u), 4 * (j + v));
|
|
4090
|
+
const [a, d] = [h(0, 0), h(1, 1)];
|
|
4091
|
+
return fu >= fv ? a + (h(1, 0) - a) * fu + (d - h(1, 0)) * fv : a + (h(0, 1) - a) * fv + (d - h(0, 1)) * fu;
|
|
4054
4092
|
};
|
|
4055
4093
|
/** 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. */
|
|
4056
|
-
var crag = (x, z, R, H, s
|
|
4057
|
-
const g =
|
|
4058
|
-
const y = g +
|
|
4094
|
+
var crag = (x, z, R, H, s) => {
|
|
4095
|
+
const g = walked(x, z);
|
|
4096
|
+
const y = g + rockMid(H);
|
|
4097
|
+
const span = [
|
|
4098
|
+
-3,
|
|
4099
|
+
-2,
|
|
4100
|
+
-1,
|
|
4101
|
+
0,
|
|
4102
|
+
1,
|
|
4103
|
+
2,
|
|
4104
|
+
3
|
|
4105
|
+
].map((k) => .4 * R * k);
|
|
4106
|
+
const round = span.map((u) => span.map((v) => walked(x + u, z + v)));
|
|
4107
|
+
const lo = Math.max(Math.min(...round.flat()), g - .55 * H);
|
|
4108
|
+
const band = Math.max(...round.flat()) + PLAYER_H;
|
|
4059
4109
|
return {
|
|
4060
4110
|
at: [
|
|
4061
4111
|
x,
|
|
@@ -4065,12 +4115,9 @@ var crag = (x, z, R, H, s, deep = 0) => {
|
|
|
4065
4115
|
R,
|
|
4066
4116
|
H,
|
|
4067
4117
|
s,
|
|
4068
|
-
parts:
|
|
4069
|
-
const gap = Math.max(b[0] - l[0][3], l[0][0] - b[3], b[2] - l[0][5], l[0][2] - b[5]);
|
|
4070
|
-
return !k || gap <= 0 || gap > 1.2;
|
|
4071
|
-
}).map(([x0, , z0, x1, y1, z1]) => [
|
|
4118
|
+
parts: fitted(rockOf(s, R, H), R, lo - y, band - y, lo - .5 - y).map(([x0, y0, z0, x1, y1, z1]) => [
|
|
4072
4119
|
x + x0,
|
|
4073
|
-
|
|
4120
|
+
y + y0,
|
|
4074
4121
|
z + z0,
|
|
4075
4122
|
x + x1,
|
|
4076
4123
|
y + y1,
|
|
@@ -4081,7 +4128,7 @@ var crag = (x, z, R, H, s, deep = 0) => {
|
|
|
4081
4128
|
/** 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. */
|
|
4082
4129
|
var CRAGS = {
|
|
4083
4130
|
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))],
|
|
4084
|
-
field: FIELD.map(([x, z, r], i) => crag(x, z, r, .75 * r, i + 100
|
|
4131
|
+
field: FIELD.map(([x, z, r], i) => crag(x, z, r, .75 * r, i + 100))
|
|
4085
4132
|
};
|
|
4086
4133
|
var ghosts = (l) => l.flatMap((c) => c.parts).map(([x0, y0, z0, x1, y1, z1]) => ({
|
|
4087
4134
|
...box(x0, y0, z0, x1, y1, z1, STONE),
|
|
@@ -4,5 +4,15 @@ import type { WorldDef } from '../shared/world';
|
|
|
4
4
|
* of the bound) and, at most 360 m more from a spot on the bound, inside the far clip (FAR).
|
|
5
5
|
*/
|
|
6
6
|
export declare const SKY = 800;
|
|
7
|
+
/**
|
|
8
|
+
* The ranges on the horizon, all round, past the crater wall: radius from the middle of the play
|
|
9
|
+
* area, height of its highest peak, rows of points from foot to crest, its grey in the sun and in
|
|
10
|
+
* the shade (the nearer darker and sharper, the farther paler and flatter, as the eye expects with
|
|
11
|
+
* no air), seed.
|
|
12
|
+
* Inside the stars' dome and, from the far side of the bound, the far plane.
|
|
13
|
+
*/
|
|
14
|
+
export declare const RANGES: number[][];
|
|
15
|
+
/** Columns a range is drawn in: three quarters of a degree each, no segment shows on its skyline. */
|
|
16
|
+
export declare const RANGE_COLS = 480;
|
|
7
17
|
/** The moon's scenery vertices, in the renderer's format. */
|
|
8
18
|
export declare const moonscape: (def: WorldDef) => number[];
|
|
@@ -34,18 +34,18 @@ export declare const MOUND: number, RISE: number;
|
|
|
34
34
|
*/
|
|
35
35
|
export declare const FLATS: number[][];
|
|
36
36
|
type V3 = [number, number, number];
|
|
37
|
+
/** How high a rock's middle is over the ground: three tenths of its height, and 0.6 m or half its height if less. Its widest is there, its flank steep down to the ground: a body is stopped at its foot. */
|
|
38
|
+
export declare const rockMid: (H: number) => number;
|
|
37
39
|
/**
|
|
38
40
|
* The form of a boulder of radius R and height H from a seed: how far it reaches from its middle
|
|
39
|
-
* (
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* `tops` are the lobes' middles (x, z) and the height of their top over the rock's middle.
|
|
41
|
+
* (rockMid() over the ground) along a unit vector. A rounded solid, no plane in it:
|
|
42
|
+
* an ellipsoid stretched unevenly on its three axes and turned by the seed, upright under its
|
|
43
|
+
* middle (it stands in the regolith, as wide at the ground as at its middle) and a dome over it, swollen and shrunk by two low octaves
|
|
44
|
+
* of noise with the bearing (large soft lobes), with one gentle hollow and one flatter side. Only
|
|
45
|
+
* + - * /, Math.sqrt and the hash: the boxes below come from it on every side.
|
|
45
46
|
*/
|
|
46
47
|
export declare const rockOf: (s: number, R: number, H: number) => {
|
|
47
48
|
reach: (u: V3) => number;
|
|
48
|
-
tops: number[][];
|
|
49
49
|
};
|
|
50
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
51
|
export declare const PIT_R: number, PIT_S: number, PIT_FLOOR: number, PIT_STEPS: 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.121.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|