@inventure71/paddockjs 4.2.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 +34 -0
- package/INSTALL_AND_UPDATE.md +23 -4
- package/README.md +31 -2
- package/docs/advanced_ai_pace.md +131 -0
- package/docs/advanced_physics_rebuild.md +166 -0
- package/docs/architecture.md +109 -30
- package/docs/cleanup_coverage.md +284 -0
- package/docs/component_inventory.md +31 -15
- 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/grid_walk.md +80 -0
- package/docs/index.md +1 -0
- package/docs/keyboard_driving_fix.md +118 -0
- package/docs/limit_driving_2026-10-14.md +88 -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 +36 -11
- package/docs/testing-reliability-guide.md +5 -0
- package/docs/v11_improvements.md +108 -0
- package/package.json +23 -13
- 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 +13 -259
- 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 +21 -140
- 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 +34 -259
- 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 +5 -11
- 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 +14 -3
- package/src/simulation/driver/edgeRecovery.js +0 -1
- package/src/simulation/driver/racingControls.js +10 -406
- package/src/simulation/driver/racingDriverProfile.js +48 -0
- package/src/simulation/driver/racingLinePlan.js +48 -15
- package/src/simulation/driver/rejoinControls.js +58 -111
- package/src/simulation/driver/safetyCarControls.js +12 -0
- package/src/simulation/driver/trafficScan.js +89 -6
- 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 +1 -1
- package/src/simulation/race/redFlag.js +2 -4
- package/src/simulation/race/safetyCar.js +3 -8
- 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/rulesReview.js +1 -7
- 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 +3 -3
- 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 +1 -25
- 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 +4 -241
- 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 +20 -6
- 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 +0 -56
- package/src/simulation/vehicle/vehicleKinematics.js +10 -0
- package/src/simulation/vehicle/vehiclePhysics.js +35 -194
- package/src/simulation/vehicle/vehicleSnapshots.js +13 -4
- package/src/simulation/vehicle/vehicleState.js +2 -1
- 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/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
|
@@ -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
|
+
}
|
|
@@ -2,7 +2,7 @@ import { clamp, normalizeAngle, wrapDistance } from '../simMath.js';
|
|
|
2
2
|
import { PIT_LANE_WIDTH } from './trackConstants.js';
|
|
3
3
|
import { pointInsideBounds } from './trackMath.js';
|
|
4
4
|
import { nearestPitLaneState, resolveDirectConnectorPitLaneState } from './pitLaneState.js';
|
|
5
|
-
import {
|
|
5
|
+
import { queryNearestTrackProjectionInto } from './trackQueryIndex.js';
|
|
6
6
|
import { recordStat } from './trackQueryStats.js';
|
|
7
7
|
|
|
8
8
|
export function pointAt(track, distanceAlong) {
|
|
@@ -108,30 +108,6 @@ function sampleIndexAtDistanceUnwrapped(track, wrapped) {
|
|
|
108
108
|
return index;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
export function nearestSampleInRange(track, position, startIndex, endIndex) {
|
|
112
|
-
const sampleCount = track.samples.length - 1;
|
|
113
|
-
let best = null;
|
|
114
|
-
let bestDistance = Infinity;
|
|
115
|
-
|
|
116
|
-
for (let index = startIndex; index <= endIndex; index += 1) {
|
|
117
|
-
const wrappedIndex = ((index % sampleCount) + sampleCount) % sampleCount;
|
|
118
|
-
const sample = track.samples[wrappedIndex];
|
|
119
|
-
const dx = position.x - sample.x;
|
|
120
|
-
const dy = position.y - sample.y;
|
|
121
|
-
const squared = dx * dx + dy * dy;
|
|
122
|
-
if (squared < bestDistance) {
|
|
123
|
-
bestDistance = squared;
|
|
124
|
-
best = sample;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return { best, bestDistance };
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function nearestSampleGlobal(track, position) {
|
|
132
|
-
return nearestSampleInRange(track, position, 0, track.samples.length - 2);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
111
|
export function createTrackState(track, position, best) {
|
|
136
112
|
return writeTrackState({}, track, position, best);
|
|
137
113
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CENTERLINE_CONTROLS, TRACK } from './trackConstants.js';
|
|
2
|
+
import { distance } from './trackMath.js';
|
|
3
|
+
import { rawCenterPoint } from './centerlineSpline.js';
|
|
4
|
+
import { recalculateSampleGeometry } from './sampleGeometry.js';
|
|
5
|
+
import { rotateSamplesToStandingStart, straightenStandingStartSamples } from './startStraight.js';
|
|
6
|
+
import { prepareSampleIndexLut } from './spatialQueries.js';
|
|
7
|
+
import { createTrackSectors } from './trackSectors.js';
|
|
8
|
+
import { deriveDrsZones, normalizeDrsZone } from './drsZones.js';
|
|
9
|
+
import { createPitLaneModel } from './pitLaneLayout.js';
|
|
10
|
+
import { attachTrackQueryIndex, createTrackQueryIndex } from './trackQueryConstruction.js';
|
|
11
|
+
import { attachTrackSnapshotJsonSerializer } from './trackSnapshotJson.js';
|
|
12
|
+
import { cacheTrackModel, getCachedTrackModel } from './trackModelCache.js';
|
|
13
|
+
|
|
14
|
+
export function buildTrackModel(track = TRACK) {
|
|
15
|
+
const cached = getCachedTrackModel(track);
|
|
16
|
+
if (cached) return cached;
|
|
17
|
+
|
|
18
|
+
const controls = track.centerlineControls ?? CENTERLINE_CONTROLS;
|
|
19
|
+
const base = [];
|
|
20
|
+
for (let index = 0; index <= track.sampleCount; index += 1) {
|
|
21
|
+
base.push(rawCenterPoint(index / track.sampleCount, controls, track.curveInterpolation));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let totalLength = 0;
|
|
25
|
+
const samples = base.map((point, index) => {
|
|
26
|
+
if (index > 0) totalLength += distance(base[index - 1], point);
|
|
27
|
+
return { ...point, distance: totalLength, heading: 0, normalX: 0, normalY: 0, curvature: 0 };
|
|
28
|
+
});
|
|
29
|
+
recalculateSampleGeometry(samples);
|
|
30
|
+
|
|
31
|
+
const startStraightOptions = track.generationOptions?.startStraight;
|
|
32
|
+
const rotatedSamples = rotateSamplesToStandingStart(samples, totalLength, startStraightOptions);
|
|
33
|
+
const straightenedTrack = straightenStandingStartSamples(rotatedSamples, totalLength, startStraightOptions);
|
|
34
|
+
const normalizedSamples = straightenedTrack.samples;
|
|
35
|
+
totalLength = straightenedTrack.totalLength;
|
|
36
|
+
|
|
37
|
+
const model = {
|
|
38
|
+
...track,
|
|
39
|
+
centerlineControls: controls,
|
|
40
|
+
length: totalLength,
|
|
41
|
+
samples: normalizedSamples,
|
|
42
|
+
sectors: createTrackSectors(totalLength),
|
|
43
|
+
drsZones: (track.drsZones ?? deriveDrsZones(normalizedSamples, totalLength))
|
|
44
|
+
.map((zone) => normalizeDrsZone(zone, totalLength)),
|
|
45
|
+
};
|
|
46
|
+
model.pitLane = track.pitLane?.enabled === false || track.generationOptions?.pitLane?.enabled === false
|
|
47
|
+
? null
|
|
48
|
+
: createPitLaneModel(model);
|
|
49
|
+
attachTrackQueryIndex(model, createTrackQueryIndex(model));
|
|
50
|
+
prepareSampleIndexLut(model);
|
|
51
|
+
attachTrackSnapshotJsonSerializer(model);
|
|
52
|
+
cacheTrackModel(track, model);
|
|
53
|
+
return model;
|
|
54
|
+
}
|
|
@@ -34,7 +34,6 @@ export const START_STRAIGHT_GRID_LENGTH = metersToSimUnits(496);
|
|
|
34
34
|
export const START_STRAIGHT_EXIT_LENGTH = metersToSimUnits(500);
|
|
35
35
|
export const START_STRAIGHT_LOCK_EXTRA = metersToSimUnits(43);
|
|
36
36
|
export const START_STRAIGHT_BLEND_LENGTH = metersToSimUnits(320);
|
|
37
|
-
export const NEAREST_HINT_WINDOW_SAMPLES = 240;
|
|
38
37
|
export const PIT_LANE_WIDTH = metersToSimUnits(12);
|
|
39
38
|
export const PIT_LANE_EDGE_GAP = metersToSimUnits(16);
|
|
40
39
|
export const PIT_ACCESS_MIN_LENGTH = metersToSimUnits(70);
|
|
@@ -66,27 +65,6 @@ export const PIT_LANE_FINISH_RATIO = 0.64;
|
|
|
66
65
|
export const PIT_WORLD_PADDING = metersToSimUnits(24);
|
|
67
66
|
export const PIT_TRACK_CLEARANCE_MARGIN = metersToSimUnits(5);
|
|
68
67
|
export const PIT_LANE_OFFSET_SEARCH_STEP = metersToSimUnits(12);
|
|
69
|
-
export const PROCEDURAL_TRACK_TEMPLATES = [
|
|
70
|
-
[
|
|
71
|
-
[0.08, 0.55], [0.10, 0.80], [0.22, 0.89], [0.42, 0.84], [0.52, 0.93],
|
|
72
|
-
[0.60, 0.75], [0.74, 0.88], [0.91, 0.76], [0.94, 0.54], [0.82, 0.46],
|
|
73
|
-
[0.94, 0.28], [0.78, 0.18], [0.62, 0.31], [0.54, 0.13], [0.43, 0.30],
|
|
74
|
-
[0.33, 0.17], [0.20, 0.24], [0.12, 0.38], [0.22, 0.48], [0.13, 0.50],
|
|
75
|
-
],
|
|
76
|
-
[
|
|
77
|
-
[0.07, 0.46], [0.14, 0.72], [0.25, 0.83], [0.39, 0.73], [0.47, 0.88],
|
|
78
|
-
[0.56, 0.70], [0.67, 0.82], [0.88, 0.84], [0.95, 0.63], [0.83, 0.56],
|
|
79
|
-
[0.92, 0.43], [0.79, 0.35], [0.88, 0.20], [0.68, 0.15], [0.58, 0.29],
|
|
80
|
-
[0.47, 0.18], [0.34, 0.30], [0.21, 0.19], [0.10, 0.28], [0.17, 0.39],
|
|
81
|
-
],
|
|
82
|
-
[
|
|
83
|
-
[0.06, 0.61], [0.13, 0.86], [0.31, 0.91], [0.43, 0.79], [0.57, 0.87],
|
|
84
|
-
[0.71, 0.70], [0.92, 0.72], [0.95, 0.50], [0.84, 0.43], [0.91, 0.32],
|
|
85
|
-
[0.74, 0.24], [0.69, 0.11], [0.54, 0.18], [0.45, 0.08], [0.35, 0.22],
|
|
86
|
-
[0.23, 0.17], [0.11, 0.31], [0.24, 0.43], [0.15, 0.52], [0.28, 0.60],
|
|
87
|
-
],
|
|
88
|
-
];
|
|
89
|
-
|
|
90
68
|
export const CENTERLINE_CONTROLS = [
|
|
91
69
|
{ x: WORLD.width * 0.05, y: WORLD.height * 0.56 },
|
|
92
70
|
{ x: WORLD.width * 0.10, y: WORLD.height * 0.81 },
|
|
@@ -161,35 +161,6 @@ export function pointInsideBounds(point, bounds) {
|
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
export function projectPointToSegment(position, start, end) {
|
|
165
|
-
const dx = end.x - start.x;
|
|
166
|
-
const dy = end.y - start.y;
|
|
167
|
-
const lengthSquared = dx * dx + dy * dy;
|
|
168
|
-
const amount = lengthSquared > 0
|
|
169
|
-
? clamp(((position.x - start.x) * dx + (position.y - start.y) * dy) / lengthSquared, 0, 1)
|
|
170
|
-
: 0;
|
|
171
|
-
const projected = {
|
|
172
|
-
x: start.x + dx * amount,
|
|
173
|
-
y: start.y + dy * amount,
|
|
174
|
-
};
|
|
175
|
-
const length = Math.sqrt(lengthSquared);
|
|
176
|
-
const heading = Math.atan2(dy, dx);
|
|
177
|
-
const normalX = length > 0 ? -dy / length : 0;
|
|
178
|
-
const normalY = length > 0 ? dx / length : 1;
|
|
179
|
-
const signedOffset = (position.x - projected.x) * normalX + (position.y - projected.y) * normalY;
|
|
180
|
-
|
|
181
|
-
return {
|
|
182
|
-
point: projected,
|
|
183
|
-
amount,
|
|
184
|
-
length,
|
|
185
|
-
heading,
|
|
186
|
-
normalX,
|
|
187
|
-
normalY,
|
|
188
|
-
signedOffset,
|
|
189
|
-
crossTrackError: Math.abs(signedOffset),
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
164
|
export function nearestPointOnPolyline(points, position, segmentIndices = null) {
|
|
194
165
|
return nearestPointOnPolylineInto({}, points, position, { segmentIndices });
|
|
195
166
|
}
|
|
@@ -306,3 +277,7 @@ export function pointIsInsidePolygon(point, polygon) {
|
|
|
306
277
|
|
|
307
278
|
return inside;
|
|
308
279
|
}
|
|
280
|
+
|
|
281
|
+
export function finitePoint(point) {
|
|
282
|
+
return Number.isFinite(point?.x) && Number.isFinite(point?.y);
|
|
283
|
+
}
|