@reicek/neataptic-ts 0.1.21 → 0.1.23
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 +31 -0
- package/.github/agents/docs-scout.agent.md +29 -0
- package/.github/agents/plan-scout.agent.md +31 -0
- package/.github/agents/solid-split.agent.md +143 -0
- package/.github/copilot-instructions.md +119 -0
- package/.github/skills/solid-split-playbook/SKILL.md +220 -0
- package/.github/skills/solid-split-playbook/assets/docs-checklist.md +34 -0
- package/.github/skills/solid-split-playbook/assets/split-plan-template.md +48 -0
- package/.github/skills/solid-split-playbook/assets/split-workflow-checklist.md +51 -0
- package/.github/skills/trace-analyzer-extension/SKILL.md +63 -0
- package/.github/skills/trace-analyzer-extension/assets/extension-checklist.md +24 -0
- package/.github/skills/trace-analyzer-extension/references/analyzer-extension-workflow.md +101 -0
- package/.github/skills/trace-audit-reporting/SKILL.md +96 -0
- package/.github/skills/trace-audit-reporting/assets/performance-report-template.md +123 -0
- package/.github/skills/trace-audit-reporting/references/trace-analysis-workflow.md +132 -0
- package/package.json +7 -3
- package/plans/ES2023 migration +13 -8
- package/plans/Evolution_Training_Interoperability_Contracts.md +1 -1
- package/plans/Flappy_Bird_Folder_Documentation_Pass.md +53 -0
- package/plans/Flappy_Evolution_Worker_Documentation_Pass.md +58 -0
- 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/analyze-trace.ts +590 -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 +127 -222
- package/src/architecture/README.md +117 -184
- package/src/architecture/architect.ts +6 -0
- package/src/architecture/layer/README.md +38 -38
- package/src/architecture/network/README.md +49 -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/network.types.ts +39 -0
- 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/serialize/network.serialize.json.utils.ts +1 -0
- package/src/architecture/network/serialize/network.serialize.utils.ts +6 -1
- package/src/architecture/network/serialize/network.serialize.utils.types.ts +1 -1
- 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/architecture/network.ts +114 -10
- 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 +623 -568
- package/src/neat/neat.evolve.population.utils.ts +29 -5
- package/src/neat/neat.helpers.ts +16 -0
- package/src/neat/neat.topology-intent.utils.ts +160 -0
- 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/README.md +193 -88
- package/test/examples/flappy_bird/browser-entry/README.md +1441 -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 +9 -396
- package/test/examples/flappy_bird/browser-entry/browser-entry.playback.utils.ts +6 -714
- package/test/examples/flappy_bird/browser-entry/browser-entry.render.types.ts +26 -3
- package/test/examples/flappy_bird/browser-entry/browser-entry.runtime.types.ts +16 -1
- package/test/examples/flappy_bird/browser-entry/browser-entry.simulation.types.ts +39 -5
- package/test/examples/flappy_bird/browser-entry/browser-entry.spawn.utils.ts +11 -31
- package/test/examples/flappy_bird/browser-entry/browser-entry.stats.types.ts +32 -4
- package/test/examples/flappy_bird/browser-entry/browser-entry.ts +11 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.types.ts +8 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.visualization.types.ts +50 -7
- package/test/examples/flappy_bird/browser-entry/browser-entry.visualization.utils.ts +21 -893
- package/test/examples/flappy_bird/browser-entry/browser-entry.worker.types.ts +91 -10
- package/test/examples/flappy_bird/browser-entry/host/README.md +318 -0
- package/test/examples/flappy_bird/browser-entry/host/host.canvas.service.ts +16 -0
- package/test/examples/flappy_bird/browser-entry/host/host.constants.ts +20 -0
- package/test/examples/flappy_bird/browser-entry/host/host.dom.service.ts +10 -0
- package/test/examples/flappy_bird/browser-entry/host/host.resize.service.ts +1 -295
- package/test/examples/flappy_bird/browser-entry/host/host.stats.service.ts +14 -0
- package/test/examples/flappy_bird/browser-entry/host/host.ts +592 -6
- package/test/examples/flappy_bird/browser-entry/host/host.types.ts +13 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/README.md +309 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.constants.ts +47 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.services.ts +392 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.ts +132 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.types.ts +92 -0
- package/test/examples/flappy_bird/browser-entry/host/resize/host.resize.service.utils.ts +272 -0
- package/test/examples/flappy_bird/browser-entry/network-view/README.md +389 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.draw.service.ts +13 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.labels.utils.ts +12 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.layout.utils.ts +14 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.topology.utils.ts +267 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.ts +823 -7
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.types.ts +11 -0
- package/test/examples/flappy_bird/browser-entry/playback/README.md +845 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/README.md +355 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +1068 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.batch.services.ts +64 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.cache.services.ts +207 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.constants.ts +197 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.geometry.batch.utils.ts +114 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.geometry.layout.utils.test.ts +96 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.geometry.layout.utils.ts +204 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.geometry.services.ts +49 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.geometry.utils.ts +313 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.layer.services.ts +81 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.math.utils.test.ts +33 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.math.utils.ts +201 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.pulse.selection.utils.ts +171 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.pulse.timing.utils.ts +124 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.pulse.utils.test.ts +279 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.pulse.utils.ts +132 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.scene.services.ts +26 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.services.ts +65 -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 +342 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/playback.background.ground-grid.utils.ts +10 -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 +127 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.draw.services.ts +184 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.scene.services.ts +64 -0
- package/test/examples/flappy_bird/browser-entry/playback/background/playback.background.services.ts +6 -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 +105 -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 +541 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.bird.utils.ts +180 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.canvas.services.ts +77 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.entity.services.ts +167 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.scene.services.ts +57 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.service.test.ts +176 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.service.ts +113 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.services.ts +35 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.trail.utils.ts +248 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.types.ts +103 -0
- package/test/examples/flappy_bird/browser-entry/playback/frame-render/playback.frame-render.utils.ts +11 -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 +10 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.iteration.services.ts +192 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.loop.service.ts +12 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.orchestration.types.ts +78 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.render.pipe-outline.service.ts +128 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.render.service.ts +1 -116
- package/test/examples/flappy_bird/browser-entry/playback/playback.session.services.ts +184 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.snapshot.utils.test.ts +121 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.snapshot.utils.ts +8 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.layer.services.ts +36 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.service.ts +11 -128
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.services.ts +268 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.types.ts +91 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.utils.ts +11 -4
- package/test/examples/flappy_bird/browser-entry/playback/playback.trail.utils.ts +9 -86
- package/test/examples/flappy_bird/browser-entry/playback/playback.ts +75 -7
- package/test/examples/flappy_bird/browser-entry/playback/playback.types.ts +12 -9
- package/test/examples/flappy_bird/browser-entry/playback/playback.worker-channel.utils.ts +11 -123
- package/test/examples/flappy_bird/browser-entry/playback/snapshot/README.md +55 -0
- package/test/examples/flappy_bird/browser-entry/playback/snapshot/playback.snapshot.services.ts +103 -0
- package/test/examples/flappy_bird/browser-entry/playback/snapshot/playback.snapshot.summary.utils.test.ts +45 -0
- package/test/examples/flappy_bird/browser-entry/playback/snapshot/playback.snapshot.summary.utils.ts +28 -0
- package/test/examples/flappy_bird/browser-entry/playback/trail/README.md +95 -0
- package/test/examples/flappy_bird/browser-entry/playback/trail/playback.trail.history.services.test.ts +35 -0
- package/test/examples/flappy_bird/browser-entry/playback/trail/playback.trail.history.services.ts +64 -0
- package/test/examples/flappy_bird/browser-entry/playback/trail/playback.trail.opacity.utils.test.ts +37 -0
- package/test/examples/flappy_bird/browser-entry/playback/trail/playback.trail.opacity.utils.ts +74 -0
- package/test/examples/flappy_bird/browser-entry/playback/worker-channel/README.md +71 -0
- package/test/examples/flappy_bird/browser-entry/playback/worker-channel/playback.worker-channel.request.services.ts +45 -0
- package/test/examples/flappy_bird/browser-entry/playback/worker-channel/playback.worker-channel.summary.services.ts +74 -0
- package/test/examples/flappy_bird/browser-entry/playback/worker-channel/playback.worker-channel.types.ts +53 -0
- package/test/examples/flappy_bird/browser-entry/runtime/README.md +304 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.browser-globals.service.ts +15 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.errors.ts +17 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.evolution-launch.service.ts +56 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.evolution-loop.service.ts +19 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.lifecycle.service.ts +96 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.startup.service.ts +92 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.telemetry.service.ts +24 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.ts +31 -121
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.types.ts +65 -0
- package/test/examples/flappy_bird/browser-entry/visualization/README.md +568 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.colors.utils.ts +26 -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 +979 -19
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.legend.utils.ts +157 -3
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.topology.utils.ts +13 -27
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.ts +7 -20
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.types.ts +14 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +238 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.errors.ts +11 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.generation.service.ts +12 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.playback.service.test.ts +143 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.playback.service.ts +140 -14
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.request.service.ts +27 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.ts +8 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.types.ts +23 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.url.service.ts +5 -0
- package/test/examples/flappy_bird/constants/README.md +1163 -0
- package/test/examples/flappy_bird/constants/constants.birds.ts +16 -38
- package/test/examples/flappy_bird/constants/constants.difficulty.ts +21 -0
- package/test/examples/flappy_bird/constants/constants.network-view.ts +24 -0
- package/test/examples/flappy_bird/constants/constants.network.ts +1 -1
- package/test/examples/flappy_bird/constants/constants.observation.ts +7 -0
- package/test/examples/flappy_bird/constants/constants.palette.ts +9 -2
- package/test/examples/flappy_bird/constants/constants.physics.ts +9 -0
- package/test/examples/flappy_bird/constants/constants.pipe-render.ts +3 -0
- package/test/examples/flappy_bird/constants/constants.pipes.ts +22 -3
- package/test/examples/flappy_bird/constants/constants.runtime.ts +28 -4
- package/test/examples/flappy_bird/constants/constants.starfield.ts +78 -3
- package/test/examples/flappy_bird/constants/constants.ts +6 -0
- package/test/examples/flappy_bird/environment/README.md +182 -0
- package/test/examples/flappy_bird/environment/environment.collision.utils.ts +7 -0
- package/test/examples/flappy_bird/environment/environment.constants.ts +16 -3
- package/test/examples/flappy_bird/environment/environment.observation.utils.ts +12 -19
- package/test/examples/flappy_bird/environment/environment.state.service.ts +10 -0
- package/test/examples/flappy_bird/environment/environment.step.service.ts +15 -66
- package/test/examples/flappy_bird/environment/environment.types.ts +14 -0
- package/test/examples/flappy_bird/evaluation/README.md +155 -0
- package/test/examples/flappy_bird/evaluation/evaluation.constants.ts +23 -4
- package/test/examples/flappy_bird/evaluation/evaluation.fitness.utils.ts +16 -1
- package/test/examples/flappy_bird/evaluation/evaluation.rollout.service.ts +7 -374
- package/test/examples/flappy_bird/evaluation/evaluation.seed.utils.ts +4 -0
- package/test/examples/flappy_bird/evaluation/evaluation.types.ts +18 -2
- package/test/examples/flappy_bird/evaluation/rollout/README.md +355 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.constants.ts +38 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.service.ts +71 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.services.ts +338 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.types.ts +69 -0
- package/test/examples/flappy_bird/evaluation/rollout/evaluation.rollout.utils.ts +399 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/README.md +845 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.constants.ts +49 -7
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.errors.ts +34 -3
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.evolution.service.ts +22 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.playback.service.ts +62 -26
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.protocol.service.ts +27 -1
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.runtime.service.ts +23 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.frame.service.ts +378 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.types.ts +22 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.utils.ts +20 -203
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.snapshot.utils.test.ts +94 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.snapshot.utils.ts +78 -13
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.ts +235 -344
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.types.ts +170 -22
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.warm-start.service.ts +314 -0
- package/test/examples/flappy_bird/flappy.simulation.shared.utils.ts +17 -0
- package/test/examples/flappy_bird/flappyEnvironment.ts +21 -0
- package/test/examples/flappy_bird/flappyEvaluation.ts +12 -0
- package/test/examples/flappy_bird/flappyEvolution.worker.ts +7 -0
- package/test/examples/flappy_bird/index.ts +8 -2
- package/test/examples/flappy_bird/rng.ts +10 -0
- package/test/examples/flappy_bird/simulation-shared/README.md +518 -0
- package/test/examples/flappy_bird/simulation-shared/observation/README.md +255 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.features.utils.ts +339 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.ts +19 -0
- package/test/examples/flappy_bird/simulation-shared/observation/observation.vector.utils.ts +81 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.constants.ts +3 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.control.utils.ts +6 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.difficulty.utils.ts +9 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.errors.ts +10 -1
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.memory.utils.ts +18 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.observation.utils.ts +7 -402
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.spawn.utils.ts +36 -6
- package/test/examples/flappy_bird/{evaluation/evaluation.statistics.utils.ts → simulation-shared/simulation-shared.statistics.utils.ts} +30 -9
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.types.ts +38 -5
- package/test/examples/flappy_bird/trainFlappyBird.ts +13 -0
- package/test/examples/flappy_bird/trainer/README.md +676 -0
- package/test/examples/flappy_bird/trainer/evaluation/README.md +253 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.constants.ts +15 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.services.ts +86 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.ts +187 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.types.ts +32 -0
- package/test/examples/flappy_bird/trainer/evaluation/trainer.evaluation.service.utils.ts +182 -0
- package/test/examples/flappy_bird/trainer/trainer.evaluation.service.ts +13 -0
- package/test/examples/flappy_bird/trainer/trainer.fitness.service.ts +23 -1
- package/test/examples/flappy_bird/trainer/trainer.loop.service.ts +17 -1
- package/test/examples/flappy_bird/trainer/trainer.report.service.services.ts +181 -0
- package/test/examples/flappy_bird/trainer/trainer.report.service.ts +136 -0
- package/test/examples/flappy_bird/trainer/trainer.selection.utils.ts +89 -0
- package/test/examples/flappy_bird/trainer/trainer.setup.service.ts +22 -0
- package/test/examples/flappy_bird/trainer/trainer.signals.service.ts +8 -0
- package/test/examples/flappy_bird/trainer/trainer.ts +38 -553
- package/test/examples/flappy_bird/trainer/trainer.types.ts +44 -7
- package/test/neat/neat.topology-intent.test.ts +129 -0
- package/test/network/network.topology-intent.test.ts +44 -0
- 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
|
@@ -1,717 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveAliveBirdCount,
|
|
3
|
-
resolveLeaderPipesPassed,
|
|
4
|
-
} from './browser-entry.observation.utils';
|
|
5
|
-
import {
|
|
6
|
-
resolveVisibleWorldHeightPx,
|
|
7
|
-
resolveVisibleWorldWidthPx,
|
|
8
|
-
resolveWorldViewport,
|
|
9
|
-
} from './browser-entry.viewport.utils';
|
|
10
|
-
import { requestWorkerPlaybackStep } from './worker-channel/worker-channel';
|
|
11
|
-
import {
|
|
12
|
-
FLAPPY_EMULATION_SPEED_MULTIPLIER,
|
|
13
|
-
FLAPPY_BIRD_VIEWPORT_X_RATIO,
|
|
14
|
-
FLAPPY_BIRD_CHAMPION_SHINE_FILL_STYLE,
|
|
15
|
-
FLAPPY_BIRD_CHAMPION_SHINE_GLOW_COLOR,
|
|
16
|
-
FLAPPY_BIRD_SHINE_FILL_STYLE,
|
|
17
|
-
FLAPPY_BIRD_SHINE_INSET_RATIO,
|
|
18
|
-
FLAPPY_BIRD_SHINE_SIZE_RATIO,
|
|
19
|
-
FLAPPY_BIRD_WHITE_SHINE_GLOW_COLOR,
|
|
20
|
-
FLAPPY_BIRD_WHITE_SHINE_GLOW_BLUR_PX,
|
|
21
|
-
FLAPPY_BIRD_AURA_ALPHA,
|
|
22
|
-
FLAPPY_BIRD_AURA_BLUR_MULTIPLIER,
|
|
23
|
-
FLAPPY_BIRD_AURA_EXPAND_PX,
|
|
24
|
-
FLAPPY_BIRD_BODY_GLOW_BLUR_PX,
|
|
25
|
-
FLAPPY_BIRD_CHAMPION_EXTRA_GLOW_BLUR_PX,
|
|
26
|
-
FLAPPY_BIRD_CHAMPION_RED_GLOW_ALPHA,
|
|
27
|
-
FLAPPY_BIRD_CHAMPION_RED_GLOW_EXPAND_PX,
|
|
28
|
-
FLAPPY_LEADER_RING_LINE_WIDTH_PX,
|
|
29
|
-
FLAPPY_LEADER_RING_GLOW_BLUR_PX,
|
|
30
|
-
FLAPPY_LEADER_RING_RADIUS_OFFSET_PX,
|
|
31
|
-
FLAPPY_NON_CHAMPION_OPACITY,
|
|
32
|
-
FLAPPY_TRAIL_LINE_WIDTH_PX,
|
|
33
|
-
FLAPPY_TRAIL_MIN_HORIZONTAL_SEGMENT_PX,
|
|
34
|
-
FLAPPY_TRAIL_MIN_VERTICAL_SEGMENT_PX,
|
|
35
|
-
FLAPPY_NEON_PALETTE,
|
|
36
|
-
} from '../constants/constants';
|
|
37
|
-
import type {
|
|
38
|
-
EvolutionPlaybackStepSnapshot,
|
|
39
|
-
PlaybackFrameStats,
|
|
40
|
-
PopulationRenderState,
|
|
41
|
-
TrailPoint,
|
|
42
|
-
TrailState,
|
|
43
|
-
} from './browser-entry.types';
|
|
44
|
-
import {
|
|
45
|
-
FLAPPY_PIPE_SPEED_PX_PER_FRAME,
|
|
46
|
-
FLAPPY_PIPE_WIDTH_PX,
|
|
47
|
-
FLAPPY_BIRD_X_PX,
|
|
48
|
-
FLAPPY_BIRD_RADIUS_PX,
|
|
49
|
-
FLAPPY_TRAIL_OPACITY_FACTOR,
|
|
50
|
-
} from '../constants/constants';
|
|
51
|
-
import { nextAnimationFrame } from './playback/playback.loop.service';
|
|
52
|
-
import { resolveStarfieldTiles } from './playback/playback.starfield.service';
|
|
53
|
-
import { positiveModulo } from './playback/playback.starfield.utils';
|
|
54
|
-
import {
|
|
55
|
-
pushTrailPoint,
|
|
56
|
-
resolveEdgeOpacityFactor,
|
|
57
|
-
resolveTrailLifetimeOpacityFactor,
|
|
58
|
-
} from './playback/playback.trail.utils';
|
|
59
|
-
import type { PlaybackEdgeBounds } from './playback/playback.types';
|
|
60
|
-
import {
|
|
61
|
-
resolvePlaybackCompletionSummary,
|
|
62
|
-
resolvePlaybackFrameStats,
|
|
63
|
-
resolvePlaybackStepRequest,
|
|
64
|
-
} from './playback/playback.worker-channel.utils';
|
|
65
|
-
import {
|
|
66
|
-
resolveBirdRenderStyle,
|
|
67
|
-
resolveChampionBirdIndex,
|
|
68
|
-
} from './playback/playback.render.utils';
|
|
69
|
-
import { drawPipeNeonOutline } from './playback/playback.render.service';
|
|
70
|
-
|
|
71
1
|
/**
|
|
72
|
-
*
|
|
2
|
+
* Compatibility facade for the browser-entry playback boundary.
|
|
73
3
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* @returns Aggregate playback summary.
|
|
4
|
+
* Older imports still reach playback through this file, while the real
|
|
5
|
+
* implementation now lives in the dedicated playback folder. Keeping the facade
|
|
6
|
+
* explicit preserves stable imports while letting the playback subsystem grow
|
|
7
|
+
* into a clearer module boundary.
|
|
79
8
|
*/
|
|
80
|
-
export
|
|
81
|
-
canvas: HTMLCanvasElement,
|
|
82
|
-
context: CanvasRenderingContext2D,
|
|
83
|
-
evolutionWorker: Worker,
|
|
84
|
-
onFrameStats: (stats: PlaybackFrameStats) => void,
|
|
85
|
-
): Promise<{
|
|
86
|
-
averagePipesPassed: number;
|
|
87
|
-
p90FramesSurvived: number;
|
|
88
|
-
winnerPipesPassed: number;
|
|
89
|
-
winnerFramesSurvived: number;
|
|
90
|
-
}> {
|
|
91
|
-
// Step 1: Initialize worker playback state with current viewport width.
|
|
92
|
-
evolutionWorker.postMessage({
|
|
93
|
-
type: 'start-playback',
|
|
94
|
-
payload: {
|
|
95
|
-
visibleWorldWidthPx: resolveVisibleWorldWidthPx(canvas),
|
|
96
|
-
visibleWorldHeightPx: resolveVisibleWorldHeightPx(canvas),
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// Step 2: Initialize local render/trail state mirrors.
|
|
101
|
-
const renderState: PopulationRenderState = {
|
|
102
|
-
frameIndex: 0,
|
|
103
|
-
visibleWorldWidthPx: resolveVisibleWorldWidthPx(canvas),
|
|
104
|
-
visibleWorldHeightPx: resolveVisibleWorldHeightPx(canvas),
|
|
105
|
-
nextPipeId: 0,
|
|
106
|
-
lastSpawnedPipeGapPx: 0,
|
|
107
|
-
lastSpawnedPipeGapCenterYPx: 0,
|
|
108
|
-
lastSpawnedPipeSpawnIntervalFrames: 0,
|
|
109
|
-
framesUntilNextPipeSpawn: 0,
|
|
110
|
-
pipes: [],
|
|
111
|
-
birds: [],
|
|
112
|
-
};
|
|
113
|
-
const trailState: TrailState = {
|
|
114
|
-
birdTrailsY: [],
|
|
115
|
-
};
|
|
116
|
-
let simulationFrameBudget = 0;
|
|
117
|
-
let finished = false;
|
|
118
|
-
let averagePipesPassed = 0;
|
|
119
|
-
let p90FramesSurvived = 0;
|
|
120
|
-
let winnerPipesPassed = 0;
|
|
121
|
-
let winnerFramesSurvived = 0;
|
|
122
|
-
let latestLeaderPipesPassed = 0;
|
|
123
|
-
let latestLeaderFramesSurvived = 0;
|
|
124
|
-
|
|
125
|
-
// Step 3: Run playback batches until worker reports completion.
|
|
126
|
-
while (!finished) {
|
|
127
|
-
// Step 3.1: Resolve frame budget and request one playback step batch.
|
|
128
|
-
renderState.visibleWorldWidthPx = resolveVisibleWorldWidthPx(canvas);
|
|
129
|
-
renderState.visibleWorldHeightPx = resolveVisibleWorldHeightPx(canvas);
|
|
130
|
-
const { simulationFrameBudgetRemainder, playbackStepRequest } =
|
|
131
|
-
resolvePlaybackStepRequest({
|
|
132
|
-
simulationFrameBudget,
|
|
133
|
-
visibleWorldWidthPx: renderState.visibleWorldWidthPx,
|
|
134
|
-
visibleWorldHeightPx: renderState.visibleWorldHeightPx,
|
|
135
|
-
emulationSpeedMultiplier: FLAPPY_EMULATION_SPEED_MULTIPLIER,
|
|
136
|
-
});
|
|
137
|
-
simulationFrameBudget = simulationFrameBudgetRemainder;
|
|
138
|
-
|
|
139
|
-
const playbackStepPayload = await requestWorkerPlaybackStep(
|
|
140
|
-
evolutionWorker,
|
|
141
|
-
playbackStepRequest,
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
// Step 3.2: Apply state snapshot and update visual trail cache.
|
|
145
|
-
applyPlaybackSnapshot(renderState, playbackStepPayload.snapshot);
|
|
146
|
-
updateTrailState(trailState, renderState);
|
|
147
|
-
|
|
148
|
-
// Step 3.3: Resolve leader metrics and emit frame telemetry.
|
|
149
|
-
const leaderPipesPassed = resolveLeaderPipesPassed(renderState.birds);
|
|
150
|
-
const leaderFramesSurvived = resolveLeaderFramesSurvived(renderState);
|
|
151
|
-
latestLeaderPipesPassed = leaderPipesPassed;
|
|
152
|
-
latestLeaderFramesSurvived = leaderFramesSurvived;
|
|
153
|
-
onFrameStats(
|
|
154
|
-
resolvePlaybackFrameStats(
|
|
155
|
-
playbackStepPayload,
|
|
156
|
-
renderState.frameIndex,
|
|
157
|
-
resolveAliveBirdCount(renderState.birds),
|
|
158
|
-
leaderPipesPassed,
|
|
159
|
-
leaderFramesSurvived,
|
|
160
|
-
),
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
// Step 3.4: Fold end-of-playback aggregates when worker signals done.
|
|
164
|
-
if (playbackStepPayload.done) {
|
|
165
|
-
const playbackCompletionSummary = resolvePlaybackCompletionSummary(
|
|
166
|
-
playbackStepPayload,
|
|
167
|
-
latestLeaderPipesPassed,
|
|
168
|
-
latestLeaderFramesSurvived,
|
|
169
|
-
);
|
|
170
|
-
finished = true;
|
|
171
|
-
averagePipesPassed = playbackCompletionSummary.averagePipesPassed;
|
|
172
|
-
p90FramesSurvived = playbackCompletionSummary.p90FramesSurvived;
|
|
173
|
-
winnerPipesPassed = playbackCompletionSummary.winnerPipesPassed;
|
|
174
|
-
winnerFramesSurvived = playbackCompletionSummary.winnerFramesSurvived;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Step 3.5: Render frame and yield to browser RAF when still active.
|
|
178
|
-
renderPopulationFrame(context, renderState, trailState);
|
|
179
|
-
if (!finished) {
|
|
180
|
-
await nextAnimationFrame();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Step 4: Render final settled frame and return aggregate summary.
|
|
185
|
-
renderPopulationFrame(context, renderState, trailState);
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
averagePipesPassed,
|
|
189
|
-
p90FramesSurvived,
|
|
190
|
-
winnerPipesPassed,
|
|
191
|
-
winnerFramesSurvived,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Applies worker snapshot data to the local render state.
|
|
197
|
-
*
|
|
198
|
-
* @param renderState - Mutable render state.
|
|
199
|
-
* @param snapshot - Worker playback snapshot.
|
|
200
|
-
* @returns Nothing.
|
|
201
|
-
*/
|
|
202
|
-
function applyPlaybackSnapshot(
|
|
203
|
-
renderState: PopulationRenderState,
|
|
204
|
-
snapshot: EvolutionPlaybackStepSnapshot,
|
|
205
|
-
): void {
|
|
206
|
-
renderState.frameIndex = snapshot.frameIndex;
|
|
207
|
-
renderState.visibleWorldWidthPx = snapshot.visibleWorldWidthPx;
|
|
208
|
-
renderState.visibleWorldHeightPx = snapshot.visibleWorldHeightPx;
|
|
209
|
-
renderState.pipes = snapshot.pipes;
|
|
210
|
-
renderState.birds = snapshot.birds.map((birdSnapshot) => ({
|
|
211
|
-
color: birdSnapshot.color,
|
|
212
|
-
yPx: birdSnapshot.yPx,
|
|
213
|
-
pipesPassed: birdSnapshot.pipesPassed,
|
|
214
|
-
framesSurvived: birdSnapshot.framesSurvived,
|
|
215
|
-
done: birdSnapshot.done,
|
|
216
|
-
}));
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Draws one simulation frame for the current population state.
|
|
221
|
-
*
|
|
222
|
-
* @param context - Canvas 2D drawing context.
|
|
223
|
-
* @param renderState - Mutable simulation state snapshot.
|
|
224
|
-
* @param trailState - Leader trail render cache.
|
|
225
|
-
* @returns Nothing.
|
|
226
|
-
*/
|
|
227
|
-
function renderPopulationFrame(
|
|
228
|
-
context: CanvasRenderingContext2D,
|
|
229
|
-
renderState: PopulationRenderState,
|
|
230
|
-
trailState: TrailState,
|
|
231
|
-
): void {
|
|
232
|
-
// Step 1: Resolve viewport transform and clear target canvas.
|
|
233
|
-
const viewport = resolveWorldViewport(context.canvas);
|
|
234
|
-
const visibleWorldWidthPx = Math.max(1, renderState.visibleWorldWidthPx);
|
|
235
|
-
const visibleWorldHeightPx = Math.max(1, renderState.visibleWorldHeightPx);
|
|
236
|
-
const desiredBirdScreenXPx =
|
|
237
|
-
visibleWorldWidthPx * FLAPPY_BIRD_VIEWPORT_X_RATIO;
|
|
238
|
-
const cameraLeftPx = FLAPPY_BIRD_X_PX - desiredBirdScreenXPx;
|
|
239
|
-
|
|
240
|
-
// Reset state that can suppress shadows between frames.
|
|
241
|
-
context.globalAlpha = 1;
|
|
242
|
-
context.globalCompositeOperation = 'source-over';
|
|
243
|
-
context.shadowBlur = 0;
|
|
244
|
-
context.shadowColor = 'transparent';
|
|
245
|
-
context.shadowOffsetX = 0;
|
|
246
|
-
context.shadowOffsetY = 0;
|
|
247
|
-
|
|
248
|
-
context.clearRect(0, 0, context.canvas.width, context.canvas.height);
|
|
249
|
-
|
|
250
|
-
context.save();
|
|
251
|
-
context.translate(viewport.offsetXPx, viewport.offsetYPx);
|
|
252
|
-
context.scale(viewport.scale, viewport.scale);
|
|
253
|
-
context.translate(-cameraLeftPx, 0);
|
|
254
|
-
|
|
255
|
-
// Step 2: Draw Radiant-style parallax background.
|
|
256
|
-
drawParallaxBackground(context, renderState);
|
|
257
|
-
|
|
258
|
-
// Step 3: Draw pipes with neon outlines.
|
|
259
|
-
for (const pipe of renderState.pipes) {
|
|
260
|
-
const gapHalf = pipe.gapSizePx * 0.5;
|
|
261
|
-
const pipeLeft = pipe.xPx;
|
|
262
|
-
const gapTop = pipe.gapCenterYPx - gapHalf;
|
|
263
|
-
const gapBottom = pipe.gapCenterYPx + gapHalf;
|
|
264
|
-
|
|
265
|
-
context.fillStyle = FLAPPY_NEON_PALETTE.pipeFill;
|
|
266
|
-
context.fillRect(pipeLeft, 0, FLAPPY_PIPE_WIDTH_PX, gapTop);
|
|
267
|
-
drawPipeNeonOutline(context, pipeLeft, 0, FLAPPY_PIPE_WIDTH_PX, gapTop);
|
|
268
|
-
context.fillRect(
|
|
269
|
-
pipeLeft,
|
|
270
|
-
gapBottom,
|
|
271
|
-
FLAPPY_PIPE_WIDTH_PX,
|
|
272
|
-
visibleWorldHeightPx - gapBottom,
|
|
273
|
-
);
|
|
274
|
-
drawPipeNeonOutline(
|
|
275
|
-
context,
|
|
276
|
-
pipeLeft,
|
|
277
|
-
gapBottom,
|
|
278
|
-
FLAPPY_PIPE_WIDTH_PX,
|
|
279
|
-
visibleWorldHeightPx - gapBottom,
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Step 4: Resolve champion bird and render bird bodies/shine/rings.
|
|
284
|
-
const championBirdIndex = resolveChampionBirdIndex(renderState);
|
|
285
|
-
|
|
286
|
-
renderState.birds.forEach((bird, birdIndex) => {
|
|
287
|
-
if (bird.done) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const birdSideLengthPx = Math.max(1, Math.round(FLAPPY_BIRD_RADIUS_PX * 2));
|
|
292
|
-
const birdLeftPx = Math.round(FLAPPY_BIRD_X_PX - FLAPPY_BIRD_RADIUS_PX);
|
|
293
|
-
const birdTopPx = Math.round(bird.yPx - FLAPPY_BIRD_RADIUS_PX);
|
|
294
|
-
const { birdOpacity, birdRenderColor, isChampionBird } =
|
|
295
|
-
resolveBirdRenderStyle(birdIndex, championBirdIndex);
|
|
296
|
-
|
|
297
|
-
// Step 4.1: Add a soft Radiant-style aura plate behind the champion bird.
|
|
298
|
-
if (isChampionBird) {
|
|
299
|
-
const auraExpandPx = Math.round(FLAPPY_BIRD_AURA_EXPAND_PX);
|
|
300
|
-
const previousCompositeOperation = context.globalCompositeOperation;
|
|
301
|
-
context.globalCompositeOperation = 'lighter';
|
|
302
|
-
context.globalAlpha = birdOpacity * FLAPPY_BIRD_AURA_ALPHA;
|
|
303
|
-
context.fillStyle = birdRenderColor;
|
|
304
|
-
context.shadowColor = birdRenderColor;
|
|
305
|
-
context.shadowBlur = Math.round(
|
|
306
|
-
FLAPPY_BIRD_BODY_GLOW_BLUR_PX * FLAPPY_BIRD_AURA_BLUR_MULTIPLIER,
|
|
307
|
-
);
|
|
308
|
-
context.fillRect(
|
|
309
|
-
birdLeftPx - auraExpandPx,
|
|
310
|
-
birdTopPx - auraExpandPx,
|
|
311
|
-
birdSideLengthPx + auraExpandPx * 2,
|
|
312
|
-
birdSideLengthPx + auraExpandPx * 2,
|
|
313
|
-
);
|
|
314
|
-
context.shadowBlur = 0;
|
|
315
|
-
context.shadowColor = 'transparent';
|
|
316
|
-
context.globalCompositeOperation = previousCompositeOperation;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (isChampionBird) {
|
|
320
|
-
const expandedGlowInsetPx = Math.round(
|
|
321
|
-
FLAPPY_BIRD_CHAMPION_RED_GLOW_EXPAND_PX,
|
|
322
|
-
);
|
|
323
|
-
context.globalAlpha = birdOpacity * FLAPPY_BIRD_CHAMPION_RED_GLOW_ALPHA;
|
|
324
|
-
context.fillStyle = FLAPPY_NEON_PALETTE.championBird;
|
|
325
|
-
context.shadowColor = FLAPPY_NEON_PALETTE.championBird;
|
|
326
|
-
context.shadowBlur =
|
|
327
|
-
FLAPPY_BIRD_BODY_GLOW_BLUR_PX + FLAPPY_BIRD_CHAMPION_EXTRA_GLOW_BLUR_PX;
|
|
328
|
-
context.fillRect(
|
|
329
|
-
birdLeftPx - expandedGlowInsetPx,
|
|
330
|
-
birdTopPx - expandedGlowInsetPx,
|
|
331
|
-
birdSideLengthPx + expandedGlowInsetPx * 2,
|
|
332
|
-
birdSideLengthPx + expandedGlowInsetPx * 2,
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
context.globalAlpha = birdOpacity;
|
|
337
|
-
context.fillStyle = birdRenderColor;
|
|
338
|
-
context.shadowColor = birdRenderColor;
|
|
339
|
-
context.shadowBlur =
|
|
340
|
-
FLAPPY_BIRD_BODY_GLOW_BLUR_PX +
|
|
341
|
-
(isChampionBird ? FLAPPY_BIRD_CHAMPION_EXTRA_GLOW_BLUR_PX : 0);
|
|
342
|
-
context.fillRect(birdLeftPx, birdTopPx, birdSideLengthPx, birdSideLengthPx);
|
|
343
|
-
|
|
344
|
-
const shineInsetPx = birdSideLengthPx * FLAPPY_BIRD_SHINE_INSET_RATIO;
|
|
345
|
-
const shineSideLengthPx = Math.max(
|
|
346
|
-
1,
|
|
347
|
-
birdSideLengthPx * FLAPPY_BIRD_SHINE_SIZE_RATIO,
|
|
348
|
-
);
|
|
349
|
-
context.fillStyle = isChampionBird
|
|
350
|
-
? FLAPPY_BIRD_CHAMPION_SHINE_FILL_STYLE
|
|
351
|
-
: FLAPPY_BIRD_SHINE_FILL_STYLE;
|
|
352
|
-
context.shadowColor = isChampionBird
|
|
353
|
-
? FLAPPY_BIRD_CHAMPION_SHINE_GLOW_COLOR
|
|
354
|
-
: FLAPPY_BIRD_WHITE_SHINE_GLOW_COLOR;
|
|
355
|
-
context.shadowBlur = FLAPPY_BIRD_WHITE_SHINE_GLOW_BLUR_PX;
|
|
356
|
-
context.fillRect(
|
|
357
|
-
Math.round(birdLeftPx + shineInsetPx),
|
|
358
|
-
Math.round(birdTopPx + shineInsetPx),
|
|
359
|
-
Math.round(shineSideLengthPx),
|
|
360
|
-
Math.round(shineSideLengthPx),
|
|
361
|
-
);
|
|
362
|
-
context.shadowBlur = 0;
|
|
363
|
-
context.shadowColor = 'transparent';
|
|
364
|
-
|
|
365
|
-
if (isChampionBird) {
|
|
366
|
-
context.strokeStyle = FLAPPY_NEON_PALETTE.leaderRing;
|
|
367
|
-
context.lineWidth = FLAPPY_LEADER_RING_LINE_WIDTH_PX;
|
|
368
|
-
context.shadowColor = FLAPPY_NEON_PALETTE.leaderRing;
|
|
369
|
-
context.shadowBlur = FLAPPY_LEADER_RING_GLOW_BLUR_PX;
|
|
370
|
-
const leaderRingInsetPx = Math.round(FLAPPY_LEADER_RING_RADIUS_OFFSET_PX);
|
|
371
|
-
context.strokeRect(
|
|
372
|
-
birdLeftPx - leaderRingInsetPx,
|
|
373
|
-
birdTopPx - leaderRingInsetPx,
|
|
374
|
-
birdSideLengthPx + leaderRingInsetPx * 2,
|
|
375
|
-
birdSideLengthPx + leaderRingInsetPx * 2,
|
|
376
|
-
);
|
|
377
|
-
context.shadowBlur = 0;
|
|
378
|
-
context.shadowColor = 'transparent';
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
// Step 5: Draw stepped trails for active birds.
|
|
383
|
-
renderState.birds.forEach((bird, birdIndex) => {
|
|
384
|
-
if (bird.done) {
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const birdTrailPoints = trailState.birdTrailsY[birdIndex];
|
|
389
|
-
if (!birdTrailPoints || birdTrailPoints.length === 0) {
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const parentBirdOpacity =
|
|
394
|
-
birdIndex === championBirdIndex ? 1 : FLAPPY_NON_CHAMPION_OPACITY;
|
|
395
|
-
const birdTrailColor =
|
|
396
|
-
birdIndex === championBirdIndex
|
|
397
|
-
? FLAPPY_NEON_PALETTE.trail
|
|
398
|
-
: FLAPPY_NEON_PALETTE.nonChampionBird;
|
|
399
|
-
|
|
400
|
-
drawTrail(
|
|
401
|
-
context,
|
|
402
|
-
birdTrailPoints,
|
|
403
|
-
birdTrailColor,
|
|
404
|
-
FLAPPY_BIRD_X_PX - FLAPPY_BIRD_RADIUS_PX,
|
|
405
|
-
parentBirdOpacity * FLAPPY_TRAIL_OPACITY_FACTOR,
|
|
406
|
-
{
|
|
407
|
-
leftXPx: cameraLeftPx,
|
|
408
|
-
rightXPx: cameraLeftPx + visibleWorldWidthPx,
|
|
409
|
-
topYPx: 0,
|
|
410
|
-
bottomYPx: visibleWorldHeightPx,
|
|
411
|
-
},
|
|
412
|
-
);
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
context.globalAlpha = 1;
|
|
416
|
-
// Step 6: Restore context to pre-viewport transform state.
|
|
417
|
-
context.restore();
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
function drawParallaxBackground(
|
|
421
|
-
context: CanvasRenderingContext2D,
|
|
422
|
-
renderState: PopulationRenderState,
|
|
423
|
-
): void {
|
|
424
|
-
const visibleWorldWidthPx = Math.max(
|
|
425
|
-
1,
|
|
426
|
-
Math.round(renderState.visibleWorldWidthPx),
|
|
427
|
-
);
|
|
428
|
-
const scrollBasePx = renderState.frameIndex * FLAPPY_PIPE_SPEED_PX_PER_FRAME;
|
|
429
|
-
|
|
430
|
-
// Step 1: Paint the background fill.
|
|
431
|
-
context.globalAlpha = 1;
|
|
432
|
-
context.globalCompositeOperation = 'source-over';
|
|
433
|
-
context.shadowBlur = 0;
|
|
434
|
-
context.shadowColor = 'transparent';
|
|
435
|
-
context.fillStyle = FLAPPY_NEON_PALETTE.background;
|
|
436
|
-
const visibleWorldHeightPx = Math.max(
|
|
437
|
-
1,
|
|
438
|
-
Math.round(renderState.visibleWorldHeightPx),
|
|
439
|
-
);
|
|
440
|
-
context.fillRect(0, 0, visibleWorldWidthPx, visibleWorldHeightPx);
|
|
441
|
-
|
|
442
|
-
// Step 2: Draw cached square-particle starfield layers with subtle parallax.
|
|
443
|
-
// Each layer is pre-rendered into a tile and repeated via drawImage, which is
|
|
444
|
-
// much faster than drawing dozens of blurred particles every frame.
|
|
445
|
-
context.globalCompositeOperation = 'lighter';
|
|
446
|
-
const starfieldTiles = resolveStarfieldTiles(visibleWorldHeightPx);
|
|
447
|
-
for (const tile of starfieldTiles) {
|
|
448
|
-
const scrollOffsetPx = scrollBasePx * tile.scrollRatio;
|
|
449
|
-
drawTiledImageRow(context, {
|
|
450
|
-
tile: tile.image,
|
|
451
|
-
tileWidthPx: tile.tileWidthPx,
|
|
452
|
-
visibleWidthPx: visibleWorldWidthPx,
|
|
453
|
-
offsetPx: scrollOffsetPx,
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
context.globalCompositeOperation = 'source-over';
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
function drawTiledImageRow(
|
|
460
|
-
context: CanvasRenderingContext2D,
|
|
461
|
-
layer: {
|
|
462
|
-
tile: CanvasImageSource;
|
|
463
|
-
tileWidthPx: number;
|
|
464
|
-
visibleWidthPx: number;
|
|
465
|
-
offsetPx: number;
|
|
466
|
-
},
|
|
467
|
-
): void {
|
|
468
|
-
const normalizedOffsetPx = positiveModulo(layer.offsetPx, layer.tileWidthPx);
|
|
469
|
-
const maxTileIndex = Math.ceil(layer.visibleWidthPx / layer.tileWidthPx) + 1;
|
|
470
|
-
|
|
471
|
-
for (let tileIndex = -1; tileIndex <= maxTileIndex; tileIndex += 1) {
|
|
472
|
-
const tileLeftPx = tileIndex * layer.tileWidthPx - normalizedOffsetPx;
|
|
473
|
-
context.drawImage(layer.tile, tileLeftPx, 0);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Updates the trail cache from the latest frame snapshot.
|
|
479
|
-
*
|
|
480
|
-
* @param trailState - Mutable trail state.
|
|
481
|
-
* @param renderState - Current render state.
|
|
482
|
-
* @returns Nothing.
|
|
483
|
-
*/
|
|
484
|
-
function updateTrailState(
|
|
485
|
-
trailState: TrailState,
|
|
486
|
-
renderState: PopulationRenderState,
|
|
487
|
-
): void {
|
|
488
|
-
renderState.birds.forEach((bird, birdIndex) => {
|
|
489
|
-
if (!trailState.birdTrailsY[birdIndex]) {
|
|
490
|
-
trailState.birdTrailsY[birdIndex] = [];
|
|
491
|
-
}
|
|
492
|
-
const birdTrail = trailState.birdTrailsY[birdIndex];
|
|
493
|
-
|
|
494
|
-
if (bird.done) {
|
|
495
|
-
birdTrail.length = 0;
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
pushTrailPoint(birdTrail, renderState.frameIndex, bird.yPx);
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* Renders a stepped trail polyline.
|
|
505
|
-
*
|
|
506
|
-
* @param context - Canvas 2D context.
|
|
507
|
-
* @param trailPoints - Ordered trail points.
|
|
508
|
-
* @param color - Trail color.
|
|
509
|
-
* @param anchorX - Latest point x-anchor.
|
|
510
|
-
* @returns Nothing.
|
|
511
|
-
*/
|
|
512
|
-
function drawTrail(
|
|
513
|
-
context: CanvasRenderingContext2D,
|
|
514
|
-
trailPoints: TrailPoint[],
|
|
515
|
-
color: string,
|
|
516
|
-
anchorX: number,
|
|
517
|
-
baseOpacity: number,
|
|
518
|
-
edgeBounds: PlaybackEdgeBounds,
|
|
519
|
-
): void {
|
|
520
|
-
// Step 1: Guard empty trails.
|
|
521
|
-
if (trailPoints.length === 0) {
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
const latestTrailFrameIndex = trailPoints.at(-1)?.frameIndex ?? 0;
|
|
526
|
-
|
|
527
|
-
const firstTrailPoint = trailPoints[0];
|
|
528
|
-
const firstTrailFrameOffset = Math.max(
|
|
529
|
-
0,
|
|
530
|
-
latestTrailFrameIndex - firstTrailPoint.frameIndex,
|
|
531
|
-
);
|
|
532
|
-
let previousXPosition =
|
|
533
|
-
anchorX - firstTrailFrameOffset * FLAPPY_PIPE_SPEED_PX_PER_FRAME;
|
|
534
|
-
let previousYPosition = firstTrailPoint.yPx;
|
|
535
|
-
let previousFrameOffset = firstTrailFrameOffset;
|
|
536
|
-
const maxTrailFrameOffset = Math.max(1, firstTrailFrameOffset);
|
|
537
|
-
|
|
538
|
-
// Step 2: Configure trail stroke style.
|
|
539
|
-
const previousGlobalAlpha = context.globalAlpha;
|
|
540
|
-
context.strokeStyle = color;
|
|
541
|
-
context.lineWidth = FLAPPY_TRAIL_LINE_WIDTH_PX;
|
|
542
|
-
|
|
543
|
-
// Step 3: Render stepped segments with edge-proximity alpha fading.
|
|
544
|
-
trailPoints.slice(1).forEach((trailPoint) => {
|
|
545
|
-
const frameOffset = Math.max(
|
|
546
|
-
0,
|
|
547
|
-
latestTrailFrameIndex - trailPoint.frameIndex,
|
|
548
|
-
);
|
|
549
|
-
const nextXPosition =
|
|
550
|
-
anchorX - frameOffset * FLAPPY_PIPE_SPEED_PX_PER_FRAME;
|
|
551
|
-
const nextYPosition = trailPoint.yPx;
|
|
552
|
-
|
|
553
|
-
const horizontalDeltaPx = nextXPosition - previousXPosition;
|
|
554
|
-
const horizontalDirection = Math.sign(horizontalDeltaPx) || 1;
|
|
555
|
-
const steppedHorizontalLengthPx = Math.max(
|
|
556
|
-
Math.abs(horizontalDeltaPx),
|
|
557
|
-
FLAPPY_TRAIL_MIN_HORIZONTAL_SEGMENT_PX,
|
|
558
|
-
);
|
|
559
|
-
const steppedHorizontalXPosition =
|
|
560
|
-
previousXPosition + horizontalDirection * steppedHorizontalLengthPx;
|
|
561
|
-
drawTrailSegmentWithEdgeFade(
|
|
562
|
-
context,
|
|
563
|
-
previousXPosition,
|
|
564
|
-
previousYPosition,
|
|
565
|
-
steppedHorizontalXPosition,
|
|
566
|
-
previousYPosition,
|
|
567
|
-
baseOpacity,
|
|
568
|
-
edgeBounds,
|
|
569
|
-
previousFrameOffset,
|
|
570
|
-
frameOffset,
|
|
571
|
-
maxTrailFrameOffset,
|
|
572
|
-
);
|
|
573
|
-
previousXPosition = steppedHorizontalXPosition;
|
|
574
|
-
|
|
575
|
-
const verticalDeltaPx = nextYPosition - previousYPosition;
|
|
576
|
-
if (verticalDeltaPx !== 0) {
|
|
577
|
-
const verticalDirection = Math.sign(verticalDeltaPx);
|
|
578
|
-
const steppedVerticalLengthPx = Math.max(
|
|
579
|
-
Math.abs(verticalDeltaPx),
|
|
580
|
-
FLAPPY_TRAIL_MIN_VERTICAL_SEGMENT_PX,
|
|
581
|
-
);
|
|
582
|
-
const steppedVerticalYPosition =
|
|
583
|
-
previousYPosition + verticalDirection * steppedVerticalLengthPx;
|
|
584
|
-
drawTrailSegmentWithEdgeFade(
|
|
585
|
-
context,
|
|
586
|
-
previousXPosition,
|
|
587
|
-
previousYPosition,
|
|
588
|
-
steppedHorizontalXPosition,
|
|
589
|
-
steppedVerticalYPosition,
|
|
590
|
-
baseOpacity,
|
|
591
|
-
edgeBounds,
|
|
592
|
-
previousFrameOffset,
|
|
593
|
-
frameOffset,
|
|
594
|
-
maxTrailFrameOffset,
|
|
595
|
-
);
|
|
596
|
-
previousYPosition = steppedVerticalYPosition;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
drawTrailSegmentWithEdgeFade(
|
|
600
|
-
context,
|
|
601
|
-
previousXPosition,
|
|
602
|
-
previousYPosition,
|
|
603
|
-
steppedHorizontalXPosition,
|
|
604
|
-
nextYPosition,
|
|
605
|
-
baseOpacity,
|
|
606
|
-
edgeBounds,
|
|
607
|
-
previousFrameOffset,
|
|
608
|
-
frameOffset,
|
|
609
|
-
maxTrailFrameOffset,
|
|
610
|
-
);
|
|
611
|
-
previousYPosition = nextYPosition;
|
|
612
|
-
|
|
613
|
-
drawTrailSegmentWithEdgeFade(
|
|
614
|
-
context,
|
|
615
|
-
previousXPosition,
|
|
616
|
-
previousYPosition,
|
|
617
|
-
nextXPosition,
|
|
618
|
-
nextYPosition,
|
|
619
|
-
baseOpacity,
|
|
620
|
-
edgeBounds,
|
|
621
|
-
previousFrameOffset,
|
|
622
|
-
frameOffset,
|
|
623
|
-
maxTrailFrameOffset,
|
|
624
|
-
);
|
|
625
|
-
previousXPosition = nextXPosition;
|
|
626
|
-
previousYPosition = nextYPosition;
|
|
627
|
-
previousFrameOffset = frameOffset;
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
// Step 4: Restore caller alpha state.
|
|
631
|
-
context.globalAlpha = previousGlobalAlpha;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
/**
|
|
635
|
-
* Draws one trail segment with edge-aware alpha attenuation.
|
|
636
|
-
*
|
|
637
|
-
* @param context - Canvas 2D context.
|
|
638
|
-
* @param startXPx - Segment start x position.
|
|
639
|
-
* @param startYPx - Segment start y position.
|
|
640
|
-
* @param endXPx - Segment end x position.
|
|
641
|
-
* @param endYPx - Segment end y position.
|
|
642
|
-
* @param baseOpacity - Base trail opacity before edge fading.
|
|
643
|
-
* @param edgeBounds - Visible world bounds used for edge distance checks.
|
|
644
|
-
* @param startFrameOffset - Age offset at segment start (frames from latest).
|
|
645
|
-
* @param endFrameOffset - Age offset at segment end (frames from latest).
|
|
646
|
-
* @param maxTrailFrameOffset - Oldest age offset currently retained by the trail.
|
|
647
|
-
* @returns Nothing.
|
|
648
|
-
*/
|
|
649
|
-
function drawTrailSegmentWithEdgeFade(
|
|
650
|
-
context: CanvasRenderingContext2D,
|
|
651
|
-
startXPx: number,
|
|
652
|
-
startYPx: number,
|
|
653
|
-
endXPx: number,
|
|
654
|
-
endYPx: number,
|
|
655
|
-
baseOpacity: number,
|
|
656
|
-
edgeBounds: PlaybackEdgeBounds,
|
|
657
|
-
startFrameOffset: number,
|
|
658
|
-
endFrameOffset: number,
|
|
659
|
-
maxTrailFrameOffset: number,
|
|
660
|
-
): void {
|
|
661
|
-
const segmentLengthPx = Math.hypot(endXPx - startXPx, endYPx - startYPx);
|
|
662
|
-
if (segmentLengthPx === 0 || baseOpacity <= 0) {
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
// Step 1: Resolve edge-fade factor from both segment endpoints.
|
|
667
|
-
const startOpacityFactor = resolveEdgeOpacityFactor(
|
|
668
|
-
startXPx,
|
|
669
|
-
startYPx,
|
|
670
|
-
edgeBounds,
|
|
671
|
-
);
|
|
672
|
-
const endOpacityFactor = resolveEdgeOpacityFactor(endXPx, endYPx, edgeBounds);
|
|
673
|
-
const edgeOpacityFactor = Math.min(startOpacityFactor, endOpacityFactor);
|
|
674
|
-
|
|
675
|
-
// Step 2: Resolve lifetime fade so older trail history fades near cutoff.
|
|
676
|
-
const startLifetimeOpacityFactor = resolveTrailLifetimeOpacityFactor(
|
|
677
|
-
startFrameOffset,
|
|
678
|
-
maxTrailFrameOffset,
|
|
679
|
-
);
|
|
680
|
-
const endLifetimeOpacityFactor = resolveTrailLifetimeOpacityFactor(
|
|
681
|
-
endFrameOffset,
|
|
682
|
-
maxTrailFrameOffset,
|
|
683
|
-
);
|
|
684
|
-
const lifetimeOpacityFactor = Math.min(
|
|
685
|
-
startLifetimeOpacityFactor,
|
|
686
|
-
endLifetimeOpacityFactor,
|
|
687
|
-
);
|
|
688
|
-
|
|
689
|
-
const segmentOpacity =
|
|
690
|
-
baseOpacity * edgeOpacityFactor * lifetimeOpacityFactor;
|
|
691
|
-
if (segmentOpacity <= 0) {
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
// Step 3: Draw the segment with resolved opacity.
|
|
696
|
-
context.globalAlpha = segmentOpacity;
|
|
697
|
-
context.beginPath();
|
|
698
|
-
context.moveTo(startXPx, startYPx);
|
|
699
|
-
context.lineTo(endXPx, endYPx);
|
|
700
|
-
context.stroke();
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
/**
|
|
704
|
-
* Resolves the maximum survived-frame count in the current render state.
|
|
705
|
-
*
|
|
706
|
-
* @param renderState - Current render state.
|
|
707
|
-
* @returns Maximum frames survived.
|
|
708
|
-
*/
|
|
709
|
-
function resolveLeaderFramesSurvived(
|
|
710
|
-
renderState: PopulationRenderState,
|
|
711
|
-
): number {
|
|
712
|
-
return renderState.birds.reduce(
|
|
713
|
-
(maximumFramesSurvived, bird) =>
|
|
714
|
-
Math.max(maximumFramesSurvived, bird.framesSurvived),
|
|
715
|
-
0,
|
|
716
|
-
);
|
|
717
|
-
}
|
|
9
|
+
export { animatePopulationEpisodeInternal } from './playback/playback';
|