@johnmorrisdotca/chikyu-earth 0.54.0 → 0.56.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/CHANGELOG.md +16 -1
- package/NOTICE.md +5 -1
- package/README.md +1 -1
- package/dist/door/gibs.d.ts +55 -6
- package/dist/door/gibs.js +177 -51
- package/dist/photos/index.d.ts +232 -0
- package/dist/photos/index.js +261 -0
- package/dist/realistic/element-base.d.ts +21 -0
- package/dist/realistic/element-base.js +57 -14
- package/dist/realistic/gate.d.ts +5 -0
- package/dist/realistic/gate.js +5 -2
- package/dist/realistic/index.d.ts +1 -0
- package/dist/realistic/index.js +1 -0
- package/dist/realistic/pace.d.ts +98 -0
- package/dist/realistic/pace.js +112 -0
- package/dist/satellites/track.js +25 -0
- package/dist/satellites/types.d.ts +5 -0
- package/dist/space/element-base.d.ts +21 -0
- package/dist/space/element-base.js +58 -8
- package/package.json +6 -1
package/dist/realistic/gate.d.ts
CHANGED
|
@@ -71,3 +71,8 @@ export declare function frameCap(maxFps?: number, device?: {
|
|
|
71
71
|
deviceMemory?: number;
|
|
72
72
|
hardwareConcurrency?: number;
|
|
73
73
|
}): number;
|
|
74
|
+
/** Whether this is a small device: 2 GB of memory or less, or 2 cores or fewer (`deviceMemory` and `hardwareConcurrency` from `navigator`, either may be left out). */
|
|
75
|
+
export declare function smallDevice(device?: {
|
|
76
|
+
deviceMemory?: number;
|
|
77
|
+
hardwareConcurrency?: number;
|
|
78
|
+
}): boolean;
|
package/dist/realistic/gate.js
CHANGED
|
@@ -88,6 +88,9 @@ export function createGate(minMs, fire, timers = browserTimers) {
|
|
|
88
88
|
* ```
|
|
89
89
|
*/
|
|
90
90
|
export function frameCap(maxFps = 30, device = {}) {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
return Math.max(1, smallDevice(device) ? Math.min(maxFps, 20) : maxFps);
|
|
92
|
+
}
|
|
93
|
+
/** Whether this is a small device: 2 GB of memory or less, or 2 cores or fewer (`deviceMemory` and `hardwareConcurrency` from `navigator`, either may be left out). */
|
|
94
|
+
export function smallDevice(device = {}) {
|
|
95
|
+
return (device.deviceMemory !== undefined && device.deviceMemory <= 2) || (device.hardwareConcurrency !== undefined && device.hardwareConcurrency <= 2);
|
|
93
96
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { greenwichSidereal, subsolarPoint, unitVector, julianDay } from "./sun.ts";
|
|
2
2
|
export { chooseTier, textureBytes, textureCap, MAX_TEXTURE, TIERS, TEXELS_PER_RADIUS_PIXEL, type Layer } from "./tiers.ts";
|
|
3
3
|
export { createGate, frameCap, type Gate } from "./gate.ts";
|
|
4
|
+
export { framesPerSecond, readSmoothFps, smoothCap, waitFor, watchLowBattery } from "./pace.ts";
|
|
4
5
|
export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre, type CameraMode, type LightMode } from "./earth.ts";
|
|
5
6
|
export type { ThreeParts } from "./earth.ts";
|
|
6
7
|
export { TEXEL_SLACK, coveringTile, gridTilesInView, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type TilePerspective, type VisibleTile } from "./tiles.ts";
|
package/dist/realistic/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
export { greenwichSidereal, subsolarPoint, unitVector, julianDay } from "./sun.js";
|
|
4
4
|
export { chooseTier, textureBytes, textureCap, MAX_TEXTURE, TIERS, TEXELS_PER_RADIUS_PIXEL } from "./tiers.js";
|
|
5
5
|
export { createGate, frameCap } from "./gate.js";
|
|
6
|
+
export { framesPerSecond, readSmoothFps, smoothCap, waitFor, watchLowBattery } from "./pace.js";
|
|
6
7
|
export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre } from "./earth.js";
|
|
7
8
|
export { TEXEL_SLACK, coveringTile, gridTilesInView, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView } from "./tiles.js";
|
|
8
9
|
export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.js";
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** The most frames a second a clock at real time (or up to 60 times it) draws by default: `smooth-fps` changes it. */
|
|
2
|
+
export declare const SMOOTH_FPS = 15;
|
|
3
|
+
/** The most `smooth-fps` allows. */
|
|
4
|
+
export declare const SMOOTH_FPS_MAX = 30;
|
|
5
|
+
/** How far, in CSS pixels, the fastest thing on show may move between two frames before the next one is drawn: half a pixel is under what the eye reads as a step. */
|
|
6
|
+
export declare const SMOOTH_STEP_PX = 0.5;
|
|
7
|
+
/** The fastest clock, in seconds of game time for each real second, that is paced by half a pixel and the `smooth-fps` cap (at real time exactly; above it never less often than a frame a pixel). Beyond it the picture is drawn once for each pixel moved, up to 30 a second. */
|
|
8
|
+
export declare const SMOOTH_UP_TO = 60;
|
|
9
|
+
/**
|
|
10
|
+
* Read `smooth-fps`: a number of frames a second from 1 to 30, and 15 for nothing or anything else.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The attribute's text, or `null` when it is not set.
|
|
13
|
+
* @returns The frames a second.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { readSmoothFps } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
18
|
+
*
|
|
19
|
+
* console.log(readSmoothFps(null), readSmoothFps("24"), readSmoothFps("500"), readSmoothFps("many"));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function readSmoothFps(value: string | null): number;
|
|
23
|
+
/**
|
|
24
|
+
* The cap on the frames a second of a running clock for this device: `smoothFps`, or half of it (at least 1) on a small device (2 GB of memory or less, or 2 cores or fewer) or on a battery at 20% or lower that is not charging.
|
|
25
|
+
*
|
|
26
|
+
* @param smoothFps - The page's own cap (`smooth-fps`).
|
|
27
|
+
* @param tight - Whether the device is small or its battery low.
|
|
28
|
+
* @returns The frames a second to allow.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { smoothCap } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
33
|
+
*
|
|
34
|
+
* console.log(smoothCap(15, false), smoothCap(15, true));
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function smoothCap(smoothFps: number, tight: boolean): number;
|
|
38
|
+
/** What `framesPerSecond` reads. */
|
|
39
|
+
export interface PaceInput {
|
|
40
|
+
/** How fast the quickest thing on show moves across the screen, in CSS pixels a second of real time: the Earth's turn at this zoom, a satellite dot, the ridden craft and the camera in a ride. */
|
|
41
|
+
pixelsPerSecond: number;
|
|
42
|
+
/** The clock's speed, in seconds of game time for each real second. */
|
|
43
|
+
speed: number;
|
|
44
|
+
/** The most frames a second from `smoothCap`. */
|
|
45
|
+
cap: number;
|
|
46
|
+
/** A reader who asked for reduced motion: at most one a second. */
|
|
47
|
+
reduced?: boolean;
|
|
48
|
+
/** Something moves that the Earth's own turn does not account for (satellites on show, a ride): at least one a second. Otherwise a still picture may be drawn less often than that. */
|
|
49
|
+
always?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* How many frames a second a running clock should draw (a number below 1 means a frame less often than every second, which only a picture with nothing quick in it gets).
|
|
53
|
+
* At real time a frame is drawn each time the quickest thing has moved half a pixel on the screen, at most `cap` a second. Above real time, up to 60 times it, that or a frame for every pixel it moves (up to 30 a second, as it always was), whichever is more often,
|
|
54
|
+
* so a faster clock is never drawn less often than it was; above that a frame for every pixel, up to 30 a second. A reader who asked for reduced motion gets one a second at most. At least one a second when `always` or the clock is faster than real time.
|
|
55
|
+
*
|
|
56
|
+
* @param input - How fast things move and the limits.
|
|
57
|
+
* @returns Frames a second, 0 when nothing moves at all.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { framesPerSecond } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
62
|
+
*
|
|
63
|
+
* // a low satellite on a whole Earth, then the same zoomed in, then a reader who asked for reduced motion
|
|
64
|
+
* console.log(framesPerSecond({ pixelsPerSecond: 0.3, speed: 1, cap: 15, always: true }));
|
|
65
|
+
* console.log(framesPerSecond({ pixelsPerSecond: 6, speed: 1, cap: 15, always: true }));
|
|
66
|
+
* console.log(framesPerSecond({ pixelsPerSecond: 6, speed: 1, cap: 15, always: true, reduced: true }));
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function framesPerSecond(input: PaceInput): number;
|
|
70
|
+
/**
|
|
71
|
+
* The wait, in milliseconds, before the next frame at `perSecond`: never under a frame's share of a second and never over `longest`.
|
|
72
|
+
*
|
|
73
|
+
* @param perSecond - Frames a second from `framesPerSecond`.
|
|
74
|
+
* @param longest - The longest wait, in milliseconds (a minute at real time with nothing quick on show).
|
|
75
|
+
* @returns Milliseconds.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { waitFor } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
80
|
+
*
|
|
81
|
+
* console.log(waitFor(4, 60_000), waitFor(0, 60_000));
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function waitFor(perSecond: number, longest: number): number;
|
|
85
|
+
/**
|
|
86
|
+
* Ask the browser (where it can say) whether the battery is at 20% or lower and not charging, and tell `set` when it is. Browsers without the battery API, and a refusal, say nothing: the device counts as plugged in.
|
|
87
|
+
*
|
|
88
|
+
* @param nav - `navigator`, or anything with its `getBattery`.
|
|
89
|
+
* @param set - Called with `true` when the battery is low.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { watchLowBattery } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
94
|
+
*
|
|
95
|
+
* watchLowBattery(navigator, (low) => console.log("low battery", low));
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function watchLowBattery(nav: object, set: (low: boolean) => void): void;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// How often a running clock draws: the pure rule, with no browser in it, so a test can ask it anything. Both live views (the realistic Earth and the space view) use it.
|
|
2
|
+
/** The most frames a second a clock at real time (or up to 60 times it) draws by default: `smooth-fps` changes it. */
|
|
3
|
+
export const SMOOTH_FPS = 15;
|
|
4
|
+
/** The most `smooth-fps` allows. */
|
|
5
|
+
export const SMOOTH_FPS_MAX = 30;
|
|
6
|
+
/** How far, in CSS pixels, the fastest thing on show may move between two frames before the next one is drawn: half a pixel is under what the eye reads as a step. */
|
|
7
|
+
export const SMOOTH_STEP_PX = 0.5;
|
|
8
|
+
/** The fastest clock, in seconds of game time for each real second, that is paced by half a pixel and the `smooth-fps` cap (at real time exactly; above it never less often than a frame a pixel). Beyond it the picture is drawn once for each pixel moved, up to 30 a second. */
|
|
9
|
+
export const SMOOTH_UP_TO = 60;
|
|
10
|
+
/**
|
|
11
|
+
* Read `smooth-fps`: a number of frames a second from 1 to 30, and 15 for nothing or anything else.
|
|
12
|
+
*
|
|
13
|
+
* @param value - The attribute's text, or `null` when it is not set.
|
|
14
|
+
* @returns The frames a second.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { readSmoothFps } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
19
|
+
*
|
|
20
|
+
* console.log(readSmoothFps(null), readSmoothFps("24"), readSmoothFps("500"), readSmoothFps("many"));
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function readSmoothFps(value) {
|
|
24
|
+
if (value === null || value.trim() === "")
|
|
25
|
+
return SMOOTH_FPS;
|
|
26
|
+
const number = Number(value);
|
|
27
|
+
return Number.isFinite(number) ? Math.min(SMOOTH_FPS_MAX, Math.max(1, number)) : SMOOTH_FPS;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The cap on the frames a second of a running clock for this device: `smoothFps`, or half of it (at least 1) on a small device (2 GB of memory or less, or 2 cores or fewer) or on a battery at 20% or lower that is not charging.
|
|
31
|
+
*
|
|
32
|
+
* @param smoothFps - The page's own cap (`smooth-fps`).
|
|
33
|
+
* @param tight - Whether the device is small or its battery low.
|
|
34
|
+
* @returns The frames a second to allow.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { smoothCap } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
39
|
+
*
|
|
40
|
+
* console.log(smoothCap(15, false), smoothCap(15, true));
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function smoothCap(smoothFps, tight) {
|
|
44
|
+
return tight ? Math.max(1, Math.round(smoothFps / 2)) : Math.max(1, smoothFps);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* How many frames a second a running clock should draw (a number below 1 means a frame less often than every second, which only a picture with nothing quick in it gets).
|
|
48
|
+
* At real time a frame is drawn each time the quickest thing has moved half a pixel on the screen, at most `cap` a second. Above real time, up to 60 times it, that or a frame for every pixel it moves (up to 30 a second, as it always was), whichever is more often,
|
|
49
|
+
* so a faster clock is never drawn less often than it was; above that a frame for every pixel, up to 30 a second. A reader who asked for reduced motion gets one a second at most. At least one a second when `always` or the clock is faster than real time.
|
|
50
|
+
*
|
|
51
|
+
* @param input - How fast things move and the limits.
|
|
52
|
+
* @returns Frames a second, 0 when nothing moves at all.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { framesPerSecond } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
57
|
+
*
|
|
58
|
+
* // a low satellite on a whole Earth, then the same zoomed in, then a reader who asked for reduced motion
|
|
59
|
+
* console.log(framesPerSecond({ pixelsPerSecond: 0.3, speed: 1, cap: 15, always: true }));
|
|
60
|
+
* console.log(framesPerSecond({ pixelsPerSecond: 6, speed: 1, cap: 15, always: true }));
|
|
61
|
+
* console.log(framesPerSecond({ pixelsPerSecond: 6, speed: 1, cap: 15, always: true, reduced: true }));
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export function framesPerSecond(input) {
|
|
65
|
+
const pixels = Number.isFinite(input.pixelsPerSecond) ? Math.max(0, input.pixelsPerSecond) : 0;
|
|
66
|
+
const speed = Math.abs(input.speed);
|
|
67
|
+
const smooth = Math.min(Math.max(1, input.cap), pixels / SMOOTH_STEP_PX);
|
|
68
|
+
const pixelwise = Math.min(SMOOTH_FPS_MAX, pixels);
|
|
69
|
+
// real time is strictly within the cap; above it the picture is never drawn less often than it was (a frame for each pixel, up to 30 a second), and above 60 times it is that alone
|
|
70
|
+
let rate = speed <= 1 ? smooth : speed <= SMOOTH_UP_TO ? Math.max(smooth, pixelwise) : pixelwise;
|
|
71
|
+
if (input.reduced)
|
|
72
|
+
rate = Math.min(rate, 1);
|
|
73
|
+
if (input.always || speed > 1)
|
|
74
|
+
rate = Math.max(rate, 1);
|
|
75
|
+
return rate;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The wait, in milliseconds, before the next frame at `perSecond`: never under a frame's share of a second and never over `longest`.
|
|
79
|
+
*
|
|
80
|
+
* @param perSecond - Frames a second from `framesPerSecond`.
|
|
81
|
+
* @param longest - The longest wait, in milliseconds (a minute at real time with nothing quick on show).
|
|
82
|
+
* @returns Milliseconds.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { waitFor } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
87
|
+
*
|
|
88
|
+
* console.log(waitFor(4, 60_000), waitFor(0, 60_000));
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export function waitFor(perSecond, longest) {
|
|
92
|
+
return perSecond > 0 ? Math.min(longest, 1000 / perSecond) : longest;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Ask the browser (where it can say) whether the battery is at 20% or lower and not charging, and tell `set` when it is. Browsers without the battery API, and a refusal, say nothing: the device counts as plugged in.
|
|
96
|
+
*
|
|
97
|
+
* @param nav - `navigator`, or anything with its `getBattery`.
|
|
98
|
+
* @param set - Called with `true` when the battery is low.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import { watchLowBattery } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
103
|
+
*
|
|
104
|
+
* watchLowBattery(navigator, (low) => console.log("low battery", low));
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export function watchLowBattery(nav, set) {
|
|
108
|
+
nav.getBattery?.().then((battery) => {
|
|
109
|
+
if (!battery.charging && battery.level <= 0.2)
|
|
110
|
+
set(true);
|
|
111
|
+
}, () => undefined);
|
|
112
|
+
}
|
package/dist/satellites/track.js
CHANGED
|
@@ -138,6 +138,10 @@ export function createSatellites(sets, options = {}) {
|
|
|
138
138
|
let bMs = 0;
|
|
139
139
|
let ready = false;
|
|
140
140
|
let stepMs = MIN_STEP_MS;
|
|
141
|
+
// the quickest satellite between the two samples now held, in Earth radii for each second of game time, worked out once for each pair (see `at`) and not at every frame
|
|
142
|
+
let fastest = 0;
|
|
143
|
+
let fastestAt = Number.NaN;
|
|
144
|
+
let fastestTo = Number.NaN;
|
|
141
145
|
let propagations = 0;
|
|
142
146
|
let placed = 0;
|
|
143
147
|
const timing = { lastBatchMs: 0, maxBatchMs: 0 };
|
|
@@ -236,6 +240,9 @@ export function createSatellites(sets, options = {}) {
|
|
|
236
240
|
get placed() {
|
|
237
241
|
return placed;
|
|
238
242
|
},
|
|
243
|
+
get fastest() {
|
|
244
|
+
return fastest;
|
|
245
|
+
},
|
|
239
246
|
get estimateFar() {
|
|
240
247
|
return estimate;
|
|
241
248
|
},
|
|
@@ -388,6 +395,24 @@ export function createSatellites(sets, options = {}) {
|
|
|
388
395
|
ready = true;
|
|
389
396
|
}
|
|
390
397
|
}
|
|
398
|
+
// how far the quickest one went between the two samples: once for each pair of samples (about once a second), never at a frame, so it costs one pass over the group a second
|
|
399
|
+
if (fastestAt !== aMs || fastestTo !== bMs) {
|
|
400
|
+
fastestAt = aMs;
|
|
401
|
+
fastestTo = bMs;
|
|
402
|
+
let most = 0;
|
|
403
|
+
for (let i = 0; i < n; i += 1) {
|
|
404
|
+
if (okA[i] !== 1 || okB[i] !== 1)
|
|
405
|
+
continue;
|
|
406
|
+
const k = i * 3;
|
|
407
|
+
const dx = b[k] - a[k];
|
|
408
|
+
const dy = b[k + 1] - a[k + 1];
|
|
409
|
+
const dz = b[k + 2] - a[k + 2];
|
|
410
|
+
const squared = dx * dx + dy * dy + dz * dz;
|
|
411
|
+
if (squared > most)
|
|
412
|
+
most = squared;
|
|
413
|
+
}
|
|
414
|
+
fastest = Math.sqrt(most) / ((bMs - aMs) / 1000);
|
|
415
|
+
}
|
|
391
416
|
const t = (ms - aMs) / (bMs - aMs);
|
|
392
417
|
let count = 0;
|
|
393
418
|
for (let i = 0; i < n; i += 1) {
|
|
@@ -170,6 +170,11 @@ export interface Satellites {
|
|
|
170
170
|
visible(index: number): boolean;
|
|
171
171
|
/** How many of them the last `at` or `arc` placed. */
|
|
172
172
|
readonly placed: number;
|
|
173
|
+
/**
|
|
174
|
+
* How fast the quickest satellite goes, in Earth radii for each second of the clock's time, between the two moments SGP4 was last run at for `at` (0 before the first `at`). It is worked out once for each pair of moments from
|
|
175
|
+
* the places already held, so it costs nothing at a frame; the view uses it to draw a frame whenever the quickest dot has moved half a pixel. Multiply by the Earth's radius on the screen for pixels.
|
|
176
|
+
*/
|
|
177
|
+
readonly fastest: number;
|
|
173
178
|
/** Place satellites beyond `maxAgeDays` from their elements as an estimate (`estimateFar`, off by default). Setting it places everything again at the next draw. */
|
|
174
179
|
estimateFar: boolean;
|
|
175
180
|
/** How many satellites the last `at` or `arc` placed as an estimate. */
|
|
@@ -707,6 +707,20 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
707
707
|
*/
|
|
708
708
|
get satelliteStreakMax(): number;
|
|
709
709
|
set satelliteStreakMax(value: number);
|
|
710
|
+
/**
|
|
711
|
+
* The most frames a second drawn for a clock at real time, or up to 60 times it (the attribute `smooth-fps`; 15 when the page says nothing; 1 to 30). The picture is drawn each time the quickest thing in it (the Earth's turn at this zoom, a satellite dot,
|
|
712
|
+
* the ridden craft and the camera in a ride) has moved half a pixel, at least once a second while anything but the Earth is moving, and at most this many. Half as many on a small device or a battery at 20% or lower; one a second for a reader who asked for reduced motion.
|
|
713
|
+
*
|
|
714
|
+
* @example
|
|
715
|
+
* ```ts
|
|
716
|
+
* import "@johnmorrisdotca/chikyu-earth/space/element";
|
|
717
|
+
*
|
|
718
|
+
* const space = document.querySelector("chikyu-space")!;
|
|
719
|
+
* space.smoothFps = 24;
|
|
720
|
+
* ```
|
|
721
|
+
*/
|
|
722
|
+
get smoothFps(): number;
|
|
723
|
+
set smoothFps(value: number);
|
|
710
724
|
/**
|
|
711
725
|
* Show a group of satellites (made by `createSatellites`) under a name, or take the group away with `null`. A group is one draw call however many satellites it holds. Giving the name of a group
|
|
712
726
|
* that is already shown replaces it. `style`: `color` and `size` (CSS pixels) of the dots, and `orbits` to draw every orbit (only for a group of 40 or fewer, such as the stations).
|
|
@@ -927,6 +941,13 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
927
941
|
time: number;
|
|
928
942
|
lookups: number;
|
|
929
943
|
satellites: SatelliteStats;
|
|
944
|
+
/** How often the running clock draws, as last worked out: the quickest thing's speed on the screen (CSS pixels a second of real time), the frames a second that asks for, the most allowed (`smooth-fps`, halved on a small device or a low battery) and the wait before the next step in milliseconds. */
|
|
945
|
+
pace: {
|
|
946
|
+
pixelsPerSecond: number;
|
|
947
|
+
perSecond: number;
|
|
948
|
+
cap: number;
|
|
949
|
+
waitMs: number;
|
|
950
|
+
};
|
|
930
951
|
/** The cross-fade when `light` changes to or from `lit` (300 ms, a cut under reduced motion): `mix` is 0 for the true light and 1 for `lit`, and `fading` is true while it moves and another frame is wanted. */
|
|
931
952
|
lightFade: {
|
|
932
953
|
mix: number;
|
|
@@ -20,7 +20,8 @@ import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
|
|
|
20
20
|
import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
|
|
21
21
|
import { SEA_NAMES_ATTRIBUTES, readSeaNames } from "../sea-names/geometry.js";
|
|
22
22
|
import { SEA_NAMES_STYLE, createSeaHost } from "../sea-names/host.js";
|
|
23
|
-
import { createGate, frameCap } from "../realistic/gate.js";
|
|
23
|
+
import { createGate, frameCap, smallDevice } from "../realistic/gate.js";
|
|
24
|
+
import { framesPerSecond, readSmoothFps, smoothCap, SMOOTH_UP_TO, waitFor, watchLowBattery } from "../realistic/pace.js";
|
|
24
25
|
import { createFinerHolder, GIBS_ID } from "../door/gibs.js";
|
|
25
26
|
import { folderSource } from "../door/map.js";
|
|
26
27
|
import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
|
|
@@ -178,7 +179,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
|
|
|
178
179
|
* ```
|
|
179
180
|
*/
|
|
180
181
|
export class ChikyuSpace extends HTMLElement {
|
|
181
|
-
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...BEAM_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-model-size", "ride-drag", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom", "ride-up", "compass"];
|
|
182
|
+
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...BEAM_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-model-size", "ride-drag", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom", "ride-up", "compass", "smooth-fps"];
|
|
182
183
|
#model = newSpaceModel();
|
|
183
184
|
/** The finer imagery (NASA's tile service), one source while the attributes stay the same. Off unless `tiles-finer="gibs"`. */
|
|
184
185
|
#finerHold = createFinerHolder(() => new Date(this.#model.time), () => this.#gate?.request());
|
|
@@ -215,6 +216,10 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
215
216
|
#toldTrack = "";
|
|
216
217
|
#bodiesNote;
|
|
217
218
|
#gate;
|
|
219
|
+
/** Whether the battery is low (at 20% or less and not charging): the smooth frame rate is halved. */
|
|
220
|
+
#lowBattery = false;
|
|
221
|
+
/** What `#schedule` last worked out, for `stats`. */
|
|
222
|
+
#pace = { pixelsPerSecond: 0, perSecond: 0, cap: 0, waitMs: 0 };
|
|
218
223
|
#taken;
|
|
219
224
|
#stage;
|
|
220
225
|
#labelBox;
|
|
@@ -344,6 +349,11 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
344
349
|
this.#pool.clear();
|
|
345
350
|
const nav = navigator;
|
|
346
351
|
this.#gate = createGate(1000 / frameCap(30, { deviceMemory: nav.deviceMemory, hardwareConcurrency: nav.hardwareConcurrency }), () => this.#view?.invalidate());
|
|
352
|
+
this.#lowBattery = false;
|
|
353
|
+
watchLowBattery(nav, () => {
|
|
354
|
+
this.#lowBattery = true;
|
|
355
|
+
this.#schedule();
|
|
356
|
+
});
|
|
347
357
|
this.#stage.addEventListener("webglcontextlost", this.#lost, true);
|
|
348
358
|
this.#stage.addEventListener("webglcontextrestored", this.#restored, true);
|
|
349
359
|
const taken = takeRenderer((state) => {
|
|
@@ -603,6 +613,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
603
613
|
this.#model.satellites.streakMax = readStreakMax(value);
|
|
604
614
|
this.#gate?.request();
|
|
605
615
|
}
|
|
616
|
+
else if (name === "smooth-fps")
|
|
617
|
+
this.#schedule();
|
|
606
618
|
else if (name === "tiles" || name === "tiles-finer" || name === "tiles-finer-layer" || name === "tiles-finer-date" || name === "tiles-finer-timeout")
|
|
607
619
|
this.#gate?.request();
|
|
608
620
|
if (name === "air-thickness" || name === "air-label" || name === "lang")
|
|
@@ -1963,6 +1975,27 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1963
1975
|
else
|
|
1964
1976
|
this.removeAttribute("satellite-streak-max");
|
|
1965
1977
|
}
|
|
1978
|
+
/**
|
|
1979
|
+
* The most frames a second drawn for a clock at real time, or up to 60 times it (the attribute `smooth-fps`; 15 when the page says nothing; 1 to 30). The picture is drawn each time the quickest thing in it (the Earth's turn at this zoom, a satellite dot,
|
|
1980
|
+
* the ridden craft and the camera in a ride) has moved half a pixel, at least once a second while anything but the Earth is moving, and at most this many. Half as many on a small device or a battery at 20% or lower; one a second for a reader who asked for reduced motion.
|
|
1981
|
+
*
|
|
1982
|
+
* @example
|
|
1983
|
+
* ```ts
|
|
1984
|
+
* import "@johnmorrisdotca/chikyu-earth/space/element";
|
|
1985
|
+
*
|
|
1986
|
+
* const space = document.querySelector("chikyu-space")!;
|
|
1987
|
+
* space.smoothFps = 24;
|
|
1988
|
+
* ```
|
|
1989
|
+
*/
|
|
1990
|
+
get smoothFps() {
|
|
1991
|
+
return readSmoothFps(this.getAttribute("smooth-fps"));
|
|
1992
|
+
}
|
|
1993
|
+
set smoothFps(value) {
|
|
1994
|
+
if (Number.isFinite(value) && value > 0)
|
|
1995
|
+
this.setAttribute("smooth-fps", String(value));
|
|
1996
|
+
else
|
|
1997
|
+
this.removeAttribute("smooth-fps");
|
|
1998
|
+
}
|
|
1966
1999
|
/**
|
|
1967
2000
|
* Show a group of satellites (made by `createSatellites`) under a name, or take the group away with `null`. A group is one draw call however many satellites it holds. Giving the name of a group
|
|
1968
2001
|
* that is already shown replaces it. `style`: `color` and `size` (CSS pixels) of the dots, and `orbits` to draw every orbit (only for a group of 40 or fewer, such as the stations).
|
|
@@ -2453,6 +2486,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
2453
2486
|
time: this.#model.time,
|
|
2454
2487
|
lookups: this.#model.lookups,
|
|
2455
2488
|
satellites: this.#satelliteStats(),
|
|
2489
|
+
pace: { ...this.#pace },
|
|
2456
2490
|
lightFade: { mix: this.#model.lightFade.mix, fading: this.#model.lightFade.fading },
|
|
2457
2491
|
paths: this.#pathControls?.stats() ?? emptyPathStats(),
|
|
2458
2492
|
ride: { track: this.#model.rideTrack ? { ...this.#model.rideTrack } : null, compass: this.#compass?.shown ? { ...this.#compass.shown } : null, riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null || this.#model.rideFrame.moving, facing: this.facing, groundKm: this.#model.rideFrame.groundKm },
|
|
@@ -2502,7 +2536,19 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
2502
2536
|
return true;
|
|
2503
2537
|
return false;
|
|
2504
2538
|
}
|
|
2505
|
-
/**
|
|
2539
|
+
/** The quickest a satellite on show goes, in Earth radii for each second of game time: the quickest the groups report between their two SGP4 moments, or, before they have any (and above the interpolation limit, where they do not), a low orbit's. */
|
|
2540
|
+
#satelliteRate() {
|
|
2541
|
+
let most = 0;
|
|
2542
|
+
for (const [name, group] of this.#model.satellites.groups)
|
|
2543
|
+
if (satelliteEmphasis(name, group.visible, this.#model.satellites.focus).drawn)
|
|
2544
|
+
most = Math.max(most, group.satellites.fastest);
|
|
2545
|
+
return most > 0 && Math.abs(this.#speed) <= SMOOTH_UP_TO ? most : SATELLITE_RATE * RAD;
|
|
2546
|
+
}
|
|
2547
|
+
/**
|
|
2548
|
+
* While time runs, draw each time the quickest thing in the picture has moved half a pixel: the Earth's turn at this zoom, a satellite dot (the quickest of the groups on show, from the places they hold for the interpolation), the ridden craft and the camera in a ride.
|
|
2549
|
+
* At most `smooth-fps` a second (15), half as many on a small device or a low battery, and at least once a second while a satellite or a ride moves; real time with only the Earth turning waits up to a minute. A reader who asked for reduced motion gets one a second at most.
|
|
2550
|
+
* Faster than 60 times real time it is a frame for each pixel, up to 30 a second.
|
|
2551
|
+
*/
|
|
2506
2552
|
#schedule() {
|
|
2507
2553
|
clearTimeout(this.#timer);
|
|
2508
2554
|
this.#timer = undefined;
|
|
@@ -2510,12 +2556,16 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
2510
2556
|
return;
|
|
2511
2557
|
const satellites = this.#satellitesMoving();
|
|
2512
2558
|
const riding = this.#model.ride !== null;
|
|
2559
|
+
const speed = Math.abs(this.#speed);
|
|
2513
2560
|
const radius = this.#model.drawn?.radiusPx ?? 200;
|
|
2514
|
-
const pixelsPerSecond = Math.max(
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
const
|
|
2561
|
+
const pixelsPerSecond = Math.max(EARTH_RATE * RAD * speed * radius, satellites ? this.#satelliteRate() * speed * radius : 0, this.#model.rideMotion * speed);
|
|
2562
|
+
const nav = navigator;
|
|
2563
|
+
const cap = smoothCap(this.smoothFps, this.#lowBattery || smallDevice({ deviceMemory: nav.deviceMemory, hardwareConcurrency: nav.hardwareConcurrency }));
|
|
2564
|
+
// a reader who asked for reduced motion gets one a second while satellites or a ride move or the clock is at real time; a clock the reader set running faster over a bare Earth is theirs to ask for (as before)
|
|
2565
|
+
const perSecond = framesPerSecond({ pixelsPerSecond, speed: this.#speed, cap, reduced: prefersLessMotion() && (satellites || riding || speed <= 1), always: satellites || riding });
|
|
2566
|
+
// a hidden tab is not drawn: it is looked at once a second, as the browser would have it anyway
|
|
2567
|
+
const wait = Math.max(waitFor(perSecond, REAL_TIME_TICK_MS), document.visibilityState === "hidden" ? 1000 : 0);
|
|
2568
|
+
this.#pace = { pixelsPerSecond, perSecond, cap, waitMs: wait };
|
|
2519
2569
|
this.#timer = setTimeout(this.#tick, wait);
|
|
2520
2570
|
}
|
|
2521
2571
|
/** Bring the moment shown up to `now` (the page's own clock, in milliseconds) at the speed it has run at. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.56.0",
|
|
4
4
|
"description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on the place you give it, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"earth",
|
|
@@ -191,6 +191,11 @@
|
|
|
191
191
|
"import": "./dist/place/index.js",
|
|
192
192
|
"default": "./dist/place/index.js"
|
|
193
193
|
},
|
|
194
|
+
"./photos": {
|
|
195
|
+
"types": "./dist/photos/index.d.ts",
|
|
196
|
+
"import": "./dist/photos/index.js",
|
|
197
|
+
"default": "./dist/photos/index.js"
|
|
198
|
+
},
|
|
194
199
|
"./package.json": "./package.json"
|
|
195
200
|
},
|
|
196
201
|
"files": [
|