@inventure71/paddockjs 0.3.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +91 -0
- package/INSTALL_AND_UPDATE.md +5 -2
- package/README.md +328 -13
- package/docs/architecture.md +150 -41
- package/docs/concepts.md +22 -3
- package/docs/custom_model_controller.md +329 -0
- package/docs/data_contract.md +474 -34
- package/docs/data_model.md +1 -1
- package/docs/index.md +1 -0
- package/docs/learnings.md +23 -1
- package/docs/rules.md +169 -21
- package/docs/system_specs.md +56 -20
- package/docs/training.md +369 -25
- package/examples/python/README.md +62 -0
- package/examples/python/base_policy_server.py +191 -0
- package/examples/python/requirements.txt +2 -0
- package/examples/train-basic-policy.mjs +5 -6
- package/examples/trainingData.mjs +133 -0
- package/package.json +15 -4
- package/src/api/PaddockSimulatorController.js +36 -2
- package/src/app/BrowserExpertAdapter.js +367 -9
- package/src/app/F1SimulatorApp.js +615 -940
- package/src/app/banners/bannerFormatters.js +55 -0
- package/src/app/banners/raceDataBannerController.js +141 -0
- package/src/app/banners/stewardMessageController.js +99 -0
- package/src/app/camera/cameraConstants.js +21 -0
- package/src/app/camera/cameraController.js +265 -0
- package/src/app/camera/cameraGeometry.js +176 -0
- package/src/app/domBindings.js +14 -1
- package/src/app/readouts/carOverviewRenderer.js +109 -0
- package/src/app/readouts/controlStateRenderer.js +37 -0
- package/src/app/readouts/raceStatusRenderer.js +133 -0
- package/src/app/readouts/readoutFormatters.js +58 -0
- package/src/app/readouts/telemetryRenderer.js +113 -0
- package/src/app/readouts/timingTowerRenderer.js +177 -0
- package/src/app/rendering/appAssets.js +38 -0
- package/src/app/rendering/carRenderer.js +286 -0
- package/src/app/rendering/displayUtils.js +22 -0
- package/src/app/rendering/drsTrailRenderer.js +90 -0
- package/src/app/rendering/expertSensorRenderer.js +126 -0
- package/src/app/rendering/pitLaneStatusRenderer.js +50 -0
- package/src/app/rendering/replayGhostRenderer.js +124 -0
- package/src/app/rendering/trackRenderer.js +25 -0
- package/src/app/runtime/frameLoop.js +66 -0
- package/src/app/runtime/runtimeTiming.js +34 -0
- package/src/app/runtime/runtimeVisibility.js +45 -0
- package/src/config/defaultOptions.js +24 -4
- package/src/environment/actions.js +38 -7
- package/src/environment/controllerLoop.js +246 -0
- package/src/environment/episode.js +86 -2
- package/src/environment/evaluation.js +206 -0
- package/src/environment/index.d.ts +638 -6
- package/src/environment/index.js +14 -0
- package/src/environment/metrics.js +159 -0
- package/src/environment/observationOptions.js +33 -0
- package/src/environment/observations.js +500 -43
- package/src/environment/options.js +41 -2
- package/src/environment/recorder.js +28 -0
- package/src/environment/runtime.js +260 -24
- package/src/environment/scenarios.js +249 -0
- package/src/environment/sensors/bodySenses.js +23 -0
- package/src/environment/sensors/boundarySenses.js +17 -0
- package/src/environment/sensors/carRays.js +75 -0
- package/src/environment/sensors/contactSenses.js +32 -0
- package/src/environment/sensors/index.js +157 -0
- package/src/environment/sensors/indexedRayBands.js +103 -0
- package/src/environment/sensors/nearbyCars.js +52 -0
- package/src/environment/sensors/opponentRadar.js +65 -0
- package/src/environment/sensors/rayConfig.js +110 -0
- package/src/environment/sensors/rayDefaults.js +6 -0
- package/src/environment/sensors/rayGeometry.js +60 -0
- package/src/environment/sensors/rayGuards.js +19 -0
- package/src/environment/sensors/sensorTargets.js +60 -0
- package/src/environment/sensors/surfaceRays.js +296 -0
- package/src/environment/sensors/trackRays.js +261 -0
- package/src/environment/sensors.js +1 -257
- package/src/environment/specs.js +188 -9
- package/src/environment/workerProtocol.js +64 -0
- package/src/index.d.ts +533 -7
- package/src/index.js +26 -0
- package/src/rendering/proceduralTrackAsset.js +20 -510
- package/src/rendering/renderSnapshot.js +38 -12
- package/src/rendering/track/finishLineRenderer.js +34 -0
- package/src/rendering/track/gridRenderer.js +47 -0
- package/src/rendering/track/offsetStrokeSafety.js +136 -0
- package/src/rendering/track/pitLaneRenderer.js +248 -0
- package/src/rendering/track/trackMaterialRenderer.js +326 -0
- package/src/rendering/track/trackRenderConstants.js +38 -0
- package/src/rendering/track/trackRenderGeometry.js +94 -0
- package/src/simulation/collisionGeometry.js +214 -0
- package/src/simulation/driver/driverControlConstants.js +28 -0
- package/src/simulation/driver/driverController.js +47 -0
- package/src/simulation/driver/driverInput.js +28 -0
- package/src/simulation/driver/driverMath.js +6 -0
- package/src/simulation/driver/driverPersonality.js +25 -0
- package/src/simulation/driver/edgeRecovery.js +48 -0
- package/src/simulation/driver/racingControls.js +399 -0
- package/src/simulation/driver/racingLinePlan.js +166 -0
- package/src/simulation/driver/recoveryDynamics.js +38 -0
- package/src/simulation/driver/rejoinControls.js +213 -0
- package/src/simulation/driver/safetyCarControls.js +35 -0
- package/src/simulation/driver/trafficScan.js +51 -0
- package/src/simulation/driverController.js +4 -253
- package/src/simulation/participants/participantInteractions.js +120 -0
- package/src/simulation/pit/pitFlow.js +234 -0
- package/src/simulation/pit/pitIntent.js +92 -0
- package/src/simulation/pit/pitOccupancy.js +47 -0
- package/src/simulation/pit/pitPenaltyService.js +71 -0
- package/src/simulation/pit/pitQueue.js +55 -0
- package/src/simulation/pit/pitRouteMovement.js +160 -0
- package/src/simulation/pit/pitRouting.js +319 -0
- package/src/simulation/pit/pitService.js +41 -0
- package/src/simulation/pit/pitServiceConstants.js +21 -0
- package/src/simulation/pit/pitServiceProfile.js +45 -0
- package/src/simulation/pit/pitSnapshots.js +61 -0
- package/src/simulation/pit/pitState.js +113 -0
- package/src/simulation/pit/pitTireService.js +92 -0
- package/src/simulation/race/classification.js +104 -0
- package/src/simulation/race/gridPenalties.js +37 -0
- package/src/simulation/race/raceControlState.js +38 -0
- package/src/simulation/race/raceDistance.js +32 -0
- package/src/simulation/race/raceFinish.js +65 -0
- package/src/simulation/race/raceLifecycle.js +71 -0
- package/src/simulation/race/raceOrder.js +113 -0
- package/src/simulation/race/raceProgress.js +124 -0
- package/src/simulation/race/raceSetup.js +93 -0
- package/src/simulation/race/raceStep.js +80 -0
- package/src/simulation/race/redFlag.js +15 -0
- package/src/simulation/race/retirements.js +44 -0
- package/src/simulation/race/safetyCar.js +86 -0
- package/src/simulation/race/stalledDnf.js +86 -0
- package/src/simulation/raceSimulation.js +386 -1012
- package/src/simulation/replay/replayGhosts.js +128 -0
- package/src/simulation/rules/collisionSteward.js +69 -0
- package/src/simulation/rules/moduleConfig.js +72 -0
- package/src/simulation/rules/penaltyConfig.js +99 -0
- package/src/simulation/rules/penaltyEvents.js +18 -0
- package/src/simulation/rules/penaltyLedger.js +153 -0
- package/src/simulation/rules/penaltyStats.js +26 -0
- package/src/simulation/rules/pitLaneSpeedingSteward.js +71 -0
- package/src/simulation/rules/ruleConfigMerge.js +41 -0
- package/src/simulation/rules/ruleDefaults.js +85 -0
- package/src/simulation/rules/rulesReview.js +141 -0
- package/src/simulation/rules/rulesetPresets.js +47 -0
- package/src/simulation/rules/tireRequirementSteward.js +29 -0
- package/src/simulation/rules/trackLimitsSteward.js +85 -0
- package/src/simulation/rulesConfig.js +34 -0
- package/src/simulation/snapshots/raceSnapshots.js +192 -0
- package/src/simulation/timing/drsTiming.js +87 -0
- package/src/simulation/timing/gapEstimation.js +38 -0
- package/src/simulation/timing/lapTelemetry.js +182 -0
- package/src/simulation/timing/raceTiming.js +15 -0
- package/src/simulation/timing/sectorPerformance.js +60 -0
- package/src/simulation/timing/timingConstants.js +5 -0
- package/src/simulation/timing/timingHistory.js +46 -0
- package/src/simulation/timing/timingLines.js +79 -0
- package/src/simulation/track/centerlineSpline.js +59 -0
- package/src/simulation/track/drsZones.js +67 -0
- package/src/simulation/track/pitLaneAccess.js +103 -0
- package/src/simulation/track/pitLaneLayout.js +395 -0
- package/src/simulation/track/pitLaneState.js +160 -0
- package/src/simulation/track/proceduralCenterline.js +237 -0
- package/src/simulation/track/sampleGeometry.js +49 -0
- package/src/simulation/track/spatialQueries.js +154 -0
- package/src/simulation/track/startStraight.js +141 -0
- package/src/simulation/track/trackConstants.js +109 -0
- package/src/simulation/track/trackGenerationOptions.js +283 -0
- package/src/simulation/track/trackMath.js +241 -0
- package/src/simulation/track/trackModel.js +240 -0
- package/src/simulation/track/trackQueryIndex.js +945 -0
- package/src/simulation/track/trackSectors.js +19 -0
- package/src/simulation/track/trackStatePolicy.js +24 -0
- package/src/simulation/track/trackValidation.js +98 -0
- package/src/simulation/trackModel.js +1 -628
- package/src/simulation/units.js +6 -4
- package/src/simulation/vehicle/contactResolution.js +116 -0
- package/src/simulation/vehicle/mainTrackWheelSurface.js +82 -0
- package/src/simulation/vehicle/pitWheelSurface.js +69 -0
- package/src/simulation/vehicle/runoffResponse.js +88 -0
- package/src/simulation/vehicle/surfacePriority.js +28 -0
- package/src/simulation/vehicle/vehicleGeometry.js +247 -0
- package/src/simulation/vehicle/vehiclePhysics.js +363 -0
- package/src/simulation/vehicle/vehicleSnapshots.js +316 -0
- package/src/simulation/vehicle/vehicleState.js +186 -0
- package/src/simulation/vehicle/wheelSurface.js +150 -0
- package/src/simulation/vehicleGeometry.js +1 -0
- package/src/simulation/vehiclePhysics.js +1 -104
- package/src/simulation/warmup/runtimeWarmup.js +224 -0
- package/src/simulation/wheelSurface.js +1 -0
- package/src/styles.css +342 -42
- package/src/ui/bannerTemplates.js +69 -0
- package/src/ui/cameraControlsTemplate.js +20 -0
- package/src/ui/carOverviewTemplate.js +33 -0
- package/src/ui/componentTemplates.js +20 -426
- package/src/ui/raceCanvasTemplate.js +69 -0
- package/src/ui/raceControlStatusBanner.js +39 -0
- package/src/ui/raceControlsTemplate.js +36 -0
- package/src/ui/shellTemplate.js +6 -5
- package/src/ui/telemetryDrawerTemplate.js +55 -0
- package/src/ui/telemetryTemplates.js +136 -0
- package/src/ui/templateUtils.js +23 -0
- package/src/ui/timingTowerTemplate.js +34 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,96 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Promote the `v6` simulator work as the next major PaddockJS release. This release keeps the package boundary focused on browser-mounted simulator components, composable simulator surfaces, and browser-free JavaScript environment/control APIs.
|
|
8
|
+
- Add the stricter opt-in `physicsMode: 'simulator'` vehicle model with 2D velocity/yaw dynamics, traction limits, speed-sensitive steering, steering scrub, slip telemetry, reduced off-road grip, and simulator-mode AI tuning. The default remains `physicsMode: 'arcade'` for existing hosts.
|
|
9
|
+
- Add richer procedural track generation with semantic profiles (`race`, `training-short`, `training-medium`, and `training-technical`), validated connected-region centerlines, profile-level generation controls, deterministic `trackGeneration` options, DRS zones, pit-lane access geometry, and cached track query indexes.
|
|
10
|
+
- Add hard barrier-wall consequences and opt-in stalled off-track DNF handling. Barrier contact now marks cars destroyed/DNF in both physics modes, while `rules.modules.stalledDnf` can retire cars that remain stopped off legal surfaces.
|
|
11
|
+
- Expand the headless environment contract for real training loops: compact vector/object/full observation output, optional `Float32Array` vectors, schema caching, no-state/minimal/full result output, per-driver episode info, selected-driver resets, reset-only scenario placements, reward normalization, evaluation helpers, rollout metrics, and a shared driver-controller loop.
|
|
12
|
+
- Add physical-driver observation support with richer body/boundary/contact senses, opponent radar, configurable ray layouts, surface-aware ray channels, driver/debug precision modes, and model-sense visualization that renders the active observation rather than recomputing browser-only values.
|
|
13
|
+
- Add participant interaction profiles and replay ghosts for training/comparison workflows. `batch-training`, `isolated-training`, and related profiles can make real physics participants non-colliding, sensor-hidden, pit-non-blocking, or race-order-excluded, while replay ghosts remain separate trajectory overlays outside car physics/rules.
|
|
14
|
+
- Add Policy Runner support for the three package-supported controller paths: browser-run distilled policy playback, JSON policy-server action loops, and live preview streams for externally rendered snapshots.
|
|
15
|
+
- Add Python bridge examples for policy-server integration through `examples/python/base_policy_server.py` plus a minimal `requirements.txt`.
|
|
16
|
+
- Add UI/runtime controls for simulation speed, external rendering/live preview, replay ghost drawing, no-collision markers, debug-only physics-mode indicators, runtime warmup, visibility-aware frame loops, and reduced high-speed DOM refresh cost.
|
|
17
|
+
|
|
18
|
+
### Package UI And Showcase
|
|
19
|
+
|
|
20
|
+
- Rework the tracked `local-preview` showcase into release coverage pages for templates, components, API controls, behavior/layout contracts, stewarding, collision lab, Policy Runner, and rules.
|
|
21
|
+
- Add generated showcase coverage cards and hideable example-code panels so each documented mount/control path has an accurate colocated example.
|
|
22
|
+
- Add the Rules page and update showcase navigation across all tracked pages.
|
|
23
|
+
- Clean up showcase composition bugs around loaded simulator heights, placeholder min-heights, section-title wrapping, empty/wrong code examples, and host embed overflow.
|
|
24
|
+
- Remove the old standalone `expert-environment.html` page after folding the supported environment/control coverage into the broader docs and Policy Runner paths.
|
|
25
|
+
|
|
26
|
+
### Architecture And Maintenance
|
|
27
|
+
|
|
28
|
+
- Split large facade files into feature-owned modules for app banners, camera control, readouts, rendering, runtime lifecycle, sensors, track generation/querying, pit flow, race lifecycle, race order, race finish/classification, rules, timing, driver control, vehicle physics, and snapshots.
|
|
29
|
+
- Keep compatibility barrels thin while moving implementation into canonical feature directories such as `src/simulation/track/`, `src/simulation/vehicle/`, `src/simulation/driver/`, `src/simulation/timing/`, `src/simulation/pit/`, `src/environment/sensors/`, and `src/app/`.
|
|
30
|
+
- Add fast/slow Vitest mode helpers, release browser-smoke coverage, local-preview markup regressions, policy-runner encoder/server tests, warmup tests, physics-mode tests, expert sensor renderer tests, and a track-query-index benchmark script.
|
|
31
|
+
- Update package release gates so `npm run check` runs fast tests, public type checks, dry pack, packed-consumer smoke, tracked showcase build, and quick Chromium smoke; `npm run check:release` adds slow characterization and the full browser smoke matrix.
|
|
32
|
+
|
|
33
|
+
### Fixes And Behavior Cleanup
|
|
34
|
+
|
|
35
|
+
- Ensure browser expert teardown destroys the expert adapter and detaches external renderer subscriptions.
|
|
36
|
+
- Preserve external renderer driver IDs when incoming live-preview frames already use local simulator driver IDs.
|
|
37
|
+
- Keep browser expert rendering stable when compact environment result options request no returned state payload.
|
|
38
|
+
- Validate missing/non-finite controlled-driver actions instead of silently applying stale or zero controls.
|
|
39
|
+
- Keep environment reset behavior stable when partial reset options omit nested groups or intentionally replace scenario placements.
|
|
40
|
+
- Keep no-collision participants and replay ghosts aligned across rendering, sensors, race order, collision, pit occupancy, and public snapshots.
|
|
41
|
+
- Keep model-facing observations and visual sensor overlays aligned to the active observation contract, with debug precision reserved for labeled diagnostics.
|
|
42
|
+
- Make the debug physics-mode square opt-in through `debug.physicsModeIndicator` and hidden by default for package consumers.
|
|
43
|
+
- Remove the deleted `training-lab` workflow from the package boundary; release artifacts include supported docs/examples only.
|
|
44
|
+
|
|
45
|
+
### Documentation
|
|
46
|
+
|
|
47
|
+
- Add the Custom Model Controller Guide for wrapping a trained model as a batched controller usable from browser playback or headless loops.
|
|
48
|
+
- Expand README, system specs, data contract, training guide, rules, concepts, architecture notes, learnings, and install/update workflow for the new simulator, environment, Policy Runner, showcase, and release-gate behavior.
|
|
49
|
+
- Document the Python policy-server boundary as an example bridge, not a packaged Python Gymnasium/PettingZoo integration.
|
|
50
|
+
|
|
51
|
+
### Known Future Scope
|
|
52
|
+
|
|
53
|
+
- Weather effects, reliability failures, fuel-load performance effects, static obstacles, debug mutation APIs, assisted controls, and packaged Python Gymnasium/PettingZoo wrappers remain intentionally out of 2.0.0.
|
|
54
|
+
|
|
55
|
+
## 1.0.0
|
|
56
|
+
|
|
57
|
+
### Major Changes
|
|
58
|
+
|
|
59
|
+
- Promote PaddockJS to the first stable release for reusable browser embeds and headless JavaScript training/control workflows. The package now exposes the production simulator through `mountF1Simulator()`, composable mount helpers through `createPaddockSimulator()`, and a browser-free environment API through `@inventure71/paddockjs/environment`.
|
|
60
|
+
- Stabilize the 1.0 race-simulation feature set around pit-lane and pit-stop behavior, stewarded penalties, more realistic vehicle geometry and wheel-level surface handling, improved timing/DRS data, and lower-cost simulation/runtime paths.
|
|
61
|
+
|
|
62
|
+
### Race Simulation
|
|
63
|
+
|
|
64
|
+
- Add deterministic procedural tracks with pit-lane geometry, service areas, team queue slots, garage boxes, legal pit-lane surfaces, pit entry/exit routes, pit-lane open/closed state, and red-flag gating.
|
|
65
|
+
- Add automatic and host-controlled pit-stop intent, target tire compounds, service timing, penalty service before tire work, team queue behavior, pit-service countdown display, and optional pit-crew service variability.
|
|
66
|
+
- Add penalty ledger support for time, drive-through, stop-go, position-drop, grid-drop, and disqualification consequences, including service/cancel/final-classification conversion behavior.
|
|
67
|
+
- Enforce track limits from all four wheel contact patches, not car center position, and resolve each car's physics surface from the worst wheel surface.
|
|
68
|
+
- Add pit-lane speeding steward enforcement on speed-limited pit-lane parts while keeping pit-entry and pit-exit connector roads legal but not speed-limited.
|
|
69
|
+
- Use body-hull car collision geometry instead of transparent sprite bounds, with swept checks to prevent endpoint tunneling and contact metadata for callbacks/debugging.
|
|
70
|
+
- Fix lapped-traffic collision fault assignment so rear contact is judged by physical track order rather than cumulative race distance.
|
|
71
|
+
- Fix DRS detection so physically-ahead lapped traffic can be the DRS reference car.
|
|
72
|
+
- Improve race timing with fixed timing-line crossing history, interval and leader-gap modes, lap-gap labels for lapped cars, sector telemetry, provisional waved-flag status, and final classification after the full field finishes.
|
|
73
|
+
|
|
74
|
+
### Performance And Runtime
|
|
75
|
+
|
|
76
|
+
- Cache per-car geometry and wheel-surface state for repeated collision, surface, snapshot, and debug consumers.
|
|
77
|
+
- Reduce collision candidate work with circular-track distance-window pruning before swept AABB/SAT checks.
|
|
78
|
+
- Reduce headless/runtime cost by avoiding repeated full snapshot serialization during frame skips and by adding lean render/observation snapshot paths.
|
|
79
|
+
- Reduce observation cost by reusing ray-origin track state and broadphasing ray/car tests before exact footprint intersection.
|
|
80
|
+
- Reduce browser work by throttling noncritical DOM/timing refreshes at high playback speeds, reusing supplied snapshots for camera-control availability, caching stable pit-lane status graphics, pruning DRS trail histories in place, and skipping repeated text/markup writes.
|
|
81
|
+
|
|
82
|
+
### Public API And Docs
|
|
83
|
+
|
|
84
|
+
- Add and document the expert/headless environment API, action and observation specs, starter progress reward helper, rollout recorder/evaluation helpers, and worker-protocol wrapper.
|
|
85
|
+
- Add public controller methods for safety car, red flag, pit-lane open/closed state, pit intent/compound control, and penalty serve/cancel controls.
|
|
86
|
+
- Add the `ui.simulationSpeedControl` TypeScript option and document the browser playback speed control.
|
|
87
|
+
- Expand local preview and browser smoke coverage for templates, composable mounts, API controls, behavior, stewarding, collision lab, expert environment, and policy runner pages.
|
|
88
|
+
- Update package docs for 1.0 behavior, data contracts, architecture boundaries, rules, training/control usage, and installation/update workflow.
|
|
89
|
+
|
|
90
|
+
### Known Future Scope
|
|
91
|
+
|
|
92
|
+
- Weather effects, reliability failures, and fuel-load performance effects remain intentionally out of 1.0.0 and are tracked as future work.
|
|
93
|
+
|
|
3
94
|
## 0.3.0
|
|
4
95
|
|
|
5
96
|
### Minor Changes
|
package/INSTALL_AND_UPDATE.md
CHANGED
|
@@ -112,7 +112,7 @@ npm run check
|
|
|
112
112
|
Install a specific version when the host needs a controlled upgrade:
|
|
113
113
|
|
|
114
114
|
```bash
|
|
115
|
-
npm install @inventure71/paddockjs@
|
|
115
|
+
npm install @inventure71/paddockjs@2.0.0
|
|
116
116
|
npm run check
|
|
117
117
|
```
|
|
118
118
|
|
|
@@ -122,7 +122,10 @@ After updating, smoke-test the page that mounts the simulator. Browser behavior
|
|
|
122
122
|
|
|
123
123
|
The package repo owns its release process:
|
|
124
124
|
|
|
125
|
-
- `npm run check` runs runtime tests, public type verification, dry-pack verification,
|
|
125
|
+
- `npm run check` runs fast runtime tests, public type verification, dry-pack verification, packed-consumer install/build verification, the tracked showcase build, and a quick Chromium browser smoke test.
|
|
126
|
+
- `npm run check:release` runs the exhaustive release gate, including slow characterization tests and the full Chromium browser smoke matrix.
|
|
127
|
+
- `npm run consumer:smoke` packs the package, installs the tarball into a fresh temporary Vite app, and builds that app through public package imports.
|
|
128
|
+
- `npm run browser:smoke` builds `local-preview`, starts a local preview server, and checks desktop/mobile canvas rendering, overflow constraints, API buttons, and visual policy-runner stepping in Chromium. Use `npm run browser:smoke:quick` for the smaller local browser pass and `npm run browser:smoke:full` for the full matrix.
|
|
126
129
|
- `npm run changeset` records the next version bump and changelog note.
|
|
127
130
|
- `npm run version-packages` applies pending Changesets locally.
|
|
128
131
|
- `.github/workflows/ci.yml` verifies the package on push and pull request.
|
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ npm install @inventure71/paddockjs
|
|
|
12
12
|
|
|
13
13
|
## Documentation
|
|
14
14
|
|
|
15
|
-
Start with [docs/index.md](docs/index.md) for system specs, rules, concepts, data contracts, and architecture notes.
|
|
15
|
+
Start with [docs/index.md](docs/index.md) for system specs, rules, concepts, data contracts, and architecture notes. If you already trained a driver model and want to run it in PaddockJS, use the [Custom Model Controller Guide](docs/custom_model_controller.md).
|
|
16
16
|
|
|
17
17
|
## Package Workflow
|
|
18
18
|
|
|
@@ -28,25 +28,36 @@ Useful commands:
|
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
30
|
npm run check
|
|
31
|
+
npm run check:release
|
|
32
|
+
npm run consumer:smoke
|
|
33
|
+
npm run browser:smoke
|
|
31
34
|
npm run showcase:dev
|
|
32
35
|
npm run showcase:build
|
|
33
36
|
npm run changeset
|
|
34
37
|
```
|
|
35
38
|
|
|
36
|
-
`npm run check`
|
|
39
|
+
`npm run check` is the normal local gate: fast runtime tests, public declarations, dry package contents, packed-package consumption in a fresh Vite app, the showcase build, and a quick Chromium smoke against the showcase. `npm run check:release` runs the same package gates plus slow characterization tests and the full browser smoke matrix.
|
|
37
40
|
|
|
38
41
|
Local development and showcase builds require Node `20.19.0` or newer. CI currently runs the package check on Node 22 and releases on Node 24.
|
|
39
42
|
|
|
43
|
+
## 2.0.0 Release Highlights
|
|
44
|
+
|
|
45
|
+
Version `2.0.0` is the current major release line. It adds the stricter opt-in simulator physics mode, richer procedural track generation, indexed track/ray queries, barrier destruction and stalled-DNF behavior, batch-training participant profiles, replay ghosts, compact/vectorized environment output, policy-server/live-preview Policy Runner paths, Python policy-server examples, the custom model controller guide, the Rules showcase page, and the full release-gated local preview coverage.
|
|
46
|
+
|
|
47
|
+
The package still does not ship trained model weights, model storage, a Python Gymnasium/PettingZoo package, static obstacles, weather, reliability failures, fuel-load effects, or debug mutation APIs. Those remain host-owned or future scope.
|
|
48
|
+
|
|
40
49
|
## Expert Environment API
|
|
41
50
|
|
|
42
51
|
Headless training code imports the environment subpath:
|
|
43
52
|
|
|
44
53
|
```js
|
|
45
|
-
import { createPaddockEnvironment
|
|
54
|
+
import { createPaddockEnvironment } from '@inventure71/paddockjs/environment';
|
|
46
55
|
```
|
|
47
56
|
|
|
48
57
|
The package root remains the browser component API. The environment subpath is intentionally browser-free and does not import DOM, PixiJS, or package CSS.
|
|
49
|
-
PaddockJS is a bring-your-own-model environment. It does not choose an ML framework, store model weights, or ship a trained driver.
|
|
58
|
+
PaddockJS is a bring-your-own-model environment. It does not choose an ML framework, store model weights, or ship a trained driver. The shared `createPaddockDriverControllerLoop()` helper lets a user-owned controller run against either browser expert mode or `createPaddockEnvironment()` with the same batched `decideBatch(context)` call shape.
|
|
59
|
+
|
|
60
|
+
Browser and headless environments default to `physicsMode: 'arcade'` for existing hosts. Opt into the stricter vehicle model with `physicsMode: 'simulator'` when you want 2D velocity/yaw dynamics, traction limits, steering scrub, derived slip telemetry, reduced off-road grip, and simulator-mode AI tuning:
|
|
50
61
|
|
|
51
62
|
```js
|
|
52
63
|
const env = createPaddockEnvironment({
|
|
@@ -54,7 +65,7 @@ const env = createPaddockEnvironment({
|
|
|
54
65
|
entries,
|
|
55
66
|
controlledDrivers: ['budget'],
|
|
56
67
|
frameSkip: 2,
|
|
57
|
-
|
|
68
|
+
physicsMode: 'simulator',
|
|
58
69
|
});
|
|
59
70
|
|
|
60
71
|
let result = env.reset();
|
|
@@ -63,13 +74,37 @@ result = env.step({
|
|
|
63
74
|
});
|
|
64
75
|
```
|
|
65
76
|
|
|
66
|
-
|
|
77
|
+
Action steering is an absolute normalized steering target: `-1` points the wheel to maximum left, `0` points it to center, `1` points it to maximum right, and intermediate values target the same percentage of the maximum angle. Physics still rate-limits how quickly the steering wheel reaches that target.
|
|
78
|
+
|
|
79
|
+
The environment can run with no reward, as above, or with a host-supplied `reward(context)` callback. Reward formulas stay user-owned; PaddockJS only supplies the neutral facts:
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
const env = createPaddockEnvironment({
|
|
83
|
+
drivers,
|
|
84
|
+
entries,
|
|
85
|
+
controlledDrivers: ['budget'],
|
|
86
|
+
reward({ metrics, episode }) {
|
|
87
|
+
if (metrics.destroyed) return -200;
|
|
88
|
+
if (metrics.offTrack) return -12;
|
|
89
|
+
if (episode.terminated) return 0;
|
|
90
|
+
return metrics.legalProgressDeltaMeters;
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Reward callback results are converted to numbers per controlled driver. Missing, `NaN`, or infinite callback results become a neutral `0` so one bad callback value cannot poison a training batch.
|
|
96
|
+
|
|
97
|
+
The repository also includes dependency-free examples that use the same environment contract:
|
|
67
98
|
|
|
68
99
|
```bash
|
|
69
100
|
node examples/train-basic-policy.mjs --generations=4 --candidates=5 --episodes=1 --steps=240
|
|
70
101
|
```
|
|
71
102
|
|
|
72
|
-
|
|
103
|
+
The starter script imports the public `@inventure71/paddockjs/environment` subpath and uses self-contained example data from `examples/trainingData.mjs`, so it does not depend on private package source modules for demo drivers. `createProgressReward()` remains available as example/demo reward code only; it is not the official reward and not part of the environment objective.
|
|
104
|
+
|
|
105
|
+
Each default ray reports track-transition distance and car distance. A track hit uses `kind: 'exit'` when the ray leaves the road and `kind: 'entry'` when an off-track ray points back to the road. Richer sensor layouts are opt-in: rays can use per-ray lengths, predefined layouts such as `driver-front-heavy`, channels for `roadEdge`, `kerb`, `illegalSurface`, and `car`, and `precision: 'driver' | 'debug'`. Driver precision is the default model-facing contract; debug precision is only for clearly labeled diagnostics. Surface channels are computed only when requested. Barrier walls are rendered and enforced as hard destruction boundaries in both physics modes, but they are not model-facing ray targets. `observation.object.self.onTrack` follows the simulator's wheel-level legality rules, so track, kerb, and legal pit-lane/box surfaces are on-track for reward and observation purposes. `pitIntent: 0` is always accepted as the no-op clear value, including environments where pit stops are disabled.
|
|
106
|
+
|
|
107
|
+
For realistic local-perception policies, use `physicsMode: 'simulator'` with `observation.profile: 'physical-driver'`. It exposes yaw rate, local boundary distances, contact-patch surface readings, richer opponent radar, and surface-aware ray fields in the versioned vector schema. The profile defaults track lookahead to `[]` so the policy does not receive privileged future curvature unless the host explicitly opts back in.
|
|
73
108
|
|
|
74
109
|
External training code can inspect the environment contract without guessing field ranges:
|
|
75
110
|
|
|
@@ -78,6 +113,108 @@ const actionSpec = env.getActionSpec();
|
|
|
78
113
|
const observationSpec = env.getObservationSpec();
|
|
79
114
|
```
|
|
80
115
|
|
|
116
|
+
Controller modules own model loading, inference, memory, rewards, and logs. PaddockJS supplies cached specs, stable controlled-driver ordering, compact observations, action validation, and repeated stepping through normal physics controls:
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
import { createPaddockDriverControllerLoop } from '@inventure71/paddockjs';
|
|
120
|
+
|
|
121
|
+
const controller = {
|
|
122
|
+
async decideBatch(ctx) {
|
|
123
|
+
return Object.fromEntries(ctx.orderedObservations.map(({ driverId, vector }) => [
|
|
124
|
+
driverId,
|
|
125
|
+
userModelAction(vector),
|
|
126
|
+
]));
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const loop = createPaddockDriverControllerLoop({
|
|
131
|
+
runtime: env,
|
|
132
|
+
controller,
|
|
133
|
+
actionRepeat: 4,
|
|
134
|
+
});
|
|
135
|
+
await loop.reset();
|
|
136
|
+
await loop.step();
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`loop.start()` may begin from a fresh runtime and will lazily reset before the first scheduled step. In `onStep(ctx)`, `ctx.actions` is the current applied action map and `ctx.previousActions` is the action map applied on the prior physics step. Scheduled playback stops on controller/runtime errors and exposes the value through `loop.stats.lastError`.
|
|
140
|
+
|
|
141
|
+
The environment also exposes reset-only scenario placement, neutral rollout recording, deterministic evaluation metrics, and a JSON-serializable worker protocol for external bridges:
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
const env = createPaddockEnvironment({
|
|
145
|
+
drivers,
|
|
146
|
+
entries,
|
|
147
|
+
controlledDrivers: ['budget'],
|
|
148
|
+
scenario: {
|
|
149
|
+
preset: 'off-track-recovery',
|
|
150
|
+
placements: {
|
|
151
|
+
budget: { distanceMeters: 420, offsetMeters: 16, speedKph: 65 },
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Scenario placement is an environment reset feature, not a policy assist. During `step(actions)`, controlled cars still move only through normalized steering, throttle, brake, and pit intent. `steering`, `throttle`, and `brake` are required for each controlled-driver action; missing or non-finite values fail validation instead of becoming silent zero controls.
|
|
158
|
+
|
|
159
|
+
For same-environment batched learning, controlled cars can use compact vector observations and reset independently at episode boundaries:
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
const env = createPaddockEnvironment({
|
|
163
|
+
drivers,
|
|
164
|
+
entries,
|
|
165
|
+
controlledDrivers: agentIds,
|
|
166
|
+
physicsMode: 'simulator',
|
|
167
|
+
participantInteractions: { defaultProfile: 'batch-training' },
|
|
168
|
+
observation: {
|
|
169
|
+
profile: 'physical-driver',
|
|
170
|
+
output: 'vector',
|
|
171
|
+
includeSchema: false,
|
|
172
|
+
vectorType: 'float32',
|
|
173
|
+
},
|
|
174
|
+
result: {
|
|
175
|
+
stateOutput: 'none',
|
|
176
|
+
resetDriversObservationScope: 'reset',
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const schema = env.getObservationSpec();
|
|
181
|
+
let result = env.reset();
|
|
182
|
+
result = env.step(actionsByDriver);
|
|
183
|
+
|
|
184
|
+
env.resetDrivers({
|
|
185
|
+
[agentIds[0]]: { distanceMeters: 1200, offsetMeters: 3, speedKph: 80 },
|
|
186
|
+
}, {
|
|
187
|
+
stateOutput: 'none',
|
|
188
|
+
observationScope: 'reset',
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`batch-training` cars remain real rendered cars in `snapshot.cars`, but they are non-colliding, sensor-hidden, pit-non-blocking, and excluded from race order by default. Step results include `info.drivers[driverId]` episode state and neutral `metrics[driverId]` facts for external logging or user-defined rewards. `stateOutput: 'none'` suppresses repeated `state.snapshot` payloads for high-throughput loops; use `minimal` when the loop still needs the observation snapshot, or omit the option for the full backward-compatible public snapshot. Deterministic evaluation helpers can accept compact no-state base options and internally request the minimal snapshot needed for evaluation metrics. Reset placements are classified against the same runoff/barrier rules before observations are returned: recovery starts stay physical, while cars placed inside terminal barrier space return destroyed metrics and stable miss-valued rays instead of running far-out ray geometry.
|
|
193
|
+
|
|
194
|
+
On the package's local 20-car simulator benchmark with front-heavy physical-driver rays, compact vector/no-state output measured around `3.3ms` per environment action, with a no-ray baseline around `1.5ms`. Those numbers are hardware dependent, but they show the intended usage: keep schema/spec lookup separate, request compact vectors in training loops, and reserve full snapshots for debugging or visualization.
|
|
195
|
+
|
|
196
|
+
For multi-car training and visual comparison, PaddockJS separates real participants from replay overlays:
|
|
197
|
+
|
|
198
|
+
- `participantInteractions` changes how physics-driven cars interact with collisions, sensors, pit occupancy, and race order. Those cars remain in `snapshot.cars` and still move through steering, throttle, brake, pit intent, tire state, timing, and rules.
|
|
199
|
+
- `replayGhosts` are trajectory-driven overlays for reference laps, debugging, or comparison. They appear in `snapshot.replayGhosts`, never in `snapshot.cars`, and do not collide, rank, pit, or trigger penalties. They are sensor-hidden by default and only appear in rays or nearby observations when their own sensor flags opt in.
|
|
200
|
+
- In the browser view, non-colliding participants remain solid clickable cars but get a blue no-collision outline marker. Replay ghosts remain translucent overlays.
|
|
201
|
+
|
|
202
|
+
```js
|
|
203
|
+
const env = createPaddockEnvironment({
|
|
204
|
+
drivers,
|
|
205
|
+
entries,
|
|
206
|
+
controlledDrivers: ['model-a', 'model-b'],
|
|
207
|
+
participantInteractions: {
|
|
208
|
+
drivers: {
|
|
209
|
+
'model-a': { profile: 'isolated-training' },
|
|
210
|
+
'model-b': { profile: 'isolated-training' },
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`isolated-training` is the no-collision profile for real cars that should still remain in race order. `batch-training` is the preferred no-collision profile for same-environment learner batches because it is also excluded from race order. Both profiles hide the car from other cars' ray sensors and `nearbyCars` observations by default; use `phantom-race` or explicit `detectableByRays` / `detectableAsNearby` overrides only when sensor visibility is intentional.
|
|
217
|
+
|
|
81
218
|
Browser expert mode is opt-in through the normal mount API. When enabled, the visual simulator advances only when host code calls `simulator.expert.step(actions)`. Expert mode is a mount-time boundary; changing `expert` through `restart(nextOptions)` is rejected so ticker ownership cannot silently change under a mounted simulator.
|
|
82
219
|
Set `expert.visualizeSensors` to draw expert sensor rays inside the actual race canvas for visual debugging:
|
|
83
220
|
|
|
@@ -96,6 +233,10 @@ const simulator = await mountF1Simulator(root, {
|
|
|
96
233
|
});
|
|
97
234
|
```
|
|
98
235
|
|
|
236
|
+
The overlay renders ray values from the same active observation returned by `simulator.expert.step(actions)`; it does not recompute a separate sensor model for the browser layer. Each detected ray channel is shown as its own colored marker, so road-edge, kerb, illegal surface, and car hits can be inspected independently. This applies to every model-facing sense: Policy Runner and expert visualizations must show what the policy receives, while extra high-precision diagnostics must be labeled separately.
|
|
237
|
+
|
|
238
|
+
When multiple drivers are controlled, sensor visualization renders the selected controlled driver by default so batch-training previews do not draw every agent's rays every frame. Use `visualizeSensors: { rays: true, drivers: 'all' }` only when you intentionally want the heavier all-controlled-car overlay.
|
|
239
|
+
|
|
99
240
|
## API
|
|
100
241
|
|
|
101
242
|
All-in-one mount:
|
|
@@ -183,7 +324,7 @@ simulator.mountRaceTelemetryDrawer(document.getElementById('sim-race-workbench')
|
|
|
183
324
|
});
|
|
184
325
|
```
|
|
185
326
|
|
|
186
|
-
`drivers` is the host-owned project/pilot list. `entries` is the optional driver/car/team pairing sheet. The car/driver overview uses the existing driver and vehicle rating components from each entry. Driver and vehicle entries can also include `customFields` as extra label/value metadata. Entries can include `team: { id, name, color, icon }`; the timing tower uses the team icon and defaults team color to the car color when omitted. Assets, including the default car image and generic driver helmet, are bundled by default, so the host website does not need to provide simulator images or textures.
|
|
327
|
+
`drivers` is the host-owned project/pilot list. `entries` is the optional driver/car/team pairing sheet. The car/driver overview uses the existing driver and vehicle rating components from each entry. Driver and vehicle entries can also include `customFields` as extra label/value metadata. Entries can include `team: { id, name, color, icon, pitCrew }`; the timing tower uses the team icon and defaults team color to the car color when omitted. `team.pitCrew` accepts `speed`, `consistency`, and `reliability` values from `0` to `1` for optional pit-service variability. Assets, including the default car image and generic driver helmet, are bundled by default, so the host website does not need to provide simulator images or textures.
|
|
187
328
|
|
|
188
329
|
The returned object supports:
|
|
189
330
|
|
|
@@ -191,9 +332,17 @@ The returned object supports:
|
|
|
191
332
|
- `restart(nextOptions)` for non-asset, non-expert race/data/seed changes
|
|
192
333
|
- `selectDriver(driverId)`
|
|
193
334
|
- `setSafetyCarDeployed(deployed)`
|
|
335
|
+
- `setRedFlagDeployed(deployed)`
|
|
336
|
+
- `setPitLaneOpen(open)`
|
|
194
337
|
- `callSafetyCar()`
|
|
195
338
|
- `clearSafetyCar()`
|
|
196
339
|
- `toggleSafetyCar()`
|
|
340
|
+
- `setPitIntent(driverId, intent, targetCompound?)`
|
|
341
|
+
- `getPitIntent(driverId)`
|
|
342
|
+
- `getPitTargetCompound(driverId)`
|
|
343
|
+
- `getSimulationSpeed()`
|
|
344
|
+
- `servePenalty(penaltyId)`
|
|
345
|
+
- `cancelPenalty(penaltyId)`
|
|
197
346
|
- `getSnapshot()`
|
|
198
347
|
- `expert` when explicitly enabled, otherwise `null`
|
|
199
348
|
|
|
@@ -219,14 +368,180 @@ ui: {
|
|
|
219
368
|
raceDataBannerSize: 'auto',
|
|
220
369
|
raceDataTelemetryDetail: true,
|
|
221
370
|
timingTowerVerticalFit: 'expand-race-view',
|
|
371
|
+
},
|
|
372
|
+
debug: {
|
|
373
|
+
physicsModeIndicator: false,
|
|
222
374
|
}
|
|
223
375
|
```
|
|
224
376
|
|
|
225
|
-
`preset` is resolved before explicit host options. Available presets are `dashboard`, `timing-overlay`, `compact-race`, and `full-dashboard`; hosts can start from a preset and override any `ui` or `theme` field. `theme` maps to package CSS variables for the stable sizing/color contract: `accentColor`, `greenColor`, `yellowColor`, `timingTowerMaxWidth`, and `raceViewMinHeight`.
|
|
377
|
+
`preset` is resolved before explicit host options. Available presets are `dashboard`, `timing-overlay`, `compact-race`, and `full-dashboard`; hosts can start from a preset and override any `ui`, `debug`, or `theme` field. `debug.physicsModeIndicator: true` renders a small top-left race-canvas square: blue for arcade physics and red for simulator physics. It defaults to `false` for package consumers and is intended only for debug/development use. `theme` maps to package CSS variables for the stable sizing/color contract: `accentColor`, `greenColor`, `yellowColor`, `timingTowerMaxWidth`, and `raceViewMinHeight`.
|
|
378
|
+
|
|
379
|
+
If `trackSeed` is omitted, each mounted browser simulator creates a fresh procedural circuit. Passing `trackSeed` makes the track deterministic so multiple embeds can share the same generated circuit; repeated procedural seeds are cached within the page runtime as immutable track definitions. Treat values returned by `createProceduralTrack()` as read-only and pass custom mutable copies when experimenting with track-definition edits. `restart({ trackSeed })` rebuilds the race on the deterministic circuit for the new seed. Asset URL changes are not restartable; destroy and mount a new simulator when changing assets.
|
|
380
|
+
|
|
381
|
+
Warmup is enabled by default across browser, headless environment, and direct simulation creation. The runtime warms a disposable instance during loading and caches by configuration fingerprint, so identical resets/restarts skip repeated warmup while seed/config changes warm again automatically. Override with `warmup: { enabled, policy: 'config-change' | 'always' | 'never', steps }` or `warmup: false`.
|
|
382
|
+
|
|
383
|
+
Generated circuits are built from seeded connected region boundaries that are smoothed and warped into a validated centerline, so tracks can include concave infield/outfield sections and chicane-like bends instead of simple oval-like fallback shapes. Hosts can pass `trackGeneration` alongside `trackSeed` to choose a profile and override semantic generation controls:
|
|
384
|
+
|
|
385
|
+
```js
|
|
386
|
+
const simulator = await mountF1Simulator(root, {
|
|
387
|
+
drivers,
|
|
388
|
+
entries,
|
|
389
|
+
trackSeed: 4101,
|
|
390
|
+
trackGeneration: {
|
|
391
|
+
profile: 'training-short',
|
|
392
|
+
length: { minMeters: 900, maxMeters: 1800 },
|
|
393
|
+
startStraight: { gridMeters: 0 },
|
|
394
|
+
pitLane: { enabled: false },
|
|
395
|
+
},
|
|
396
|
+
rules: {
|
|
397
|
+
modules: {
|
|
398
|
+
pitStops: { enabled: false },
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
simulator.restart({
|
|
404
|
+
trackSeed: 5051,
|
|
405
|
+
trackGeneration: { profile: 'race' },
|
|
406
|
+
});
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Advanced callers can import `createProceduralTrack(seed, options)` when they need the generated track definition directly instead of mounting a simulator:
|
|
410
|
+
|
|
411
|
+
```js
|
|
412
|
+
import { createProceduralTrack } from '@inventure71/paddockjs';
|
|
413
|
+
|
|
414
|
+
const trainingTrack = createProceduralTrack(4101, {
|
|
415
|
+
profile: 'training-short',
|
|
416
|
+
length: { minMeters: 900, maxMeters: 1800 },
|
|
417
|
+
startStraight: { gridMeters: 0, exitMeters: 80, blendMeters: 80 },
|
|
418
|
+
pitLane: { enabled: false },
|
|
419
|
+
shape: { scale: 0.2, cornerDensity: 1.3, variation: 0.22 },
|
|
420
|
+
validation: { minClearanceMultiplier: 1, maxLocalTurnRadians: 1.85 },
|
|
421
|
+
attempts: { primary: 80, fallback: 200 },
|
|
422
|
+
});
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Profiles are presets, not separate generators. `race` preserves the default full circuit with pit lane; `training-short`, `training-medium`, and `training-technical` generate smaller pitless circuits for training or demos. Resolution is `race` defaults, then the selected profile, then explicit overrides.
|
|
426
|
+
|
|
427
|
+
Pit-lane geometry depends on the resolved generation options. The `race` profile includes:
|
|
428
|
+
|
|
429
|
+
- rendered pit lane beside the start/finish straight
|
|
430
|
+
- lane-aligned procedural entry and exit roads
|
|
431
|
+
- main fast lane sized from the team/box layout
|
|
432
|
+
- parallel working lane
|
|
433
|
+
- 10 shared team service areas
|
|
434
|
+
- 20 unused garage boxes arranged as 10 team pairs
|
|
435
|
+
|
|
436
|
+
Training profiles disable pit-lane generation by default. If a host explicitly sets `pitLane: { enabled: false }`, pit-related rules should also be disabled or left in a no-op configuration.
|
|
437
|
+
|
|
438
|
+
Pit-lane asphalt, working-lane service areas, and garage boxes are legal drivable surfaces for sensors, runoff handling, track-limit stewarding, and stalled-DNF timing. In both physics modes, the rendered barrier wall marks the hard outer runoff boundary; cars whose footprint reaches the wall's inner face are marked `destroyed`, stopped, removed from active collision/sensor participation, and treated as DNF entries at the bottom of the timing order. `physicsMode` changes vehicle integration and grip behavior, not barrier consequences. Environment results expose destruction as neutral `metrics[driverId].destroyed` and a per-driver `endReason: 'destroyed'`, so training loops can assign their own negative reward and then call `resetDrivers()` for a new episode. Opt-in stalled off-track DNF uses `endReason: 'stalled-off-track'` without setting `destroyed`. Tire energy degrades down to 1% and affects grip nonlinearly, so badly worn tires are slower and harder to rotate without making the car instantly undrivable.
|
|
439
|
+
|
|
440
|
+
When `rules.modules.pitStops.enabled` is true, cars automatically form bounded pit trains when lane space is available. They brake to the limiter by the main pit-lane start, drive along the main fast lane, pass through the team queue spot as a rolling gate, roll into the team-colored working-lane service area when it is clear, stop, serve eligible penalties before tire work, show the remaining stationary service time above the car, change to the requested configured tire compound or the default alternate compound, and exit back to the race track.
|
|
441
|
+
|
|
442
|
+
Team-mates share one service area. Every car enters through the queue spot first, but it only stops there when the active service spot is blocked. A second team car waits in the queue spot until the active service spot is physically clear, including the previous car's first movement out of the box, without blocking the main fast lane.
|
|
443
|
+
|
|
444
|
+
By default, built-in AI cars request an opportunistic `pitIntent: 1` below 50% tire energy and commit `pitIntent: 2` below 30%. Hosts can change those thresholds with `tirePitRequestThresholdPercent` and `tirePitCommitThresholdPercent`. Expert/headless controlled drivers do not receive those automatic tire-threshold calls and must request service with `pitIntent`.
|
|
445
|
+
|
|
446
|
+
Hosts can override the pit call with `setPitIntent(driverId, 0 | 1 | 2, 'H')` or expert action `{ pitIntent: 2, pitCompound: 'H' }`:
|
|
447
|
+
|
|
448
|
+
- `0` means no request
|
|
449
|
+
- `1` means keep trying until a free pit-entry window is available
|
|
450
|
+
- `2` means commit to entering at the next pit-entry window even when pit-lane capacity or gap checks would block an opportunistic stop
|
|
451
|
+
|
|
452
|
+
Completed stops can be re-armed later by tire condition or by `setPitIntent`, so pit stops are not one-use per race. Optional `pitStops.variability` uses `team.pitCrew` speed, consistency, and reliability to adjust service time and slow-stop chance; `pitStops.variability.perfect: true` forces deterministic default service time for training.
|
|
453
|
+
|
|
454
|
+
`setPitLaneOpen(false)` keeps new pending pit calls on track until reopened and the canvas shows a small red/green/yellow light near pit entry. `setRedFlagDeployed(true)` freezes race movement, closes the effective pit lane, and emits red-flag race-control state until cleared. The pit speed limiter applies on the straight main pit lane/working lane, not on the entry and exit connector roads, but automatic pit-entry routing still keeps connector speeds bounded so cars can reach the limiter safely.
|
|
455
|
+
|
|
456
|
+
Race behavior is configurable through `rules`. Flat existing options such as `standingStart: false` remain supported, and advanced behavior is grouped under module config:
|
|
457
|
+
|
|
458
|
+
```js
|
|
459
|
+
const simulator = await mountF1Simulator(root, {
|
|
460
|
+
drivers,
|
|
461
|
+
rules: {
|
|
462
|
+
ruleset: 'fia2025',
|
|
463
|
+
modules: {
|
|
464
|
+
pitStops: {
|
|
465
|
+
enabled: true,
|
|
466
|
+
pitLaneSpeedLimitKph: 80,
|
|
467
|
+
maxConcurrentPitLaneCars: 3,
|
|
468
|
+
minimumPitLaneGapMeters: 20,
|
|
469
|
+
tirePitRequestThresholdPercent: 50,
|
|
470
|
+
tirePitCommitThresholdPercent: 30,
|
|
471
|
+
variability: {
|
|
472
|
+
enabled: true,
|
|
473
|
+
perfect: false,
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
tireDegradation: {
|
|
477
|
+
enabled: true,
|
|
478
|
+
},
|
|
479
|
+
stalledDnf: {
|
|
480
|
+
enabled: true,
|
|
481
|
+
maxStoppedSeconds: 12,
|
|
482
|
+
speedThresholdKph: 5,
|
|
483
|
+
},
|
|
484
|
+
penalties: {
|
|
485
|
+
trackLimits: { strictness: 0.8 },
|
|
486
|
+
collision: { strictness: 0.5, consequences: [{ type: 'time', seconds: 5 }] },
|
|
487
|
+
tireRequirement: { strictness: 1, consequences: [{ type: 'time', seconds: 10 }] },
|
|
488
|
+
pitLaneSpeeding: { strictness: 1, speedLimitKph: 80 },
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
ui: {
|
|
493
|
+
penaltyBanners: true,
|
|
494
|
+
timingPenaltyBadges: true,
|
|
495
|
+
},
|
|
496
|
+
});
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
For deterministic single-skill training or visual checkpoint comparison, set `rules.modules.tireDegradation.enabled: false` so tyre energy remains fixed while the car still drives through normal steering, throttle, brake, and surface physics. `rules.modules.stalledDnf` defaults to `enabled: false` so base simulator and training environments keep stuck off-track cars live unless a host opts in. Set `enabled: true` to retire cars that are off legal racing or pit surfaces while below `speedThresholdKph` for `maxStoppedSeconds`.
|
|
500
|
+
|
|
501
|
+
Supported rulesets are `paddock`, `grandPrix2025`, `fia2025`, and `custom`. Presets only choose defaults; explicit module config wins. Weather, reliability, and fuel-load performance effects are reserved future modules and are not active 2.0.0 behavior. Penalty subsections use `strictness` from `0` to `1` instead of plain booleans. Track limits use the white line as the legal edge and require all four wheel contact patches to be fully outside the same side of the line before recording a violation, so normal kerb riding is not punished. Per-car `surface` is resolved from the worst wheel surface, snapshots include `car.wheels` for per-wheel surface and white-line state, and asymmetric left/right wheel resistance adds a small capped yaw tug toward the slower side when only one side is on a worse surface. Collision stewarding is driven by a body collision hull, not transparent sprite bounds or wheel-only overlap, and contact events include shape ids, contact type, depth, and time of impact. It considers impact severity, closing speed, and whether one car clearly hit another from behind; clear rear contact penalizes only the physically trailing car, including lapped traffic cases, while unclear meaningful contact records shared-fault penalties for both cars. Stalled off-track DNFs emit `car-dnf` with `reason: 'stalled-off-track'`, freeze the car, remove it from active control/collision/sensor/pit participation, and classify it with the existing DNF metadata. Pit-lane speeding is enforced on the main fast lane, working lane, service areas, and garage boxes, but not on pit-entry or pit-exit connector roads. Track-limit warnings are emitted as `track-limits` events, while penalty decisions are exposed through `snapshot.penalties` plus `penalty` events. Penalty consequences support warning, time, drive-through, stop-go, position-drop, grid-drop, and disqualification payloads. Time consequences are additive, drive-through and stop-go penalties are service obligations, and unserved service penalties convert to configured time at final classification.
|
|
502
|
+
|
|
503
|
+
`initialCameraMode` accepts `'overview'`, `'leader'`, `'selected'`, `'show-all'`, or `'pit'`; invalid values fall back to `'leader'`. The overview camera frames the active generated track bounds, including package-owned track padding and pit-lane extent, instead of using a fixed world-center zoom. Camera mode changes ease from the current camera target to the next target after the initial frame, so switching between leader, selected, overview, show-all, and pit views does not snap the world view.
|
|
504
|
+
|
|
505
|
+
The pit camera targets the generated operational pit-lane geometry, including the lane, boxes, service areas, and queue areas, while excluding the longer entry/exit access roads. It zooms out as needed to fit that work area inside the active race-view safe area, and its control is hidden when the active track has no pit lane.
|
|
506
|
+
|
|
507
|
+
Zoom buttons and wheel zoom apply to every camera mode. Zoom-out is bounded by the active generated track frame so the camera cannot pull far beyond the circuit. The renderer keeps grass coverage larger than the simulated world, and the transparent canvas host uses the same grass color as a fallback around the framed circuit.
|
|
508
|
+
|
|
509
|
+
`layoutPreset: 'left-tower-overlay'` creates a left broadcast gutter inside the race view, frames the camera around the remaining race area, and places the timing tower in that gutter without covering camera controls. The project/radio lower-third stays inside the race window and can intentionally render over the timing sidebar instead of shrinking around it.
|
|
510
|
+
|
|
511
|
+
Composable hosts should pass `{ includeRaceDataPanel: true }` to `mountRaceCanvas()` when they want that lower-third clipped and layered by the race window. `mountRaceDataPanel()` remains available for hosts that intentionally want the banner as a standalone surface.
|
|
512
|
+
|
|
513
|
+
`raceDataTelemetryDetail: true` makes the project lower-third include a compact S1/S2/S3 sector strip with live sector elapsed time and per-sector progress. That telemetry project lower-third stays visible until dismissed, muted, or replaced, while radio mode keeps its normal schedule. The standalone `mountTelemetrySectorBanner()` surface remains available only when a host explicitly mounts it.
|
|
514
|
+
|
|
515
|
+
`includeTimingTower: true` embeds the timing tower directly inside the race canvas and reserves camera space from the measured tower gutter when the tower is a side overlay. In narrow mobile hosts, package CSS stacks the embedded timing tower full-width and the camera stops reserving a fake left gutter.
|
|
516
|
+
|
|
517
|
+
`mountRaceTelemetryDrawer()` is a higher-level template that mounts an external top control row, race canvas, embedded timing tower, lower-third, top steward message, safety-car control, and a right telemetry drawer together. Pass `{ raceDataTelemetryDetail: true }` when the drawer lower-third should include compact sector detail.
|
|
518
|
+
|
|
519
|
+
The drawer top row contains camera controls, a `1x` simulation-speed button that cycles through `2x`, `3x`, `4x`, `5x`, `10x`, and back to `1x`, a `Mute banners` toggle, safety car, and the telemetry toggle so those controls do not cover the race. For other camera-control placements the speed button is hidden by default and can be enabled with `ui.simulationSpeedControl: true`.
|
|
520
|
+
|
|
521
|
+
`Mute banners` is off by default and temporarily suppresses project/radio lower-thirds while it is pressed; steward penalty banners are separate and remain controlled by `penaltyBanners`. Opening the drawer reduces the race area instead of overlaying it, and closing it removes the drawer from interaction. The drawer uses the same package-owned `telemetry-stack` component as `mountTelemetryPanel()`, so constrained host heights scroll telemetry vertically instead of letting the sidebar escape its frame.
|
|
522
|
+
|
|
523
|
+
Banner and timing layout options:
|
|
524
|
+
|
|
525
|
+
- `raceDataBanners.initial` selects the starting banner state: `'project'`, `'radio'`, or `'hidden'`.
|
|
526
|
+
- `raceDataBanners.enabled` chooses which banner types may appear.
|
|
527
|
+
- `raceDataBannerSize: 'auto'` uses the race space to the right of the timing board when it is wide enough and falls back to the full lower-third overlap when it is not.
|
|
528
|
+
- `raceDataBannerSize: 'custom'` preserves the default CSS-variable-driven lower-third size for hosts that want to tune their own banner geometry.
|
|
529
|
+
- `timingTowerVerticalFit: 'expand-race-view'` lets the race window grow tall enough for the tower.
|
|
530
|
+
- `timingTowerVerticalFit: 'scroll'` keeps the race window height and scrolls the timing list inside the cropped tower.
|
|
531
|
+
|
|
532
|
+
The same timing fit values can be passed to `mountRaceCanvas()` when `includeTimingTower` is enabled. Standalone timing towers are capped by `--timing-board-max-width` and fill their mount root height; placing the root in a fixed-height container makes only the timing entries scroll. Timing entries always stack from the top as fixed rows, so P1/P2 occupy the same vertical positions whether the race has 2 cars or 20.
|
|
533
|
+
|
|
534
|
+
The timing tower includes an `Int`/`Gap` broadcast switch: `Int` shows the interval to the car ahead, while `Gap` shows total gap to the leader. Seconds gaps are measured from hidden fixed timing-line crossings on the track. If a car is one or more whole laps behind in the selected mode, the tower shows labels such as `+1` or `+2` instead of a seconds estimate.
|
|
535
|
+
|
|
536
|
+
Other UI switches:
|
|
226
537
|
|
|
227
|
-
|
|
538
|
+
- `cameraControls` defaults to `'external'`; set it to `'embedded'` only when controls should intentionally appear inside the canvas, or `false` to omit them.
|
|
539
|
+
- `penaltyBanners: true` shows warnings and penalties in the top steward message instead of the project/radio lower-third.
|
|
540
|
+
- `showFps: false` hides the FPS readout.
|
|
541
|
+
- `telemetryIncludesOverview: false` keeps the car/driver overview out of the telemetry stack so hosts can mount `mountCarDriverOverview()` separately.
|
|
542
|
+
- `telemetryModules` controls optional package-owned telemetry surfaces: `core`, `sectors`, `lapTimes`, and `sectorTimes`.
|
|
228
543
|
|
|
229
|
-
|
|
544
|
+
Project/radio lower-thirds include a package-owned top-right close button that hides the current pill before its scheduled timeout. Time penalties put a large `+10s` style chip in the left block of the steward message and the affected car/rule beside it. Warning messages use warning colors and do not create timing-row `!` badges. The telemetry surfaces are also available as fully detached mount methods.
|
|
230
545
|
|
|
231
546
|
### Composable overlay layout contract
|
|
232
547
|
|
|
@@ -236,9 +551,9 @@ For the all-in-one simulator, call `mountF1Simulator()` and let PaddockJS genera
|
|
|
236
551
|
|
|
237
552
|
Mounted package surfaces include a lightweight red start-light loading overlay. The runtime removes each overlay after PixiJS, assets, controls, and the initial readouts are ready.
|
|
238
553
|
|
|
239
|
-
The runtime also pauses its render ticker when the race canvas is offscreen or the browser tab is hidden. This keeps pages with multiple PaddockJS embeds responsive without requiring host code to manually start and stop each simulator.
|
|
554
|
+
The runtime also pauses its render ticker when the race canvas is offscreen or the browser tab is hidden. This keeps pages with multiple PaddockJS embeds responsive without requiring host code to manually start and stop each simulator. At `5x` and `10x` browser playback, noncritical timing/readout DOM refreshes run at a lower cadence while fixed-step simulation and race events keep using authoritative race state.
|
|
240
555
|
|
|
241
|
-
Lifecycle callbacks are optional and host-owned. PaddockJS emits `onLoadingChange`, `onReady`, `onError`, `onDriverSelect`, `onRaceEvent`, `onLapChange`, and `onRaceFinish`; callback errors are routed to `onError` when provided and do not stop the simulator loop. Race snapshots include per-car interval timing, leader-gap timing, calibrated `speedKph`, automatic `track.sectors`, per-car `lapTelemetry`, finish state, `raceControl.winner` after the first finisher, and final `raceControl.classification` only after the whole field
|
|
556
|
+
Lifecycle callbacks are optional and host-owned. PaddockJS emits `onLoadingChange`, `onReady`, `onError`, `onDriverSelect`, `onRaceEvent`, `onLapChange`, and `onRaceFinish`; callback errors are routed to `onError` when provided and do not stop the simulator loop. Race snapshots include per-car interval timing, leader-gap timing, whole-lap gap counts, calibrated `speedKph`, automatic `track.sectors`, hidden `track.timingLines`, per-car `lapTelemetry`, finish state, `raceControl.winner` after the first finisher, and final `raceControl.classification` only after the whole field is finished or DNF. Sector telemetry clears future-sector values so banners and sidebars show completed splits before the active sector plus the active live timer, not stale later-sector entries. Cars that have crossed the line before full race completion expose `raceStatus: 'waved-flag'` / `wavedFlag: true` and stay frozen in provisional finish order; later barrier contact or stalled-off-track detection does not turn that result into DNF. Destroyed/out-of-race cars expose DNF metadata, show `DNF` at the bottom of the timing tower, render faded/gray in the race canvas, and appear after finishers in final classification with no finish time. If a DNF car is restored before final classification, it re-enters live timing and the race waits for it again; once `raceControl.finished` is true, classification stays final. Final classification applies time penalties and unserved service conversions through `adjustedFinishTime`, then applies position-drop and disqualification consequences to finishers before DNF entries. The field then circulates in safety-car mode and the race canvas shows a package-owned winner banner.
|
|
242
557
|
|
|
243
558
|
## License
|
|
244
559
|
|