@reicek/neataptic-ts 0.1.21 → 0.1.22
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/.github/agents/boundary-mapper.agent.md +29 -0
- package/.github/agents/docs-scout.agent.md +29 -0
- package/.github/agents/plan-scout.agent.md +29 -0
- package/.github/agents/solid-split.agent.md +138 -0
- package/.github/copilot-instructions.md +103 -0
- package/package.json +6 -3
- package/plans/ES2023 migration +13 -8
- package/plans/Evolution_Training_Interoperability_Contracts.md +1 -1
- package/plans/Interactive_Examples_and_Learning_Path.md +10 -2
- package/plans/Memory_Optimization.md +3 -3
- package/plans/README.md +63 -0
- package/plans/Roadmap.md +15 -3
- package/plans/asciiMaze_SOLID_split.done.md +130 -0
- package/plans/flappy_bird_SOLID_split.done.md +67 -0
- package/scripts/assets/theme.css +221 -34
- package/scripts/copy-examples.mjs +9 -5
- package/scripts/export-onnx.mjs +3 -3
- package/scripts/generate-bench-tables.mjs +10 -10
- package/scripts/generate-bench-tables.ts +10 -10
- package/scripts/generate-docs.ts +1415 -449
- package/scripts/render-docs-html.ts +15 -8
- package/src/README.md +101 -223
- package/src/architecture/README.md +57 -185
- package/src/architecture/layer/README.md +38 -38
- package/src/architecture/network/README.md +33 -31
- package/src/architecture/network/activate/README.md +77 -77
- package/src/architecture/network/connect/README.md +15 -13
- package/src/architecture/network/deterministic/README.md +7 -7
- package/src/architecture/network/evolve/README.md +44 -44
- package/src/architecture/network/gating/README.md +20 -20
- package/src/architecture/network/genetic/README.md +51 -51
- package/src/architecture/network/mutate/README.md +97 -97
- package/src/architecture/network/onnx/README.md +264 -264
- package/src/architecture/network/prune/README.md +39 -39
- package/src/architecture/network/remove/README.md +26 -26
- package/src/architecture/network/serialize/README.md +56 -56
- package/src/architecture/network/slab/README.md +61 -61
- package/src/architecture/network/standalone/README.md +24 -24
- package/src/architecture/network/stats/README.md +9 -9
- package/src/architecture/network/topology/README.md +46 -46
- package/src/architecture/network/training/README.md +21 -21
- package/src/methods/README.md +9 -87
- package/src/multithreading/README.md +8 -77
- package/src/multithreading/workers/README.md +2 -2
- package/src/multithreading/workers/browser/README.md +0 -6
- package/src/multithreading/workers/node/README.md +0 -3
- package/src/neat/README.md +562 -568
- package/src/utils/README.md +18 -18
- package/test/examples/asciiMaze/README.md +59 -59
- package/test/examples/asciiMaze/asciiMaze.e2e.test.ts +14 -9
- package/test/examples/asciiMaze/browser-entry/README.md +196 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.abort.services.ts +95 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.constants.ts +23 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.curriculum.services.ts +115 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.globals.services.ts +106 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.host.services.ts +157 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.services.ts +14 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.ts +129 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.types.ts +120 -0
- package/test/examples/asciiMaze/browser-entry/browser-entry.utils.ts +98 -0
- package/test/examples/asciiMaze/browser-entry.ts +10 -576
- package/test/examples/asciiMaze/dashboardManager/README.md +276 -0
- package/test/examples/asciiMaze/dashboardManager/archive/README.md +16 -0
- package/test/examples/asciiMaze/dashboardManager/archive/dashboardManager.archive.services.ts +267 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.constants.ts +35 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.services.ts +103 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.ts +181 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.types.ts +267 -0
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.utils.ts +254 -0
- package/test/examples/asciiMaze/dashboardManager/live/README.md +14 -0
- package/test/examples/asciiMaze/dashboardManager/live/dashboardManager.live.services.ts +264 -0
- package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +47 -0
- package/test/examples/asciiMaze/dashboardManager/telemetry/dashboardManager.telemetry.services.ts +513 -0
- package/test/examples/asciiMaze/dashboardManager.ts +13 -2335
- package/test/examples/asciiMaze/evolutionEngine/README.md +1058 -0
- package/test/examples/asciiMaze/evolutionEngine/curriculumPhase.ts +90 -0
- package/test/examples/asciiMaze/evolutionEngine/engineState.constants.ts +36 -0
- package/test/examples/asciiMaze/evolutionEngine/engineState.ts +58 -513
- package/test/examples/asciiMaze/evolutionEngine/engineState.types.ts +212 -0
- package/test/examples/asciiMaze/evolutionEngine/engineState.utils.ts +301 -0
- package/test/examples/asciiMaze/evolutionEngine/evolutionEngine.types.ts +445 -0
- package/test/examples/asciiMaze/evolutionEngine/evolutionLoop.ts +81 -50
- package/test/examples/asciiMaze/evolutionEngine/optionsAndSetup.ts +2 -4
- package/test/examples/asciiMaze/evolutionEngine/populationDynamics.ts +17 -33
- package/test/examples/asciiMaze/evolutionEngine/populationPruning.ts +1 -1
- package/test/examples/asciiMaze/evolutionEngine/rngAndTiming.ts +1 -2
- package/test/examples/asciiMaze/evolutionEngine/sampling.ts +1 -1
- package/test/examples/asciiMaze/evolutionEngine/scratchPools.ts +2 -5
- package/test/examples/asciiMaze/evolutionEngine/setupHelpers.ts +30 -37
- package/test/examples/asciiMaze/evolutionEngine/telemetryMetrics.ts +16 -58
- package/test/examples/asciiMaze/evolutionEngine/trainingWarmStart.ts +2 -2
- package/test/examples/asciiMaze/evolutionEngine.ts +55 -55
- package/test/examples/asciiMaze/fitness.ts +2 -2
- package/test/examples/asciiMaze/fitness.types.ts +65 -0
- package/test/examples/asciiMaze/interfaces.ts +64 -1352
- package/test/examples/asciiMaze/mazeMovement/README.md +356 -0
- package/test/examples/asciiMaze/mazeMovement/finalization/README.md +49 -0
- package/test/examples/asciiMaze/mazeMovement/finalization/mazeMovement.finalization.ts +138 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.constants.ts +101 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.services.ts +230 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.ts +299 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.types.ts +185 -0
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.utils.ts +153 -0
- package/test/examples/asciiMaze/mazeMovement/policy/README.md +91 -0
- package/test/examples/asciiMaze/mazeMovement/policy/mazeMovement.policy.ts +467 -0
- package/test/examples/asciiMaze/mazeMovement/runtime/README.md +95 -0
- package/test/examples/asciiMaze/mazeMovement/runtime/mazeMovement.runtime.ts +354 -0
- package/test/examples/asciiMaze/mazeMovement/shaping/README.md +124 -0
- package/test/examples/asciiMaze/mazeMovement/shaping/mazeMovement.shaping.ts +459 -0
- package/test/examples/asciiMaze/mazeMovement.ts +12 -2978
- package/test/examples/flappy_bird/Trace-20260309T191949.json +24124 -0
- package/test/examples/flappy_bird/browser-entry/README.md +1129 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.host.utils.ts +4 -324
- package/test/examples/flappy_bird/browser-entry/browser-entry.network-view.utils.ts +6 -399
- package/test/examples/flappy_bird/browser-entry/browser-entry.playback.utils.ts +1 -717
- package/test/examples/flappy_bird/browser-entry/browser-entry.spawn.utils.ts +11 -31
- package/test/examples/flappy_bird/browser-entry/browser-entry.visualization.utils.ts +15 -893
- package/test/examples/flappy_bird/browser-entry/host/README.md +307 -0
- package/test/examples/flappy_bird/browser-entry/host/host.resize.service.ts +1 -295
- package/test/examples/flappy_bird/browser-entry/host/host.ts +562 -6
- package/test/examples/flappy_bird/browser-entry/host/resize/README.md +274 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.constants.ts +31 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.services.ts +360 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.ts +117 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.types.ts +63 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.utils.ts +250 -0
- package/test/examples/flappy_bird/browser-entry/network-view/README.md +399 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.topology.utils.ts +255 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.ts +802 -7
- package/test/examples/flappy_bird/browser-entry/playback/README.md +684 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/README.md +277 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +770 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.cache.services.ts +178 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.constants.ts +107 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.geometry.utils.ts +518 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.math.utils.ts +117 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.pulse.utils.ts +233 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.services.ts +211 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.ts +48 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.types.ts +212 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.utils.ts +81 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.cache.services.ts +96 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.constants.ts +62 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.services.ts +244 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.ts +53 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.types.ts +68 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.utils.ts +100 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +310 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.service.ts +92 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.services.ts +272 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.types.ts +39 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.utils.ts +493 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.constants.ts +1 -1
- package/test/examples/flappy_bird/browser-entry/playback/playback.frame-render.service.ts +4 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.snapshot.utils.ts +44 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.service.ts +39 -122
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.services.ts +272 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.types.ts +62 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.utils.ts +11 -4
- package/test/examples/flappy_bird/browser-entry/playback/playback.ts +409 -8
- package/test/examples/flappy_bird/browser-entry/playback/playback.types.ts +4 -12
- package/test/examples/flappy_bird/browser-entry/runtime/README.md +235 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.evolution-launch.service.ts +45 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.lifecycle.service.ts +81 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.startup.service.ts +74 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.ts +31 -121
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.types.ts +36 -0
- package/test/examples/flappy_bird/browser-entry/visualization/README.md +557 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.constants.ts +110 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.draw.service.ts +957 -19
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.legend.utils.ts +138 -3
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.topology.utils.ts +3 -27
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.ts +1 -23
- package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +156 -0
- package/test/examples/flappy_bird/constants/README.md +1179 -0
- package/test/examples/flappy_bird/constants/constants.network-view.ts +24 -0
- package/test/examples/flappy_bird/constants/constants.palette.ts +7 -0
- package/test/examples/flappy_bird/constants/constants.starfield.ts +78 -3
- package/test/examples/flappy_bird/environment/README.md +143 -0
- package/test/examples/flappy_bird/environment/environment.observation.utils.ts +1 -19
- package/test/examples/flappy_bird/environment/environment.step.service.ts +3 -66
- package/test/examples/flappy_bird/evaluation/README.md +130 -0
- package/test/examples/flappy_bird/evaluation/evaluation.fitness.utils.ts +1 -1
- package/test/examples/flappy_bird/evaluation/evaluation.rollout.service.ts +5 -375
- package/test/examples/flappy_bird/evaluation/rollout/README.md +291 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.constants.ts +30 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.service.ts +58 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.services.ts +310 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.types.ts +56 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.utils.ts +368 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/README.md +618 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.playback.service.ts +7 -7
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.frame.service.ts +364 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.types.ts +14 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.utils.ts +4 -201
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.ts +184 -345
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.warm-start.service.ts +291 -0
- package/test/examples/flappy_bird/flappy.simulation.shared.utils.ts +5 -0
- package/test/examples/flappy_bird/simulation-shared/README.md +417 -0
- package/test/examples/flappy_bird/simulation-shared/observation/README.md +183 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.features.utils.ts +301 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.ts +9 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.vector.utils.ts +59 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.observation.utils.ts +5 -403
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.spawn.utils.ts +20 -6
- package/test/examples/flappy_bird/{evaluation/evaluation.statistics.utils.ts → simulation-shared/simulation-shared.statistics.utils.ts} +23 -8
- package/test/examples/flappy_bird/trainer/README.md +563 -0
- package/test/examples/flappy_bird/trainer/evaluation/README.md +199 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.constants.ts +9 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.services.ts +73 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.ts +165 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.types.ts +25 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.utils.ts +161 -0
- package/test/examples/flappy_bird/trainer/trainer.evaluation.service.ts +13 -0
- package/test/examples/flappy_bird/trainer/trainer.report.service.services.ts +181 -0
- package/test/examples/flappy_bird/trainer/trainer.report.service.ts +126 -0
- package/test/examples/flappy_bird/trainer/trainer.selection.utils.ts +89 -0
- package/test/examples/flappy_bird/trainer/trainer.ts +11 -553
- package/test/examples/flappy_bird/browser-entry/browser-entry.utils.ts +0 -12
- package/test/examples/flappy_bird/environment/environment.ts +0 -7
- package/test/examples/flappy_bird/evaluation/evaluation.ts +0 -7
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.ts +0 -15
- package/test/examples/flappy_bird/trainer/trainer.statistics.utils.ts +0 -78
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { FLAPPY_GROUND_GRID_FOG_HEIGHT_RATIO } from './playback.background.ground-grid.constants';
|
|
2
|
+
import type {
|
|
3
|
+
PlaybackBackgroundGroundGridSceneContext,
|
|
4
|
+
PlaybackGroundGridHorizontalGeometry,
|
|
5
|
+
PlaybackGroundGridHorizontalGeometryFactory,
|
|
6
|
+
PlaybackGroundGridVerticalGeometry,
|
|
7
|
+
PlaybackGroundGridVerticalGeometryFactory,
|
|
8
|
+
} from './playback.background.ground-grid.types';
|
|
9
|
+
|
|
10
|
+
let cachedViewportSizeKey: string | null = null;
|
|
11
|
+
let cachedFogGradientsByCanvas = new WeakMap<
|
|
12
|
+
HTMLCanvasElement,
|
|
13
|
+
Map<string, CanvasGradient>
|
|
14
|
+
>();
|
|
15
|
+
|
|
16
|
+
const cachedHorizontalGeometryBySceneKey = new Map<
|
|
17
|
+
string,
|
|
18
|
+
PlaybackGroundGridHorizontalGeometry
|
|
19
|
+
>();
|
|
20
|
+
const cachedVerticalGeometryByCycleKey = new Map<
|
|
21
|
+
string,
|
|
22
|
+
PlaybackGroundGridVerticalGeometry
|
|
23
|
+
>();
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Ensures ground-grid caches only retain entries for the current viewport size.
|
|
27
|
+
*
|
|
28
|
+
* The ground grid is derived from viewport width and total scene height, so a
|
|
29
|
+
* page resize invalidates every cached geometry variant and fog gradient.
|
|
30
|
+
*
|
|
31
|
+
* @param sceneContext - Current lower-band scene geometry.
|
|
32
|
+
* @returns Stable viewport-size cache key for the current frame.
|
|
33
|
+
*/
|
|
34
|
+
export function ensureGroundGridViewportCacheValidity(
|
|
35
|
+
sceneContext: PlaybackBackgroundGroundGridSceneContext,
|
|
36
|
+
): string {
|
|
37
|
+
const viewportSizeKey = resolveGroundGridViewportCacheKey(sceneContext);
|
|
38
|
+
if (cachedViewportSizeKey === viewportSizeKey) {
|
|
39
|
+
return viewportSizeKey;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
cachedViewportSizeKey = viewportSizeKey;
|
|
43
|
+
cachedHorizontalGeometryBySceneKey.clear();
|
|
44
|
+
cachedVerticalGeometryByCycleKey.clear();
|
|
45
|
+
cachedFogGradientsByCanvas = new WeakMap<
|
|
46
|
+
HTMLCanvasElement,
|
|
47
|
+
Map<string, CanvasGradient>
|
|
48
|
+
>();
|
|
49
|
+
return viewportSizeKey;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Resolves the viewport-size cache key used by the ground-grid caches.
|
|
54
|
+
*
|
|
55
|
+
* @param sceneContext - Current lower-band scene geometry.
|
|
56
|
+
* @returns Cache key that changes whenever the page size changes.
|
|
57
|
+
*/
|
|
58
|
+
export function resolveGroundGridViewportCacheKey(
|
|
59
|
+
sceneContext: PlaybackBackgroundGroundGridSceneContext,
|
|
60
|
+
): string {
|
|
61
|
+
return `${sceneContext.visibleWorldWidthPx}x${sceneContext.lowerBandBottomYPx}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Resolves the stable local-scene cache key for ground-grid geometry.
|
|
66
|
+
*
|
|
67
|
+
* @param sceneContext - Current lower-band scene geometry.
|
|
68
|
+
* @returns Scene key suitable for static horizontal and vertical cache entries.
|
|
69
|
+
*/
|
|
70
|
+
export function resolveGroundGridSceneCacheKey(
|
|
71
|
+
sceneContext: PlaybackBackgroundGroundGridSceneContext,
|
|
72
|
+
): string {
|
|
73
|
+
return [
|
|
74
|
+
sceneContext.visibleWorldWidthPx,
|
|
75
|
+
sceneContext.alignedHorizonYPx,
|
|
76
|
+
sceneContext.lowerBandTopYPx,
|
|
77
|
+
sceneContext.lowerBandHeightPx,
|
|
78
|
+
sceneContext.lowerBandBottomYPx,
|
|
79
|
+
sceneContext.vanishingPointXPx,
|
|
80
|
+
sceneContext.vanishingPointYPx,
|
|
81
|
+
].join(':');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Resolves the cache key for one wrapped vertical-geometry cycle.
|
|
86
|
+
*
|
|
87
|
+
* @param sceneCacheKey - Stable scene key for the active viewport.
|
|
88
|
+
* @param wrappedOffsetPx - Quantized wrapped offset within one lane cycle.
|
|
89
|
+
* @returns Cycle key used for vertical geometry reuse.
|
|
90
|
+
*/
|
|
91
|
+
export function resolveGroundGridVerticalCycleCacheKey(
|
|
92
|
+
sceneCacheKey: string,
|
|
93
|
+
wrappedOffsetPx: number,
|
|
94
|
+
): string {
|
|
95
|
+
return `${sceneCacheKey}|offset:${wrappedOffsetPx}`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Resolves cached horizontal geometry for one scene.
|
|
100
|
+
*
|
|
101
|
+
* @param sceneCacheKey - Stable scene key for the active viewport.
|
|
102
|
+
* @param factory - Lazy geometry builder used when the cache misses.
|
|
103
|
+
* @returns Cached horizontal geometry bundle for the scene.
|
|
104
|
+
*/
|
|
105
|
+
export function resolveCachedGroundGridHorizontalGeometry(
|
|
106
|
+
sceneCacheKey: string,
|
|
107
|
+
factory: PlaybackGroundGridHorizontalGeometryFactory,
|
|
108
|
+
): PlaybackGroundGridHorizontalGeometry {
|
|
109
|
+
const cachedGeometry = cachedHorizontalGeometryBySceneKey.get(sceneCacheKey);
|
|
110
|
+
if (cachedGeometry) {
|
|
111
|
+
return cachedGeometry;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const resolvedGeometry = factory();
|
|
115
|
+
cachedHorizontalGeometryBySceneKey.set(sceneCacheKey, resolvedGeometry);
|
|
116
|
+
return resolvedGeometry;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Resolves cached vertical geometry for one scene and wrapped offset cycle.
|
|
121
|
+
*
|
|
122
|
+
* @param cycleCacheKey - Scene-and-offset cache key for the active frame.
|
|
123
|
+
* @param factory - Lazy geometry builder used when the cache misses.
|
|
124
|
+
* @returns Cached vertical geometry bundle for the cycle.
|
|
125
|
+
*/
|
|
126
|
+
export function resolveCachedGroundGridVerticalGeometry(
|
|
127
|
+
cycleCacheKey: string,
|
|
128
|
+
factory: PlaybackGroundGridVerticalGeometryFactory,
|
|
129
|
+
): PlaybackGroundGridVerticalGeometry {
|
|
130
|
+
const cachedGeometry = cachedVerticalGeometryByCycleKey.get(cycleCacheKey);
|
|
131
|
+
if (cachedGeometry) {
|
|
132
|
+
return cachedGeometry;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const resolvedGeometry = factory();
|
|
136
|
+
cachedVerticalGeometryByCycleKey.set(cycleCacheKey, resolvedGeometry);
|
|
137
|
+
return resolvedGeometry;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Resolves a cached fog gradient for one canvas and local scene.
|
|
142
|
+
*
|
|
143
|
+
* @param context - Canvas 2D drawing context.
|
|
144
|
+
* @param sceneCacheKey - Stable scene key for the active viewport.
|
|
145
|
+
* @param sceneContext - Current lower-band scene geometry.
|
|
146
|
+
* @param fogColor - Theme-owned fog color token.
|
|
147
|
+
* @returns Cached fog gradient aligned to the lower-band scene.
|
|
148
|
+
*/
|
|
149
|
+
export function resolveCachedGroundGridFogGradient(
|
|
150
|
+
context: CanvasRenderingContext2D,
|
|
151
|
+
sceneCacheKey: string,
|
|
152
|
+
sceneContext: PlaybackBackgroundGroundGridSceneContext,
|
|
153
|
+
fogColor: string,
|
|
154
|
+
): CanvasGradient {
|
|
155
|
+
const fogGradientKey = `${sceneCacheKey}|fog:${fogColor}`;
|
|
156
|
+
const canvas = context.canvas;
|
|
157
|
+
const cachedGradientsForCanvas =
|
|
158
|
+
cachedFogGradientsByCanvas.get(canvas) ?? new Map<string, CanvasGradient>();
|
|
159
|
+
const cachedGradient = cachedGradientsForCanvas.get(fogGradientKey);
|
|
160
|
+
if (cachedGradient) {
|
|
161
|
+
return cachedGradient;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const fogHeightPx =
|
|
165
|
+
sceneContext.lowerBandHeightPx * FLAPPY_GROUND_GRID_FOG_HEIGHT_RATIO;
|
|
166
|
+
const fogGradient = context.createLinearGradient(
|
|
167
|
+
0,
|
|
168
|
+
sceneContext.lowerBandTopYPx,
|
|
169
|
+
0,
|
|
170
|
+
sceneContext.lowerBandTopYPx + fogHeightPx,
|
|
171
|
+
);
|
|
172
|
+
fogGradient.addColorStop(0, fogColor);
|
|
173
|
+
fogGradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
|
|
174
|
+
|
|
175
|
+
cachedGradientsForCanvas.set(fogGradientKey, fogGradient);
|
|
176
|
+
cachedFogGradientsByCanvas.set(canvas, cachedGradientsForCanvas);
|
|
177
|
+
return fogGradient;
|
|
178
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { FLAPPY_NEON_PALETTE } from '../../../../constants/constants';
|
|
2
|
+
import type { PlaybackBackgroundGroundGridStyle } from './playback.background.ground-grid.types';
|
|
3
|
+
|
|
4
|
+
/** Number of horizontal depth bands used by the neon ground grid. */
|
|
5
|
+
export const FLAPPY_GROUND_GRID_HORIZONTAL_LINE_COUNT = 16;
|
|
6
|
+
|
|
7
|
+
/** Target spacing between perspective-ray anchors at the bottom edge (pixels). */
|
|
8
|
+
export const FLAPPY_GROUND_GRID_TARGET_VERTICAL_LINE_SPACING_PX = 320;
|
|
9
|
+
|
|
10
|
+
/** Minimum visible perspective-ray count used on very narrow viewports. */
|
|
11
|
+
export const FLAPPY_GROUND_GRID_MIN_VERTICAL_LINE_COUNT = 2;
|
|
12
|
+
|
|
13
|
+
/** Extra off-screen perspective rays drawn for seamless wrap. */
|
|
14
|
+
export const FLAPPY_GROUND_GRID_VERTICAL_OVERFLOW_COUNT = 1;
|
|
15
|
+
|
|
16
|
+
/** Target screen-space height for one vertical-ray style segment (pixels). */
|
|
17
|
+
export const FLAPPY_GROUND_GRID_TARGET_VERTICAL_SEGMENT_HEIGHT_PX = 24;
|
|
18
|
+
|
|
19
|
+
/** Approximate playback frame duration used for deterministic pulse timing. */
|
|
20
|
+
export const FLAPPY_GROUND_GRID_APPROX_FRAME_DURATION_MS = 1000 / 60;
|
|
21
|
+
|
|
22
|
+
/** Interval between visible pulse events (milliseconds). */
|
|
23
|
+
export const FLAPPY_GROUND_GRID_PULSE_INTERVAL_MS = 3000;
|
|
24
|
+
|
|
25
|
+
/** Lifetime of one pulse as it travels across its chosen line (milliseconds). */
|
|
26
|
+
export const FLAPPY_GROUND_GRID_PULSE_LIFETIME_MS = 1100;
|
|
27
|
+
|
|
28
|
+
/** Glow blur applied behind each visible pulse square (pixels). */
|
|
29
|
+
export const FLAPPY_GROUND_GRID_PULSE_GLOW_BLUR_PX = 8;
|
|
30
|
+
|
|
31
|
+
/** Peak opacity used by visible pulse squares. */
|
|
32
|
+
export const FLAPPY_GROUND_GRID_PULSE_ALPHA = 0.92;
|
|
33
|
+
|
|
34
|
+
/** Smallest visible pulse square size (pixels). */
|
|
35
|
+
export const FLAPPY_GROUND_GRID_PULSE_MIN_SIZE_PX = 1;
|
|
36
|
+
|
|
37
|
+
/** Largest visible pulse square size (pixels). */
|
|
38
|
+
export const FLAPPY_GROUND_GRID_PULSE_MAX_SIZE_PX = 6;
|
|
39
|
+
|
|
40
|
+
/** Earliest progress ratio allowed for vertical pulse travel. */
|
|
41
|
+
export const FLAPPY_GROUND_GRID_VERTICAL_PULSE_START_RATIO = 0.14;
|
|
42
|
+
|
|
43
|
+
/** Latest progress ratio allowed for vertical pulse travel. */
|
|
44
|
+
export const FLAPPY_GROUND_GRID_VERTICAL_PULSE_END_RATIO = 0.62;
|
|
45
|
+
|
|
46
|
+
/** Minimum horizontal line thickness eligible for pulse travel. */
|
|
47
|
+
export const FLAPPY_GROUND_GRID_PULSE_MIN_ELIGIBLE_THICKNESS_PX = 1.5;
|
|
48
|
+
|
|
49
|
+
/** Earliest eligible slice of horizontal lines used for visible pulse picks. */
|
|
50
|
+
export const FLAPPY_GROUND_GRID_PULSE_PREFERRED_HORIZONTAL_START_RATIO = 0.4;
|
|
51
|
+
|
|
52
|
+
/** Horizontal inset that keeps vertical pulse picks away from clipped edges. */
|
|
53
|
+
export const FLAPPY_GROUND_GRID_PULSE_VISIBLE_VIEWPORT_INSET_PX = 24;
|
|
54
|
+
|
|
55
|
+
/** Size multiplier used for the soft glow halo behind one pulse square. */
|
|
56
|
+
export const FLAPPY_GROUND_GRID_PULSE_GLOW_SIZE_MULTIPLIER = 2.4;
|
|
57
|
+
|
|
58
|
+
/** Alpha ratio used for the soft glow halo behind one pulse square. */
|
|
59
|
+
export const FLAPPY_GROUND_GRID_PULSE_GLOW_ALPHA_RATIO = 0.45;
|
|
60
|
+
|
|
61
|
+
/** Normalization divisor used for deterministic pulse hash generation. */
|
|
62
|
+
export const FLAPPY_GROUND_GRID_UNSIGNED_NORMALIZATION_DIVISOR = 0x1_0000_0000;
|
|
63
|
+
|
|
64
|
+
/** Non-linear exponent used to compress depth lines toward the horizon. */
|
|
65
|
+
export const FLAPPY_GROUND_GRID_DEPTH_CURVE_EXPONENT = 2.35;
|
|
66
|
+
|
|
67
|
+
/** Scroll ratio applied to the moving vertical perspective rays. */
|
|
68
|
+
export const FLAPPY_GROUND_GRID_SCROLL_RATIO = 0.16;
|
|
69
|
+
|
|
70
|
+
/** Minimum alpha used by the farthest horizontal depth lines. */
|
|
71
|
+
export const FLAPPY_GROUND_GRID_MIN_ALPHA = 0.12;
|
|
72
|
+
|
|
73
|
+
/** Maximum alpha used by the nearest depth and perspective lines. */
|
|
74
|
+
export const FLAPPY_GROUND_GRID_MAX_ALPHA = 0.58;
|
|
75
|
+
|
|
76
|
+
/** Blur radius used by the farthest depth lines near the horizon. */
|
|
77
|
+
export const FLAPPY_GROUND_GRID_MAX_BLUR_PX = 6;
|
|
78
|
+
|
|
79
|
+
/** Blur radius used by the nearest depth lines at the bottom edge. */
|
|
80
|
+
export const FLAPPY_GROUND_GRID_MIN_BLUR_PX = 0;
|
|
81
|
+
|
|
82
|
+
/** Minimum stroke width used by far depth lines. */
|
|
83
|
+
export const FLAPPY_GROUND_GRID_MIN_THICKNESS_PX = 1;
|
|
84
|
+
|
|
85
|
+
/** Maximum stroke width used by near depth lines. */
|
|
86
|
+
export const FLAPPY_GROUND_GRID_MAX_THICKNESS_PX = 3;
|
|
87
|
+
|
|
88
|
+
/** Height ratio reserved for the subtle lower-band neon fog wash. */
|
|
89
|
+
export const FLAPPY_GROUND_GRID_FOG_HEIGHT_RATIO = 0.45;
|
|
90
|
+
|
|
91
|
+
/** Peak opacity used by the lower-band neon fog wash. */
|
|
92
|
+
export const FLAPPY_GROUND_GRID_FOG_ALPHA = 0.24;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Frozen neon style bundle reused by the playback ground-grid renderer.
|
|
96
|
+
*
|
|
97
|
+
* The values stay theme-owned but are materialized once so the renderer does
|
|
98
|
+
* not allocate a new style object during every frame.
|
|
99
|
+
*/
|
|
100
|
+
export const FLAPPY_BACKGROUND_GROUND_GRID_STYLE: PlaybackBackgroundGroundGridStyle =
|
|
101
|
+
Object.freeze({
|
|
102
|
+
lineColor: FLAPPY_NEON_PALETTE.groundGridLine,
|
|
103
|
+
glowColor: FLAPPY_NEON_PALETTE.groundGridGlow,
|
|
104
|
+
fogColor: FLAPPY_NEON_PALETTE.groundGridFog,
|
|
105
|
+
pulseFillColor: FLAPPY_NEON_PALETTE.groundGridPulseFill,
|
|
106
|
+
pulseGlowColor: FLAPPY_NEON_PALETTE.groundGridPulseGlow,
|
|
107
|
+
});
|