@inventure71/paddockjs 4.1.0 → 4.3.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 +76 -0
- package/INSTALL_AND_UPDATE.md +31 -5
- package/README.md +34 -3
- package/docs/advanced_ai_pace.md +131 -0
- package/docs/advanced_physics_rebuild.md +166 -0
- package/docs/architecture.md +111 -30
- package/docs/cleanup_coverage.md +284 -0
- package/docs/component_inventory.md +32 -16
- package/docs/composable-layouts.md +2 -0
- package/docs/concepts.md +12 -1
- package/docs/custom_model_controller.md +1 -1
- package/docs/data_contract.md +33 -10
- package/docs/data_model.md +4 -2
- package/docs/efficiency_cleanup_2026-10-13.md +80 -0
- package/docs/getting-started.md +3 -0
- package/docs/grid_walk.md +80 -0
- package/docs/index.md +5 -2
- package/docs/keyboard_driving_fix.md +118 -0
- package/docs/limit_driving_2026-10-14.md +88 -0
- package/docs/loading.md +141 -0
- package/docs/maintainability_audit_2026-09-08.md +146 -0
- package/docs/racing_ai_improvements.md +145 -0
- package/docs/rules.md +43 -13
- package/docs/sense_contract.md +4 -1
- package/docs/system_specs.md +40 -12
- package/docs/testing-reliability-guide.md +67 -0
- package/docs/v11_improvements.md +108 -0
- package/package.json +23 -15
- package/src/api/MountedSimulatorComponents.js +101 -0
- package/src/api/PaddockSimulatorController.js +56 -81
- package/src/app/BrowserExpertAdapter.js +0 -6
- package/src/app/BrowserExpertExternalRenderer.js +72 -50
- package/src/app/ExternalTrackSnapshot.js +50 -0
- package/src/app/F1SimulatorApp.js +242 -297
- package/src/app/HostLifecycleEmitter.js +93 -0
- package/src/app/banners/raceDataBannerController.js +9 -4
- package/src/app/camera/cameraConstants.js +1 -1
- package/src/app/camera/cameraController.js +10 -13
- package/src/app/camera/cameraGeometry.js +1 -1
- package/src/app/controls/SimulatorViewControls.js +45 -0
- package/src/app/controls/workbenchBindings.js +64 -0
- package/src/app/controls/workbenchDisclosure.js +41 -0
- package/src/app/domBindings.js +21 -13
- package/src/app/gridWalk/GridWalkController.js +180 -0
- package/src/app/gridWalk/gridWalkCamera.js +88 -0
- package/src/app/gridWalk/gridWalkControls.js +24 -0
- package/src/app/gridWalk/gridWalkCrew.js +246 -0
- package/src/app/gridWalk/gridWalkLabels.js +104 -0
- package/src/app/gridWalk/gridWalkLayout.js +46 -0
- package/src/app/gridWalk/gridWalkNavigation.js +99 -0
- package/src/app/gridWalk/gridWalkProjectBanner.js +43 -0
- package/src/app/gridWalk/gridWalkSession.js +50 -0
- package/src/app/layoutSupport.js +2 -0
- package/src/app/raceOverlayClearanceSupport.js +21 -7
- package/src/app/readouts/carOverviewRenderer.js +9 -4
- package/src/app/readouts/readoutFormatters.js +1 -8
- package/src/app/readouts/telemetryRenderer.js +1 -3
- package/src/app/readouts/timingTowerRenderer.js +48 -50
- package/src/app/rendering/appAssets.js +8 -10
- package/src/app/rendering/carRenderer.js +27 -79
- package/src/app/rendering/displayUtils.js +0 -6
- package/src/app/rendering/expertSensorRenderer.js +1 -1
- package/src/app/rendering/replayGhostRenderer.js +4 -1
- package/src/app/rendering/trackRenderer.js +2 -2
- package/src/app/runtime/frameLoop.js +18 -17
- package/src/app/runtime/pixiStartupLifecycle.js +94 -0
- package/src/app/runtime/runtimeTiming.js +4 -1
- package/src/app/runtime/runtimeVisibility.js +7 -2
- package/src/config/cssValues.js +1 -1
- package/src/config/defaultOptions.js +12 -173
- package/src/config/restartOptions.js +1 -0
- package/src/config/runtimeSeed.js +10 -0
- package/src/config/simulatorDefaults.js +106 -0
- package/src/config/telemetryModules.js +20 -0
- package/src/config/theme/cssTokens.js +85 -0
- package/src/config/theme/themeCss.js +72 -0
- package/src/config/theme/themeInputs.js +155 -0
- package/src/config/theme/themeResolver.js +172 -0
- package/src/config/theme/themeSelectors.js +69 -0
- package/src/config/theme/themeTokens.js +257 -0
- package/src/config/theme/themeUtils.js +15 -0
- package/src/config/themeOptions.js +14 -830
- package/src/config/timingGapMode.js +0 -2
- package/src/config/uiOptions.js +53 -0
- package/src/data/championship.js +16 -158
- package/src/data/championshipDefaults.js +87 -0
- package/src/data/driverData.js +10 -20
- package/src/data/entryIdentity.js +67 -0
- package/src/data/entryPresentation.js +23 -0
- package/src/data/entryTypes.d.ts +160 -0
- package/src/data/index.d.ts +12 -195
- package/src/data/ratingScale.js +14 -0
- package/src/data/teamTypes.d.ts +23 -0
- package/src/data/trackTypes.d.ts +101 -0
- package/src/data/vehicleData.js +12 -23
- package/src/environment/actions.js +3 -2
- package/src/environment/controllerLoop.js +57 -44
- package/src/environment/controllerScheduler.js +30 -0
- package/src/environment/driverObservations.js +260 -0
- package/src/environment/driverReset.js +51 -0
- package/src/environment/episode.js +0 -1
- package/src/environment/evaluation.js +6 -90
- package/src/environment/evaluationTracker.js +100 -0
- package/src/environment/events.js +23 -0
- package/src/environment/index.d.ts +35 -91
- package/src/environment/metrics.js +3 -17
- package/src/environment/observationSchema.js +104 -0
- package/src/environment/observationVector.js +16 -115
- package/src/environment/observations.js +16 -316
- package/src/environment/options.js +5 -24
- package/src/environment/renderFrames.js +21 -0
- package/src/environment/resetOptions.js +41 -0
- package/src/environment/results.js +125 -0
- package/src/environment/rewards.js +10 -16
- package/src/environment/runtime.js +17 -300
- package/src/environment/scenarioOptions.js +90 -0
- package/src/environment/scenarioPlacements.js +70 -0
- package/src/environment/scenarioPresets.js +78 -0
- package/src/environment/scenarios.js +5 -236
- package/src/environment/scratch.js +18 -0
- package/src/environment/sensorOptions.js +20 -0
- package/src/environment/sensors/index.js +2 -556
- package/src/environment/sensors/indexedRayBands.js +0 -18
- package/src/environment/sensors/nearbyCars.js +18 -15
- package/src/environment/sensors/opponentRadar.js +3 -2
- package/src/environment/sensors/pitConnectorProximity.js +20 -0
- package/src/environment/sensors/rayBandTrace.js +1 -37
- package/src/environment/sensors/rayBatch.js +81 -0
- package/src/environment/sensors/rayConfig.js +26 -0
- package/src/environment/sensors/rayGeometry.js +0 -8
- package/src/environment/sensors/rayGuards.js +0 -6
- package/src/environment/sensors/rayOutputs.js +75 -0
- package/src/environment/sensors/rayQuery.js +110 -0
- package/src/environment/sensors/rayScratch.js +146 -0
- package/src/environment/sensors/sensorTargets.js +12 -4
- package/src/environment/sensors/surfaceRays.js +6 -61
- package/src/environment/sensors/trackRays.js +7 -80
- package/src/environment/simulationSetup.js +30 -0
- package/src/environment/specs.js +15 -109
- package/src/index.d.ts +43 -202
- package/src/index.js +28 -6
- package/src/placeholder/index.js +1 -8
- package/src/rendering/displayLifecycle.js +6 -0
- package/src/rendering/proceduralTrackAsset.js +1 -1
- package/src/rendering/renderSnapshot.js +3 -0
- package/src/rendering/track/finishLineRenderer.js +1 -1
- package/src/rendering/track/gridRenderer.js +1 -1
- package/src/rendering/track/offsetStrokeSafety.js +2 -2
- package/src/rendering/track/pitLaneRenderer.js +1 -1
- package/src/rendering/track/trackMaterialRenderer.js +4 -4
- package/src/rendering/track/trackRenderConstants.js +0 -1
- package/src/rendering/track/trackRenderGeometry.js +1 -7
- package/src/simulation/collisionGeometry.js +12 -20
- package/src/simulation/driver/advancedPathControls.js +53 -0
- package/src/simulation/driver/advancedRacePace.js +112 -0
- package/src/simulation/driver/advancedRacingControls.js +61 -0
- package/src/simulation/driver/advancedRacingEnvelope.js +255 -0
- package/src/simulation/driver/advancedRacingSteering.js +76 -0
- package/src/simulation/driver/advancedRacingTiming.js +16 -0
- package/src/simulation/driver/arcadeRacePace.js +83 -0
- package/src/simulation/driver/arcadeRacingControls.js +111 -0
- package/src/simulation/driver/arcadeRacingEnvelope.js +63 -0
- package/src/simulation/driver/driverControlConstants.js +0 -2
- package/src/simulation/driver/driverController.js +16 -5
- package/src/simulation/driver/edgeRecovery.js +2 -3
- package/src/simulation/driver/racingControls.js +10 -396
- package/src/simulation/driver/racingDriverProfile.js +48 -0
- package/src/simulation/driver/racingLinePlan.js +54 -20
- package/src/simulation/driver/rejoinControls.js +59 -112
- package/src/simulation/driver/safetyCarControls.js +12 -0
- package/src/simulation/driver/trafficScan.js +136 -27
- package/src/simulation/participants/participantInteractions.js +24 -15
- package/src/simulation/pit/pitCarPlacement.js +29 -0
- package/src/simulation/pit/pitFlow.js +8 -30
- package/src/simulation/pit/pitIntent.js +4 -3
- package/src/simulation/pit/pitOccupancy.js +2 -2
- package/src/simulation/pit/pitQueue.js +2 -18
- package/src/simulation/pit/pitRouteMovement.js +1 -36
- package/src/simulation/pit/pitRouting.js +5 -81
- package/src/simulation/pit/pitService.js +3 -32
- package/src/simulation/pit/pitServiceConstants.js +1 -0
- package/src/simulation/pit/pitServiceProgress.js +34 -0
- package/src/simulation/pit/pitSnapshots.js +8 -4
- package/src/simulation/pit/pitState.js +1 -5
- package/src/simulation/race/classification.js +1 -8
- package/src/simulation/race/raceFinish.js +3 -8
- package/src/simulation/race/raceOrder.js +2 -13
- package/src/simulation/race/raceProgress.js +6 -20
- package/src/simulation/race/raceSetup.js +1 -1
- package/src/simulation/race/raceStep.js +20 -11
- package/src/simulation/race/redFlag.js +2 -4
- package/src/simulation/race/safetyCar.js +5 -9
- package/src/simulation/race/stalledDnf.js +2 -4
- package/src/simulation/raceSimulation.js +6 -38
- package/src/simulation/replay/replayGhosts.js +44 -32
- package/src/simulation/rules/collisionSteward.js +0 -14
- package/src/simulation/rules/penaltyActions.js +37 -0
- package/src/simulation/rules/penaltyLedger.js +8 -1
- package/src/simulation/rules/pitLaneSpeedingSteward.js +1 -1
- package/src/simulation/rules/rulesReview.js +20 -16
- package/src/simulation/rules/trackLimitsSteward.js +2 -2
- package/src/simulation/simMath.js +4 -0
- package/src/simulation/snapshots/raceSnapshots.js +30 -11
- package/src/simulation/timing/drsState.js +8 -0
- package/src/simulation/timing/drsTiming.js +2 -4
- package/src/simulation/timing/lapTelemetry.js +7 -4
- package/src/simulation/timing/sectorPerformance.js +14 -6
- package/src/simulation/timing/timingLines.js +12 -6
- package/src/simulation/track/pitLaneAccess.js +2 -2
- package/src/simulation/track/pitLaneLayout.js +4 -135
- package/src/simulation/track/pitLaneModel.js +70 -0
- package/src/simulation/track/pitLaneState.js +0 -1
- package/src/simulation/track/pitServiceLayout.js +121 -0
- package/src/simulation/track/proceduralTrack.js +77 -0
- package/src/simulation/track/spatialQueries.js +76 -31
- package/src/simulation/track/trackBuilder.js +54 -0
- package/src/simulation/track/trackConstants.js +0 -22
- package/src/simulation/track/trackMath.js +4 -29
- package/src/simulation/track/trackModel.js +12 -240
- package/src/simulation/track/trackModelCache.js +105 -0
- package/src/simulation/track/trackNearestQueries.js +1218 -0
- package/src/simulation/track/trackQueryConstants.js +3 -0
- package/src/simulation/track/trackQueryConstruction.js +368 -0
- package/src/simulation/track/trackQueryIndex.js +12 -1933
- package/src/simulation/track/trackQuerySegments.js +174 -0
- package/src/simulation/track/trackQueryStats.js +12 -0
- package/src/simulation/track/trackRayQueries.js +165 -0
- package/src/simulation/vehicle/advancedContactResponse.js +89 -0
- package/src/simulation/vehicle/advancedTireForces.js +92 -0
- package/src/simulation/vehicle/advancedVehicleModel.js +65 -0
- package/src/simulation/vehicle/advancedVehiclePhysics.js +127 -0
- package/src/simulation/vehicle/contactResolution.js +23 -9
- package/src/simulation/vehicle/mainTrackWheelSurface.js +2 -13
- package/src/simulation/vehicle/pitWheelSurface.js +0 -12
- package/src/simulation/vehicle/runoffResponse.js +2 -4
- package/src/simulation/vehicle/sampledWheelSurface.js +266 -0
- package/src/simulation/vehicle/vehicleGeometry.js +85 -103
- package/src/simulation/vehicle/vehicleKinematics.js +10 -0
- package/src/simulation/vehicle/vehiclePhysics.js +42 -196
- package/src/simulation/vehicle/vehicleSnapshots.js +18 -6
- package/src/simulation/vehicle/vehicleState.js +5 -3
- package/src/simulation/vehicle/wheelSurface.js +13 -432
- package/src/simulation/vehicle/wheelSurfaceCache.js +55 -0
- package/src/simulation/vehicle/wheelSurfaceSummary.js +101 -0
- package/src/styles.css +173 -19
- package/src/ui/bannerTemplates.js +4 -2
- package/src/ui/cameraControlsTemplate.js +4 -2
- package/src/ui/gridWalkTemplate.js +29 -0
- package/src/ui/htmlEscaping.js +8 -0
- package/src/ui/raceCanvasTemplate.js +3 -2
- package/src/ui/shellTemplate.js +3 -0
- package/src/ui/telemetryDrawerTemplate.js +4 -2
- package/src/ui/telemetryTemplates.js +3 -22
- package/src/ui/templateUtils.js +2 -8
- package/src/ui/viewControlsTemplate.js +21 -0
- package/examples/train-basic-policy.mjs +0 -276
- package/examples/trainingData.mjs +0 -133
|
@@ -25,7 +25,7 @@ function writeLapTelemetryPosition(target, track, raceDistance, totalLaps = Infi
|
|
|
25
25
|
const sectorIndex = Math.min(TELEMETRY_SECTOR_COUNT - 1, Math.floor(lapProgress / sectorLength));
|
|
26
26
|
const sectorStart = sectorIndex * sectorLength;
|
|
27
27
|
|
|
28
|
-
target.completedLaps = Math.floor(positiveDistance / track.length);
|
|
28
|
+
target.completedLaps = Math.min(Math.floor(positiveDistance / track.length), totalLaps);
|
|
29
29
|
target.currentLap = Math.max(1, lapIndex + 1);
|
|
30
30
|
target.currentSector = sectorIndex + 1;
|
|
31
31
|
target.currentSectorProgress = clamp((lapProgress - sectorStart) / sectorLength, 0, 1);
|
|
@@ -143,7 +143,10 @@ export function updateLapTelemetry(car, previousRaceDistance, currentTime, track
|
|
|
143
143
|
telemetry.lastSectors = copySectorTimes(telemetry.lastSectors, telemetry.currentSectors);
|
|
144
144
|
clearSectorTimes(telemetry.currentSectors);
|
|
145
145
|
telemetry.currentLapStartedAt = crossingTime;
|
|
146
|
-
telemetry.completedLaps = Math.
|
|
146
|
+
telemetry.completedLaps = Math.min(
|
|
147
|
+
totalLaps,
|
|
148
|
+
Math.max(telemetry.completedLaps + 1, Math.floor(boundaryDistance / track.length)),
|
|
149
|
+
);
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
telemetry.currentSectorStartedAt = crossingTime;
|
|
@@ -207,7 +210,7 @@ function syncInProgressLapTelemetry(telemetry, currentTime, currentRaceDistance,
|
|
|
207
210
|
const sectorProgress = ensureSectorTimesArray(telemetry.sectorProgress);
|
|
208
211
|
const liveSectors = ensureSectorTimesArray(telemetry.liveSectors);
|
|
209
212
|
|
|
210
|
-
telemetry.completedLaps = Math.floor(positiveDistance / track.length);
|
|
213
|
+
telemetry.completedLaps = Math.min(Math.floor(positiveDistance / track.length), totalLaps);
|
|
211
214
|
telemetry.currentLap = Math.max(1, lapIndex + 1);
|
|
212
215
|
telemetry.currentSector = activeIndex + 1;
|
|
213
216
|
telemetry.currentSectorProgress = clamp((lapProgress - sectorStart) / sectorLength, 0, 1);
|
|
@@ -234,7 +237,7 @@ function syncLapTelemetryPosition(telemetry, currentTime, currentRaceDistance, t
|
|
|
234
237
|
preserveCompletedSectors,
|
|
235
238
|
});
|
|
236
239
|
telemetry.sectorProgress = sectorProgress;
|
|
237
|
-
telemetry.completedLaps = Math.
|
|
240
|
+
telemetry.completedLaps = Math.min(telemetry.completedLaps, totalLaps);
|
|
238
241
|
telemetry.currentLapTime = Math.max(0, currentTime - telemetry.currentLapStartedAt);
|
|
239
242
|
telemetry.currentSectorElapsed = Math.max(0, currentTime - telemetry.currentSectorStartedAt);
|
|
240
243
|
syncLiveSectorTelemetry(telemetry, { preserveCompletedSectors });
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { finiteOrNull } from '../simMath.js';
|
|
2
|
+
export { finiteOrNull } from '../simMath.js';
|
|
3
|
+
|
|
1
4
|
import { TELEMETRY_SECTOR_COUNT } from './timingConstants.js';
|
|
2
5
|
|
|
3
6
|
const OVERALL_BEST_0 = '_sectorPerformanceOverallBest0';
|
|
@@ -5,7 +8,7 @@ const OVERALL_BEST_1 = '_sectorPerformanceOverallBest1';
|
|
|
5
8
|
const OVERALL_BEST_2 = '_sectorPerformanceOverallBest2';
|
|
6
9
|
|
|
7
10
|
export function createEmptySectorTimes() {
|
|
8
|
-
return Array
|
|
11
|
+
return new Array(TELEMETRY_SECTOR_COUNT).fill(null);
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
export function createEmptySectorPerformance() {
|
|
@@ -17,11 +20,19 @@ export function createEmptySectorPerformance() {
|
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
export function serializeSectorTimes(values) {
|
|
20
|
-
|
|
23
|
+
const result = new Array(TELEMETRY_SECTOR_COUNT);
|
|
24
|
+
for (let index = 0; index < TELEMETRY_SECTOR_COUNT; index += 1) {
|
|
25
|
+
result[index] = finiteOrNull(values?.[index]);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
export function serializeSectorPerformance(values) {
|
|
24
|
-
|
|
31
|
+
const result = new Array(TELEMETRY_SECTOR_COUNT);
|
|
32
|
+
for (let index = 0; index < TELEMETRY_SECTOR_COUNT; index += 1) {
|
|
33
|
+
result[index] = values?.[index] ?? null;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
25
36
|
}
|
|
26
37
|
|
|
27
38
|
export function updateSectorPerformance(cars, stats = null) {
|
|
@@ -100,9 +111,6 @@ export function updateSectorPerformance(cars, stats = null) {
|
|
|
100
111
|
return true;
|
|
101
112
|
}
|
|
102
113
|
|
|
103
|
-
export function finiteOrNull(value) {
|
|
104
|
-
return Number.isFinite(value) ? value : null;
|
|
105
|
-
}
|
|
106
114
|
|
|
107
115
|
function classifySectorPerformance(value, personalBest, overallBest) {
|
|
108
116
|
if (!Number.isFinite(value)) return null;
|
|
@@ -76,7 +76,13 @@ export function createTimingLines(track) {
|
|
|
76
76
|
export function getTimingLineNumber(track, raceDistance) {
|
|
77
77
|
const spacing = track.timingLines?.spacing;
|
|
78
78
|
if (!Number.isFinite(spacing) || spacing <= 0 || !Number.isFinite(raceDistance)) return null;
|
|
79
|
-
|
|
79
|
+
const distance = Math.max(0, raceDistance);
|
|
80
|
+
let lineNumber = Math.floor(distance / spacing);
|
|
81
|
+
// Division can round onto a line whose stored product is still ahead of
|
|
82
|
+
// the car. Use the same representable boundary for lookup and recording.
|
|
83
|
+
if (lineNumber > 0 && lineNumber * spacing > distance) lineNumber -= 1;
|
|
84
|
+
else if ((lineNumber + 1) * spacing <= distance) lineNumber += 1;
|
|
85
|
+
return lineNumber;
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
export function resetTimingLineCrossings(car, currentTime) {
|
|
@@ -105,7 +111,7 @@ export function recordTimingLineCrossings(car, previousRaceDistance, currentTime
|
|
|
105
111
|
? latestLine - (track.timingLines.count * TIMING_LINE_HISTORY_LAPS)
|
|
106
112
|
: null;
|
|
107
113
|
|
|
108
|
-
if (
|
|
114
|
+
if (travelled === 0) {
|
|
109
115
|
car.timingLineLastUpdatedAt = currentTime;
|
|
110
116
|
if (!Number.isFinite(cutoff) || cutoff <= 0 || cutoff === car.timingLinePruneCutoff) return;
|
|
111
117
|
pruneTimingLineCrossings(car, cutoff);
|
|
@@ -113,12 +119,12 @@ export function recordTimingLineCrossings(car, previousRaceDistance, currentTime
|
|
|
113
119
|
return;
|
|
114
120
|
}
|
|
115
121
|
|
|
116
|
-
if (travelled >
|
|
117
|
-
const firstLine =
|
|
118
|
-
const lastLine =
|
|
122
|
+
if (travelled > 0 && travelled < track.length / 2) {
|
|
123
|
+
const firstLine = getTimingLineNumber(track, previousDistance) + 1;
|
|
124
|
+
const lastLine = getTimingLineNumber(track, currentDistance);
|
|
119
125
|
for (let lineNumber = firstLine; lineNumber <= lastLine; lineNumber += 1) {
|
|
120
126
|
const lineDistance = lineNumber * spacing;
|
|
121
|
-
if (lineDistance <= previousDistance
|
|
127
|
+
if (lineDistance <= previousDistance || lineDistance > currentDistance) continue;
|
|
122
128
|
const ratio = clamp((lineDistance - previousDistance) / travelled, 0, 1);
|
|
123
129
|
setTimingLineCrossing(car, lineNumber, previousTime + ratio * elapsed);
|
|
124
130
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { wrapDistance } from '../simMath.js';
|
|
2
|
+
import { PIT_ACCESS_SAMPLE_STEPS, PIT_ACCESS_SEARCH_STEP, PIT_ACCESS_TRACK_OVERLAP } from './trackConstants.js';
|
|
3
3
|
import { angleBetweenVectors, headingVector, normalizeVector, sampleCubicBezier, signedLateralOffsetToPoint } from './trackMath.js';
|
|
4
4
|
import { offsetTrackPoint, pointAt } from './spatialQueries.js';
|
|
5
5
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { clamp } from '../simMath.js';
|
|
2
2
|
import { metersToSimUnits } from '../units.js';
|
|
3
|
-
import { WORLD, PIT_BOX_COUNT, PIT_BOX_DEPTH,
|
|
3
|
+
import { WORLD, PIT_BOX_COUNT, PIT_BOX_DEPTH, PIT_BOX_TO_LANE_GAP, PIT_ENTRY_SEARCH_AFTER, PIT_ENTRY_SEARCH_BEFORE, PIT_EXIT_SEARCH_AFTER, PIT_EXIT_SEARCH_BEFORE, PIT_LANE_EDGE_GAP, PIT_LANE_ENTRY_BUFFER, PIT_LANE_EXIT_BUFFER, PIT_LANE_FINISH_RATIO, PIT_LANE_OFFSET_SEARCH_STEP, PIT_LANE_WIDTH, PIT_SERVICE_AREA_DEPTH, PIT_TEAM_COUNT, PIT_BOXES_PER_TEAM, PIT_WORKING_LANE_GAP, PIT_WORKING_LANE_WIDTH, PIT_ACCESS_MAX_LENGTH, PIT_ACCESS_MIN_LENGTH, PIT_ACCESS_TANGENT_RATIO, PIT_TRACK_CLEARANCE_MARGIN } from './trackConstants.js';
|
|
4
4
|
import { clonePoint, distance, headingVector, interpolatePitPoint, nearestPointOnPolyline, normalizeVector, pointWorldClearance, projectPitPoint, createPointBounds } from './trackMath.js';
|
|
5
5
|
import { findPitAccessConnection, createPitAccessRoadCenterline } from './pitLaneAccess.js';
|
|
6
6
|
import { pointAt } from './spatialQueries.js';
|
|
7
|
+
import { createPitBoxes, getPitBoxRunLength } from './pitServiceLayout.js';
|
|
8
|
+
|
|
9
|
+
export { getPitBoxRunLength, createPitBoxCorners, createPitRectangleCorners, createPitBoxes } from './pitServiceLayout.js';
|
|
7
10
|
|
|
8
11
|
export function createStartStraightBasis(track) {
|
|
9
12
|
const finish = pointAt(track, 0);
|
|
@@ -20,20 +23,6 @@ export function createStartStraightBasis(track) {
|
|
|
20
23
|
};
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
export function getPitBoxRunLength({
|
|
24
|
-
teamCount = PIT_TEAM_COUNT,
|
|
25
|
-
boxesPerTeam = PIT_BOXES_PER_TEAM,
|
|
26
|
-
boxLength = PIT_BOX_LENGTH,
|
|
27
|
-
pairGap = PIT_BOX_PAIR_GAP,
|
|
28
|
-
teamGap = PIT_TEAM_GAP,
|
|
29
|
-
} = {}) {
|
|
30
|
-
const boxCount = teamCount * boxesPerTeam;
|
|
31
|
-
return (
|
|
32
|
-
boxCount * boxLength +
|
|
33
|
-
teamCount * Math.max(0, boxesPerTeam - 1) * pairGap +
|
|
34
|
-
Math.max(0, teamCount - 1) * teamGap
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
26
|
|
|
38
27
|
export function createPitLaneLayout() {
|
|
39
28
|
const runLength = getPitBoxRunLength();
|
|
@@ -130,128 +119,8 @@ export function choosePitLanePlacement(track, baseLaneOffset, layout) {
|
|
|
130
119
|
return candidates.sort((left, right) => right.score - left.score)[0];
|
|
131
120
|
}
|
|
132
121
|
|
|
133
|
-
export function createPitBoxCorners(center, forward, serviceNormal) {
|
|
134
|
-
const halfLength = PIT_BOX_LENGTH / 2;
|
|
135
|
-
const halfDepth = PIT_BOX_DEPTH / 2;
|
|
136
|
-
return [
|
|
137
|
-
{
|
|
138
|
-
x: center.x + forward.x * halfLength + serviceNormal.x * halfDepth,
|
|
139
|
-
y: center.y + forward.y * halfLength + serviceNormal.y * halfDepth,
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
x: center.x - forward.x * halfLength + serviceNormal.x * halfDepth,
|
|
143
|
-
y: center.y - forward.y * halfLength + serviceNormal.y * halfDepth,
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
x: center.x - forward.x * halfLength - serviceNormal.x * halfDepth,
|
|
147
|
-
y: center.y - forward.y * halfLength - serviceNormal.y * halfDepth,
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
x: center.x + forward.x * halfLength - serviceNormal.x * halfDepth,
|
|
151
|
-
y: center.y + forward.y * halfLength - serviceNormal.y * halfDepth,
|
|
152
|
-
},
|
|
153
|
-
];
|
|
154
|
-
}
|
|
155
122
|
|
|
156
|
-
export function createPitRectangleCorners(center, forward, serviceNormal, length, depth) {
|
|
157
|
-
const halfLength = length / 2;
|
|
158
|
-
const halfDepth = depth / 2;
|
|
159
|
-
return [
|
|
160
|
-
{
|
|
161
|
-
x: center.x + forward.x * halfLength + serviceNormal.x * halfDepth,
|
|
162
|
-
y: center.y + forward.y * halfLength + serviceNormal.y * halfDepth,
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
x: center.x - forward.x * halfLength + serviceNormal.x * halfDepth,
|
|
166
|
-
y: center.y - forward.y * halfLength + serviceNormal.y * halfDepth,
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
x: center.x - forward.x * halfLength - serviceNormal.x * halfDepth,
|
|
170
|
-
y: center.y - forward.y * halfLength - serviceNormal.y * halfDepth,
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
x: center.x + forward.x * halfLength - serviceNormal.x * halfDepth,
|
|
174
|
-
y: center.y + forward.y * halfLength - serviceNormal.y * halfDepth,
|
|
175
|
-
},
|
|
176
|
-
];
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export function createPitBoxes({ laneStart, laneForward, laneLength, serviceNormal }) {
|
|
180
|
-
const runLength = getPitBoxRunLength();
|
|
181
|
-
let cursor = Math.max(PIT_SERVICE_QUEUE_GAP + PIT_BOX_LENGTH / 2, (laneLength - runLength) / 2);
|
|
182
|
-
const workingLaneOffset = PIT_LANE_WIDTH / 2 + PIT_WORKING_LANE_GAP + PIT_WORKING_LANE_WIDTH / 2;
|
|
183
|
-
const boxLateral = workingLaneOffset + PIT_WORKING_LANE_WIDTH / 2 + PIT_BOX_TO_LANE_GAP + PIT_BOX_DEPTH / 2;
|
|
184
|
-
const boxes = [];
|
|
185
|
-
const serviceAreas = [];
|
|
186
|
-
|
|
187
|
-
for (let index = 0; index < PIT_BOX_COUNT; index += 1) {
|
|
188
|
-
const distanceAlongLane = cursor + PIT_BOX_LENGTH / 2;
|
|
189
|
-
const laneTarget = interpolatePitPoint(laneStart, laneForward, distanceAlongLane);
|
|
190
|
-
const center = {
|
|
191
|
-
x: laneTarget.x + serviceNormal.x * boxLateral,
|
|
192
|
-
y: laneTarget.y + serviceNormal.y * boxLateral,
|
|
193
|
-
};
|
|
194
|
-
const teamIndex = Math.floor(index / PIT_BOXES_PER_TEAM);
|
|
195
|
-
const teamBoxIndex = index % PIT_BOXES_PER_TEAM;
|
|
196
123
|
|
|
197
|
-
boxes.push({
|
|
198
|
-
id: `team-${teamIndex + 1}-box-${teamBoxIndex + 1}`,
|
|
199
|
-
index,
|
|
200
|
-
teamIndex,
|
|
201
|
-
teamBoxIndex,
|
|
202
|
-
distanceAlongLane,
|
|
203
|
-
laneTarget,
|
|
204
|
-
center,
|
|
205
|
-
length: PIT_BOX_LENGTH,
|
|
206
|
-
depth: PIT_BOX_DEPTH,
|
|
207
|
-
corners: createPitBoxCorners(center, laneForward, serviceNormal),
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
if (teamBoxIndex === PIT_BOXES_PER_TEAM - 1) {
|
|
211
|
-
const firstTeamBox = boxes[index - (PIT_BOXES_PER_TEAM - 1)];
|
|
212
|
-
const serviceDistance = (firstTeamBox.distanceAlongLane + distanceAlongLane) / 2;
|
|
213
|
-
const queueDistance = Math.max(PIT_SERVICE_QUEUE_GAP / 2, serviceDistance - PIT_SERVICE_QUEUE_GAP);
|
|
214
|
-
const serviceCenter = projectPitPoint(
|
|
215
|
-
laneStart,
|
|
216
|
-
laneForward,
|
|
217
|
-
serviceNormal,
|
|
218
|
-
serviceDistance,
|
|
219
|
-
workingLaneOffset,
|
|
220
|
-
);
|
|
221
|
-
const queuePoint = projectPitPoint(
|
|
222
|
-
laneStart,
|
|
223
|
-
laneForward,
|
|
224
|
-
serviceNormal,
|
|
225
|
-
queueDistance,
|
|
226
|
-
workingLaneOffset,
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
serviceAreas.push({
|
|
230
|
-
id: `team-${teamIndex + 1}-service`,
|
|
231
|
-
index: teamIndex,
|
|
232
|
-
teamIndex,
|
|
233
|
-
distanceAlongLane: serviceDistance,
|
|
234
|
-
queueDistanceAlongLane: queueDistance,
|
|
235
|
-
laneTarget: serviceCenter,
|
|
236
|
-
center: serviceCenter,
|
|
237
|
-
queuePoint,
|
|
238
|
-
length: PIT_SERVICE_AREA_LENGTH,
|
|
239
|
-
depth: PIT_SERVICE_AREA_DEPTH,
|
|
240
|
-
corners: createPitRectangleCorners(serviceCenter, laneForward, serviceNormal, PIT_SERVICE_AREA_LENGTH, PIT_SERVICE_AREA_DEPTH),
|
|
241
|
-
queueCorners: createPitRectangleCorners(queuePoint, laneForward, serviceNormal, PIT_SERVICE_AREA_LENGTH * 0.72, PIT_SERVICE_AREA_DEPTH),
|
|
242
|
-
garageBoxIds: boxes
|
|
243
|
-
.slice(index - (PIT_BOXES_PER_TEAM - 1), index + 1)
|
|
244
|
-
.map((box) => box.id),
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
cursor += PIT_BOX_LENGTH;
|
|
249
|
-
if (teamBoxIndex === 0) cursor += PIT_BOX_PAIR_GAP;
|
|
250
|
-
else if (teamIndex < PIT_TEAM_COUNT - 1) cursor += PIT_TEAM_GAP;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return { boxes, serviceAreas, workingLaneOffset };
|
|
254
|
-
}
|
|
255
124
|
|
|
256
125
|
export function createPitLaneBounds(pitLane) {
|
|
257
126
|
const points = [
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
function clonePointLike(point) {
|
|
2
|
+
if (!point) return point;
|
|
3
|
+
return { ...point };
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function clonePointArray(points) {
|
|
7
|
+
return Array.isArray(points) ? points.map(clonePointLike) : points;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function clonePitLaneModel(pitLane) {
|
|
11
|
+
if (!pitLane) return pitLane;
|
|
12
|
+
return {
|
|
13
|
+
...pitLane,
|
|
14
|
+
entry: pitLane.entry ? {
|
|
15
|
+
...pitLane.entry,
|
|
16
|
+
trackPoint: clonePointLike(pitLane.entry.trackPoint),
|
|
17
|
+
edgePoint: clonePointLike(pitLane.entry.edgePoint),
|
|
18
|
+
trackConnectPoint: clonePointLike(pitLane.entry.trackConnectPoint),
|
|
19
|
+
lanePoint: clonePointLike(pitLane.entry.lanePoint),
|
|
20
|
+
roadCenterline: clonePointArray(pitLane.entry.roadCenterline),
|
|
21
|
+
connector: clonePointArray(pitLane.entry.connector),
|
|
22
|
+
} : pitLane.entry,
|
|
23
|
+
exit: pitLane.exit ? {
|
|
24
|
+
...pitLane.exit,
|
|
25
|
+
trackPoint: clonePointLike(pitLane.exit.trackPoint),
|
|
26
|
+
edgePoint: clonePointLike(pitLane.exit.edgePoint),
|
|
27
|
+
trackConnectPoint: clonePointLike(pitLane.exit.trackConnectPoint),
|
|
28
|
+
lanePoint: clonePointLike(pitLane.exit.lanePoint),
|
|
29
|
+
roadCenterline: clonePointArray(pitLane.exit.roadCenterline),
|
|
30
|
+
connector: clonePointArray(pitLane.exit.connector),
|
|
31
|
+
} : pitLane.exit,
|
|
32
|
+
mainLane: pitLane.mainLane ? {
|
|
33
|
+
...pitLane.mainLane,
|
|
34
|
+
start: clonePointLike(pitLane.mainLane.start),
|
|
35
|
+
end: clonePointLike(pitLane.mainLane.end),
|
|
36
|
+
points: clonePointArray(pitLane.mainLane.points),
|
|
37
|
+
} : pitLane.mainLane,
|
|
38
|
+
workingLane: pitLane.workingLane ? {
|
|
39
|
+
...pitLane.workingLane,
|
|
40
|
+
start: clonePointLike(pitLane.workingLane.start),
|
|
41
|
+
end: clonePointLike(pitLane.workingLane.end),
|
|
42
|
+
points: clonePointArray(pitLane.workingLane.points),
|
|
43
|
+
} : pitLane.workingLane,
|
|
44
|
+
fastLane: pitLane.fastLane ? { ...pitLane.fastLane } : pitLane.fastLane,
|
|
45
|
+
serviceNormal: clonePointLike(pitLane.serviceNormal),
|
|
46
|
+
boxes: Array.isArray(pitLane.boxes)
|
|
47
|
+
? pitLane.boxes.map((box) => ({
|
|
48
|
+
...box,
|
|
49
|
+
laneTarget: clonePointLike(box.laneTarget),
|
|
50
|
+
center: clonePointLike(box.center),
|
|
51
|
+
corners: clonePointArray(box.corners),
|
|
52
|
+
}))
|
|
53
|
+
: pitLane.boxes,
|
|
54
|
+
serviceAreas: Array.isArray(pitLane.serviceAreas)
|
|
55
|
+
? pitLane.serviceAreas.map((area) => ({
|
|
56
|
+
...area,
|
|
57
|
+
laneTarget: clonePointLike(area.laneTarget),
|
|
58
|
+
center: clonePointLike(area.center),
|
|
59
|
+
queuePoint: clonePointLike(area.queuePoint),
|
|
60
|
+
corners: clonePointArray(area.corners),
|
|
61
|
+
queueCorners: clonePointArray(area.queueCorners),
|
|
62
|
+
garageBoxIds: [...(area.garageBoxIds ?? [])],
|
|
63
|
+
pitCrew: area.pitCrew ? { ...area.pitCrew } : area.pitCrew,
|
|
64
|
+
}))
|
|
65
|
+
: pitLane.serviceAreas,
|
|
66
|
+
teams: Array.isArray(pitLane.teams)
|
|
67
|
+
? pitLane.teams.map((team) => ({ ...team, boxIds: [...(team.boxIds ?? [])], pitCrew: team.pitCrew ? { ...team.pitCrew } : team.pitCrew }))
|
|
68
|
+
: pitLane.teams,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { clamp, wrapDistance } from '../simMath.js';
|
|
2
|
-
import { PIT_LANE_WIDTH } from './trackConstants.js';
|
|
3
2
|
import { nearestPointOnPolyline, nearestPointOnPolylineInto, pointInsideBounds, pointIsInsidePolygon } from './trackMath.js';
|
|
4
3
|
import { queryPitBoxCandidates, queryPitRoadSegmentCandidatesByRoute } from './trackQueryIndex.js';
|
|
5
4
|
import { ensureQueryScratch } from './trackQueryScratch.js';
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { PIT_BOX_COUNT, PIT_BOX_DEPTH, PIT_BOX_LENGTH, PIT_BOX_PAIR_GAP, PIT_BOX_TO_LANE_GAP, PIT_LANE_WIDTH, PIT_SERVICE_AREA_DEPTH, PIT_SERVICE_AREA_LENGTH, PIT_SERVICE_QUEUE_GAP, PIT_TEAM_COUNT, PIT_TEAM_GAP, PIT_BOXES_PER_TEAM, PIT_WORKING_LANE_GAP, PIT_WORKING_LANE_WIDTH } from './trackConstants.js';
|
|
2
|
+
import { interpolatePitPoint, projectPitPoint } from './trackMath.js';
|
|
3
|
+
|
|
4
|
+
export function getPitBoxRunLength({
|
|
5
|
+
teamCount = PIT_TEAM_COUNT,
|
|
6
|
+
boxesPerTeam = PIT_BOXES_PER_TEAM,
|
|
7
|
+
boxLength = PIT_BOX_LENGTH,
|
|
8
|
+
pairGap = PIT_BOX_PAIR_GAP,
|
|
9
|
+
teamGap = PIT_TEAM_GAP,
|
|
10
|
+
} = {}) {
|
|
11
|
+
const boxCount = teamCount * boxesPerTeam;
|
|
12
|
+
return (
|
|
13
|
+
boxCount * boxLength +
|
|
14
|
+
teamCount * Math.max(0, boxesPerTeam - 1) * pairGap +
|
|
15
|
+
Math.max(0, teamCount - 1) * teamGap
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createPitBoxCorners(center, forward, serviceNormal) {
|
|
20
|
+
return createPitRectangleCorners(center, forward, serviceNormal, PIT_BOX_LENGTH, PIT_BOX_DEPTH);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createPitRectangleCorners(center, forward, serviceNormal, length, depth) {
|
|
24
|
+
const halfLength = length / 2;
|
|
25
|
+
const halfDepth = depth / 2;
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
x: center.x + forward.x * halfLength + serviceNormal.x * halfDepth,
|
|
29
|
+
y: center.y + forward.y * halfLength + serviceNormal.y * halfDepth,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
x: center.x - forward.x * halfLength + serviceNormal.x * halfDepth,
|
|
33
|
+
y: center.y - forward.y * halfLength + serviceNormal.y * halfDepth,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
x: center.x - forward.x * halfLength - serviceNormal.x * halfDepth,
|
|
37
|
+
y: center.y - forward.y * halfLength - serviceNormal.y * halfDepth,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
x: center.x + forward.x * halfLength - serviceNormal.x * halfDepth,
|
|
41
|
+
y: center.y + forward.y * halfLength - serviceNormal.y * halfDepth,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createPitBoxes({ laneStart, laneForward, laneLength, serviceNormal }) {
|
|
47
|
+
const runLength = getPitBoxRunLength();
|
|
48
|
+
let cursor = Math.max(PIT_SERVICE_QUEUE_GAP + PIT_BOX_LENGTH / 2, (laneLength - runLength) / 2);
|
|
49
|
+
const workingLaneOffset = PIT_LANE_WIDTH / 2 + PIT_WORKING_LANE_GAP + PIT_WORKING_LANE_WIDTH / 2;
|
|
50
|
+
const boxLateral = workingLaneOffset + PIT_WORKING_LANE_WIDTH / 2 + PIT_BOX_TO_LANE_GAP + PIT_BOX_DEPTH / 2;
|
|
51
|
+
const boxes = [];
|
|
52
|
+
const serviceAreas = [];
|
|
53
|
+
|
|
54
|
+
for (let index = 0; index < PIT_BOX_COUNT; index += 1) {
|
|
55
|
+
const distanceAlongLane = cursor + PIT_BOX_LENGTH / 2;
|
|
56
|
+
const laneTarget = interpolatePitPoint(laneStart, laneForward, distanceAlongLane);
|
|
57
|
+
const center = {
|
|
58
|
+
x: laneTarget.x + serviceNormal.x * boxLateral,
|
|
59
|
+
y: laneTarget.y + serviceNormal.y * boxLateral,
|
|
60
|
+
};
|
|
61
|
+
const teamIndex = Math.floor(index / PIT_BOXES_PER_TEAM);
|
|
62
|
+
const teamBoxIndex = index % PIT_BOXES_PER_TEAM;
|
|
63
|
+
|
|
64
|
+
boxes.push({
|
|
65
|
+
id: `team-${teamIndex + 1}-box-${teamBoxIndex + 1}`,
|
|
66
|
+
index,
|
|
67
|
+
teamIndex,
|
|
68
|
+
teamBoxIndex,
|
|
69
|
+
distanceAlongLane,
|
|
70
|
+
laneTarget,
|
|
71
|
+
center,
|
|
72
|
+
length: PIT_BOX_LENGTH,
|
|
73
|
+
depth: PIT_BOX_DEPTH,
|
|
74
|
+
corners: createPitBoxCorners(center, laneForward, serviceNormal),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (teamBoxIndex === PIT_BOXES_PER_TEAM - 1) {
|
|
78
|
+
const firstTeamBox = boxes[index - (PIT_BOXES_PER_TEAM - 1)];
|
|
79
|
+
const serviceDistance = (firstTeamBox.distanceAlongLane + distanceAlongLane) / 2;
|
|
80
|
+
const queueDistance = Math.max(PIT_SERVICE_QUEUE_GAP / 2, serviceDistance - PIT_SERVICE_QUEUE_GAP);
|
|
81
|
+
const serviceCenter = projectPitPoint(
|
|
82
|
+
laneStart,
|
|
83
|
+
laneForward,
|
|
84
|
+
serviceNormal,
|
|
85
|
+
serviceDistance,
|
|
86
|
+
workingLaneOffset,
|
|
87
|
+
);
|
|
88
|
+
const queuePoint = projectPitPoint(
|
|
89
|
+
laneStart,
|
|
90
|
+
laneForward,
|
|
91
|
+
serviceNormal,
|
|
92
|
+
queueDistance,
|
|
93
|
+
workingLaneOffset,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
serviceAreas.push({
|
|
97
|
+
id: `team-${teamIndex + 1}-service`,
|
|
98
|
+
index: teamIndex,
|
|
99
|
+
teamIndex,
|
|
100
|
+
distanceAlongLane: serviceDistance,
|
|
101
|
+
queueDistanceAlongLane: queueDistance,
|
|
102
|
+
laneTarget: serviceCenter,
|
|
103
|
+
center: serviceCenter,
|
|
104
|
+
queuePoint,
|
|
105
|
+
length: PIT_SERVICE_AREA_LENGTH,
|
|
106
|
+
depth: PIT_SERVICE_AREA_DEPTH,
|
|
107
|
+
corners: createPitRectangleCorners(serviceCenter, laneForward, serviceNormal, PIT_SERVICE_AREA_LENGTH, PIT_SERVICE_AREA_DEPTH),
|
|
108
|
+
queueCorners: createPitRectangleCorners(queuePoint, laneForward, serviceNormal, PIT_SERVICE_AREA_LENGTH * 0.72, PIT_SERVICE_AREA_DEPTH),
|
|
109
|
+
garageBoxIds: boxes
|
|
110
|
+
.slice(index - (PIT_BOXES_PER_TEAM - 1), index + 1)
|
|
111
|
+
.map((box) => box.id),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
cursor += PIT_BOX_LENGTH;
|
|
116
|
+
if (teamBoxIndex === 0) cursor += PIT_BOX_PAIR_GAP;
|
|
117
|
+
else if (teamIndex < PIT_TEAM_COUNT - 1) cursor += PIT_TEAM_GAP;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return { boxes, serviceAreas, workingLaneOffset };
|
|
121
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { TRACK } from './trackConstants.js';
|
|
2
|
+
import { buildTrackModel } from './trackBuilder.js';
|
|
3
|
+
import { generateCenterlineControls, generateFallbackCenterlineControls, generateSafeFallbackCenterlineControls, normalizeSeed } from './proceduralCenterline.js';
|
|
4
|
+
import { isValidProceduralTrackModel } from './trackValidation.js';
|
|
5
|
+
import { resolveProceduralTrackOptions } from './trackGenerationOptions.js';
|
|
6
|
+
import { cacheProceduralTrackDefinition, getCachedProceduralTrack } from './trackModelCache.js';
|
|
7
|
+
|
|
8
|
+
export function createProceduralTrack(seed = Date.now(), options = {}) {
|
|
9
|
+
const normalizedSeed = normalizeSeed(seed);
|
|
10
|
+
const generationOptions = resolveProceduralTrackOptions(options);
|
|
11
|
+
const cacheKey = `${normalizedSeed}:${generationOptions.cacheKey}`;
|
|
12
|
+
const cached = getCachedProceduralTrack(cacheKey);
|
|
13
|
+
if (cached) return cached;
|
|
14
|
+
|
|
15
|
+
for (let attempt = 0; attempt < generationOptions.attempts.primary; attempt += 1) {
|
|
16
|
+
const candidateSeed = (normalizedSeed + Math.imul(attempt, 2654435761)) >>> 0;
|
|
17
|
+
const candidate = {
|
|
18
|
+
...TRACK,
|
|
19
|
+
name: `Generated GP ${candidateSeed.toString(36).toUpperCase().padStart(6, '0').slice(-6)}`,
|
|
20
|
+
seed: candidateSeed,
|
|
21
|
+
curveInterpolation: 'centripetal',
|
|
22
|
+
centerlineControls: generateCenterlineControls(candidateSeed, generationOptions.shape),
|
|
23
|
+
drsZones: null,
|
|
24
|
+
generationOptions,
|
|
25
|
+
...(generationOptions.pitLane.enabled === false ? { pitLane: { enabled: false } } : {}),
|
|
26
|
+
};
|
|
27
|
+
const model = buildTrackModel(candidate);
|
|
28
|
+
if (isValidProceduralTrackModel(model, generationOptions)) {
|
|
29
|
+
const trackDefinition = {
|
|
30
|
+
...candidate,
|
|
31
|
+
drsZones: model.drsZones.map(({ id, startRatio, endRatio }) => ({ id, startRatio, endRatio })),
|
|
32
|
+
};
|
|
33
|
+
return cacheProceduralTrackDefinition(cacheKey, trackDefinition, model);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let fallback = null;
|
|
38
|
+
let fallbackModel = null;
|
|
39
|
+
for (let attempt = 0; attempt < generationOptions.attempts.fallback; attempt += 1) {
|
|
40
|
+
const candidateSeed = (normalizedSeed ^ Math.imul(attempt + 1, 2246822519)) >>> 0;
|
|
41
|
+
const candidate = {
|
|
42
|
+
...TRACK,
|
|
43
|
+
name: `Generated GP ${normalizedSeed.toString(36).toUpperCase().padStart(6, '0').slice(-6)}`,
|
|
44
|
+
seed: candidateSeed,
|
|
45
|
+
curveInterpolation: 'centripetal',
|
|
46
|
+
centerlineControls: generateFallbackCenterlineControls(candidateSeed, generationOptions.shape),
|
|
47
|
+
drsZones: null,
|
|
48
|
+
generationOptions,
|
|
49
|
+
...(generationOptions.pitLane.enabled === false ? { pitLane: { enabled: false } } : {}),
|
|
50
|
+
};
|
|
51
|
+
const model = buildTrackModel(candidate);
|
|
52
|
+
if (isValidProceduralTrackModel(model, generationOptions)) {
|
|
53
|
+
fallback = candidate;
|
|
54
|
+
fallbackModel = model;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!fallback || !fallbackModel) {
|
|
60
|
+
fallback = {
|
|
61
|
+
...TRACK,
|
|
62
|
+
name: `Generated GP ${normalizedSeed.toString(36).toUpperCase().padStart(6, '0').slice(-6)}`,
|
|
63
|
+
seed: normalizedSeed,
|
|
64
|
+
curveInterpolation: 'centripetal',
|
|
65
|
+
centerlineControls: generateSafeFallbackCenterlineControls(normalizedSeed, generationOptions.shape),
|
|
66
|
+
drsZones: null,
|
|
67
|
+
generationOptions,
|
|
68
|
+
...(generationOptions.pitLane.enabled === false ? { pitLane: { enabled: false } } : {}),
|
|
69
|
+
};
|
|
70
|
+
fallbackModel = buildTrackModel(fallback);
|
|
71
|
+
}
|
|
72
|
+
const fallbackDefinition = {
|
|
73
|
+
...fallback,
|
|
74
|
+
drsZones: fallbackModel.drsZones.map(({ id, startRatio, endRatio }) => ({ id, startRatio, endRatio })),
|
|
75
|
+
};
|
|
76
|
+
return cacheProceduralTrackDefinition(cacheKey, fallbackDefinition, fallbackModel);
|
|
77
|
+
}
|