@adatechnology/game-vehicles-proving 0.2.4 → 0.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/README.md +4 -0
- package/dist/index.d.ts +59 -2
- package/dist/index.global.js +456 -30
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +164 -9
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -11,3 +11,7 @@ A `ProvingRun` owns no accumulator. The physics step is `fixedStep` (default 1/1
|
|
|
11
11
|
- **`time_scale`** (the proving area's control, 1 to 20) is not a clock: it is the number of ticks' worth of steps run in each tick (`stepFixed(STEPS_PER_TICK * timeScale)`), a fast-forward of the test alone. The scheduler's `timeScale` stays the room's slow motion, and the scheduler's cap of ticks per frame would cut a 20x run, so the fast-forward cannot live there.
|
|
12
12
|
|
|
13
13
|
Trajectories at 60 Hz are the same as with the old private accumulator (test `the scheduler tick and the old private accumulator...`).
|
|
14
|
+
|
|
15
|
+
## The proving ground on the physics engine (spec 008 T6.2b)
|
|
16
|
+
|
|
17
|
+
`startPhysicsRun` and `runTestOnPhysics` run the same procedures on the Jolt vehicle (`vehicleDescFromSemi`), model by model, against the same bands as the semi-simulation. State of the fleet on Jolt (T6.2d, open): 17 land models are outside the bands (acceleration of five cars and SUVs, heavy and military models too fast, the bicycle, the tank's turn, the tractor and four motorcycles braking on a wet track); the reasons and the owner's decisions are in `specs/008-motor-fisico-jolt/evidence.md`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DesignStats, BodyDimensions, SemiSimSpec, SemiState, SemiInput, SurfaceRegistry, SemiDriver } from '@adatechnology/game-vehicles-driving';
|
|
2
|
+
import { PhysicsWorld } from '@adatechnology/game-physics';
|
|
2
3
|
|
|
3
4
|
/** Where a vehicle moves: on the ground, on water or in the air. Each domain has its own rooms. */
|
|
4
5
|
type ProvingDomain = 'land' | 'water' | 'air';
|
|
@@ -123,6 +124,17 @@ interface RunOptions {
|
|
|
123
124
|
/** Fixed step of the simulation (default 1/120 s): the seconds one `stepFixed` step integrates. */
|
|
124
125
|
fixedStep?: number;
|
|
125
126
|
}
|
|
127
|
+
/** What a measured test's result is made from: shared by the semi-simulation run and the physics-engine run. */
|
|
128
|
+
interface ResultInput {
|
|
129
|
+
readonly test: ProvingTest;
|
|
130
|
+
readonly subject: ProvingSubject;
|
|
131
|
+
readonly memo: ProvingMemo;
|
|
132
|
+
readonly trace: ReadonlyArray<[number, number]>;
|
|
133
|
+
readonly done: boolean;
|
|
134
|
+
readonly state: SemiState;
|
|
135
|
+
readonly time: number;
|
|
136
|
+
}
|
|
137
|
+
declare function resultOf({ test, subject, memo, trace, done, state, time }: ResultInput): ProvingResult;
|
|
126
138
|
declare function startRun(test: ProvingTest, subject: ProvingSubject, options?: RunOptions): ProvingRun;
|
|
127
139
|
/** Runs a measured test to its end and returns the result. */
|
|
128
140
|
declare function runTest(test: ProvingTest, subject: ProvingSubject, options?: RunOptions): ProvingResult;
|
|
@@ -132,8 +144,10 @@ declare function runTest(test: ProvingTest, subject: ProvingSubject, options?: R
|
|
|
132
144
|
* be replaced per class through `createProvingTests({ ranges })`.
|
|
133
145
|
*/
|
|
134
146
|
interface RangeTable {
|
|
135
|
-
/** 0-100 km/h seconds by the card's acceleration rating (0-10). */
|
|
147
|
+
/** 0-100 km/h seconds by the card's acceleration rating (0-10), for a class that has no sourced table in `accelerationByClass` (no source for these numbers). */
|
|
136
148
|
accelerationSeconds: ReadonlyArray<readonly [number, number]>;
|
|
149
|
+
/** 0-100 km/h seconds by the card's acceleration rating, per class (`cars`, `suvs`, `motorcycles`): the rating places the model between the class's slowest and fastest real figure. */
|
|
150
|
+
accelerationByClass: Readonly<Record<string, ReadonlyArray<readonly [number, number]>>>;
|
|
137
151
|
/** Accepted spread around the expected 0-100 time (0.35 = ±35 %). */
|
|
138
152
|
accelerationSpread: number;
|
|
139
153
|
/** Accepted spread around the card's top speed. */
|
|
@@ -147,6 +161,15 @@ interface RangeTable {
|
|
|
147
161
|
/** Metres a four-wheel-drive vehicle has to cover in the mud test. */
|
|
148
162
|
mudFourWheelDrive: number;
|
|
149
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Real 0-100 km/h times that anchor each class: rating 1 at the slowest, rating 10 at the fastest, in between linearly.
|
|
166
|
+
* cars: slowest 15.5 s, Renault Kwid 1.0 (Renault's figure, https://www.icarros.com.br/noticias/testes-e-comparativos/como-anda-o-renault-kwid-intense,-de-r$-39.990-/23022.html; 14.9 s measured by Quatro Rodas);
|
|
167
|
+
* fastest 4.8 s, Ford Mustang GT 5.0 V8 (Ford's figure, https://media.ford.com/content/fordmedia/feu/en/news/2015/04/27/all-new-mustang-sprints-0-100-km-h-in-under-5-seconds--2-200-ord.html). A Corolla 2.0 is 9.9 s (Motor Show measurement).
|
|
168
|
+
* suvs: slowest 12.7 s, Toyota Land Cruiser Prado 2.8 D-4D 177 hp automatic (https://www.auto-data.net/en/toyota-land-cruiser-prado-j150-facelift-2017-5-door-2.8-d-4d-177hp-4wd-automatic-32878, a database, not the maker);
|
|
169
|
+
* fastest 6.7 s, Toyota Land Cruiser 300 (Toyota's figure, via https://www.motor1.com/news/515260/2022-toyota-land-cruiser-acceleration-test/).
|
|
170
|
+
* motorcycles: slowest 19.5 s, Honda PCX 160 (measured, https://www.autofun.co.id/berita-motor/mana-paling-gesit-akselerasinya-honda-pcx-160-2022-atau-yamaha-nmax-155-2022-48474); fastest 4.35 s, Kawasaki Ninja 400 (https://motostatz.com/?p=369).
|
|
171
|
+
* pickups, vans, heavy, agricultural, military: no verified pair of figures (a Hilux 2.8 is 10.0 s, Toyota Europe, one point only), so they keep `accelerationSeconds`.
|
|
172
|
+
*/
|
|
150
173
|
declare const defaultRangeTable: RangeTable;
|
|
151
174
|
/** Expected 0-100 (or 0-`target`) seconds for a subject. Below 100 km/h the time scales linearly with the target speed. */
|
|
152
175
|
declare const expectedAcceleration: (table: RangeTable, subject: ProvingSubject, target: number) => number;
|
|
@@ -237,4 +260,38 @@ interface VehicleCardData {
|
|
|
237
260
|
/** A proving subject from what a catalogue knows of a vehicle. */
|
|
238
261
|
declare function subjectFromCard(id: string, card: VehicleCardData): ProvingSubject;
|
|
239
262
|
|
|
240
|
-
|
|
263
|
+
interface PhysicsRunOptions {
|
|
264
|
+
/** A world made for this run (an empty `PhysicsWorld` of the engine under test, 120 Hz): the run puts the ground and the vehicle in it and disposes it at the end. */
|
|
265
|
+
readonly createWorld: () => PhysicsWorld;
|
|
266
|
+
readonly surfaces?: SurfaceRegistry;
|
|
267
|
+
/** Seconds between two trace samples (default 0.1). */
|
|
268
|
+
readonly sampleEvery?: number;
|
|
269
|
+
/** Fixed step of the simulation (default 1/120 s): the world's own. */
|
|
270
|
+
readonly fixedStep?: number;
|
|
271
|
+
}
|
|
272
|
+
/** A measured test in progress on the physics engine: the same procedures as `ProvingRun`, driven through the vehicle the engine simulates. */
|
|
273
|
+
interface PhysicsProvingRun {
|
|
274
|
+
readonly test: ProvingTest;
|
|
275
|
+
readonly subject: ProvingSubject;
|
|
276
|
+
readonly surface: string;
|
|
277
|
+
readonly time: number;
|
|
278
|
+
readonly done: boolean;
|
|
279
|
+
readonly trace: ReadonlyArray<[number, number]>;
|
|
280
|
+
readonly memo: ProvingMemo;
|
|
281
|
+
readonly input: SemiInput;
|
|
282
|
+
readonly fixedStep: number;
|
|
283
|
+
/**
|
|
284
|
+
* What the procedures read, from the body: x and z are the metres along the run and across it, `u` the speed along the front, `yawRate` positive to the left, `yaw`
|
|
285
|
+
* the heading, `height`, `pitch` and `roll` from the pose. The engine and gearbox have no reading in the contract: `rpm` and `gear` stay 0.
|
|
286
|
+
*/
|
|
287
|
+
readonly state: SemiState;
|
|
288
|
+
stepFixed(steps: number): void;
|
|
289
|
+
result(): ProvingResult;
|
|
290
|
+
/** Lets go of the world; `runTestOnPhysics` calls it. */
|
|
291
|
+
dispose(): void;
|
|
292
|
+
}
|
|
293
|
+
declare function startPhysicsRun(test: ProvingTest, subject: ProvingSubject, options: PhysicsRunOptions): PhysicsProvingRun;
|
|
294
|
+
/** Runs a measured test on the physics engine to its end and returns the result; the world is let go. */
|
|
295
|
+
declare function runTestOnPhysics(test: ProvingTest, subject: ProvingSubject, options: PhysicsRunOptions): ProvingResult;
|
|
296
|
+
|
|
297
|
+
export { type CertifyOptions, DEFAULT_DENSITY, type GateOptions, type PhysicsProvingRun, type PhysicsRunOptions, type ProvingCertificate, type ProvingDomain, type ProvingMemo, type ProvingProcedure, type ProvingRange, type ProvingResult, type ProvingRun, type ProvingSubject, type ProvingTest, type ProvingTestKind, type ProvingTestOptions, type ProvingTestRegistry, type ProvingVerdict, type RangeTable, type ResultInput, type RunOptions, STEPS_PER_TICK, type SignOff, type VehicleCardData, accelerationRange, brakeRange, certify, createProvingTests, defaultProvingTests, defaultRangeTable, dryBrakeRange, expectedAcceleration, gateVehicles, inRange, resultOf, runTest, runTestOnPhysics, startPhysicsRun, startRun, statusOf, subjectFromCard, subjectSpec, topSpeedRange, turnCircleRange, wetBrakeRange, withResult };
|
package/dist/index.global.js
CHANGED
|
@@ -33,7 +33,10 @@ var GameVehiclesProving = (() => {
|
|
|
33
33
|
expectedAcceleration: () => expectedAcceleration,
|
|
34
34
|
gateVehicles: () => gateVehicles,
|
|
35
35
|
inRange: () => inRange,
|
|
36
|
+
resultOf: () => resultOf,
|
|
36
37
|
runTest: () => runTest,
|
|
38
|
+
runTestOnPhysics: () => runTestOnPhysics,
|
|
39
|
+
startPhysicsRun: () => startPhysicsRun,
|
|
37
40
|
startRun: () => startRun,
|
|
38
41
|
statusOf: () => statusOf,
|
|
39
42
|
subjectFromCard: () => subjectFromCard,
|
|
@@ -173,7 +176,8 @@ var GameVehiclesProving = (() => {
|
|
|
173
176
|
PIECE_BOXES: "destruction.piece-boxes",
|
|
174
177
|
STATIC_COLLIDERS: "destruction.static-colliders",
|
|
175
178
|
SHAPES_GENERATE: "shapes.generate",
|
|
176
|
-
WORLD_REGION: "world.region"
|
|
179
|
+
WORLD_REGION: "world.region",
|
|
180
|
+
VEHICLE_HULL_PLAN: "vehicles.hull-plan"
|
|
177
181
|
};
|
|
178
182
|
var WORKER_KIND_DEFAULTS = {
|
|
179
183
|
[WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
|
|
@@ -181,7 +185,8 @@ var GameVehiclesProving = (() => {
|
|
|
181
185
|
[WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
|
|
182
186
|
[WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
|
|
183
187
|
[WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
|
|
184
|
-
[WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" }
|
|
188
|
+
[WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" },
|
|
189
|
+
[WORKER_KIND_ID.VEHICLE_HULL_PLAN]: { lane: "build", priority: 120, late: "keep-waiting" }
|
|
185
190
|
};
|
|
186
191
|
|
|
187
192
|
// ../game-runtime/dist/index.js
|
|
@@ -1096,31 +1101,301 @@ var GameVehiclesProving = (() => {
|
|
|
1096
1101
|
}
|
|
1097
1102
|
return driver;
|
|
1098
1103
|
}
|
|
1104
|
+
var CYCLIST = { watts: 250, cadenceRpm: 80, gears: [1.5, 2.5, 3.5] };
|
|
1105
|
+
var MOTORCYCLE = { engine: { idleRpm: 1300, peakRpm: 7500, redlineRpm: 1e4 }, gears: [2.8, 2, 1.5, 1.2, 1], finalDrive: 3, efficiency: 0.9, step: 1.25, topShare: 0.8, upshift: 0.6, downshift: 0.3 };
|
|
1106
|
+
var TRUCK = { engine: { idleRpm: 600, peakRpm: 1500, redlineRpm: 2500 }, gears: [7, 4.7, 3.2, 2.2, 1.5], finalDrive: 4.5, efficiency: 0.85, step: 1.5, topShare: 0.95, upshift: 0.85, downshift: 0.35 };
|
|
1107
|
+
var TRACTOR = { engine: { idleRpm: 800, peakRpm: 1600, redlineRpm: 2300 }, gears: [7, 4.7, 3.2, 2.2, 1.5], finalDrive: 4.5, efficiency: 0.85, step: 1.5, topShare: 0.95, upshift: 0.85, downshift: 0.35 };
|
|
1108
|
+
var TRACKED = { engine: { idleRpm: 600, peakRpm: 1500, redlineRpm: 2500 }, gears: [7, 4.7, 3.2, 2.2, 1.5], finalDrive: 4.5, efficiency: 0.85, step: 1.5, topShare: 0.95, upshift: 0.85, downshift: 0.35 };
|
|
1109
|
+
var drivetrainOfType = (type) => {
|
|
1110
|
+
if (type === "motorcycle") return MOTORCYCLE;
|
|
1111
|
+
if (type === "truck") return TRUCK;
|
|
1112
|
+
if (type === "tractor") return TRACTOR;
|
|
1113
|
+
if (type === "tracked") return TRACKED;
|
|
1114
|
+
return void 0;
|
|
1115
|
+
};
|
|
1116
|
+
var isTwoWheeler = (type) => type === "motorcycle" || type === "bicycle";
|
|
1117
|
+
var wheelsOfAxles = ({ axles, fourWheelDrive, twoWheeler }) => {
|
|
1118
|
+
const front = axles[0].x;
|
|
1119
|
+
const rear = axles[axles.length - 1].x;
|
|
1120
|
+
const middle = (front + rear) / 2;
|
|
1121
|
+
return axles.flatMap((axle, index) => {
|
|
1122
|
+
const isFront = index === 0;
|
|
1123
|
+
const isRear = index === axles.length - 1;
|
|
1124
|
+
const common = { x: axle.x - middle, ...isFront ? { steer: true } : {}, ...isRear ? { handbrake: true } : {} };
|
|
1125
|
+
const drive = twoWheeler ? isRear : fourWheelDrive || !isFront;
|
|
1126
|
+
const wheel = (z) => ({ ...common, z, ...drive ? { drive: true } : {} });
|
|
1127
|
+
return axle.track > 0 ? [wheel(-axle.track / 2), wheel(axle.track / 2)] : [wheel(0)];
|
|
1128
|
+
});
|
|
1129
|
+
};
|
|
1130
|
+
var trackStandIn = (tracks) => {
|
|
1131
|
+
const side = tracks.gauge / 2;
|
|
1132
|
+
return [
|
|
1133
|
+
{ x: tracks.frontX, z: -side, steer: true, drive: true },
|
|
1134
|
+
{ x: tracks.frontX, z: side, steer: true, drive: true },
|
|
1135
|
+
{ x: tracks.rearX, z: -side, drive: true, handbrake: true },
|
|
1136
|
+
{ x: tracks.rearX, z: side, drive: true, handbrake: true }
|
|
1137
|
+
];
|
|
1138
|
+
};
|
|
1139
|
+
var tracksOfBody = (tracks) => {
|
|
1140
|
+
const middle = (tracks.frontX + tracks.rearX) / 2;
|
|
1141
|
+
return { gauge: tracks.gauge, rearX: tracks.rearX - middle, frontX: tracks.frontX - middle, roadWheels: tracks.roadWheels, roadRadius: tracks.radius };
|
|
1142
|
+
};
|
|
1143
|
+
var RIDER_MASS_KG = 75;
|
|
1144
|
+
var MOTORCYCLE_POWER_FACTOR = 1.3;
|
|
1145
|
+
var MOTORCYCLE_POWER_RATING_1 = 11800 / (132 + RIDER_MASS_KG);
|
|
1146
|
+
var MOTORCYCLE_POWER_RATING_10 = 33400 / (168 + RIDER_MASS_KG);
|
|
1147
|
+
var motorcyclePower = (rating) => MOTORCYCLE_POWER_FACTOR * (MOTORCYCLE_POWER_RATING_1 + (MOTORCYCLE_POWER_RATING_10 - MOTORCYCLE_POWER_RATING_1) * (rating - 1) / 9);
|
|
1148
|
+
var carPower = (rating) => (0.06 + 0.015 * rating) * (defaultSemiSpec.engine.peakRpm * 2 * Math.PI / 60);
|
|
1149
|
+
var peakTorqueOf = (type, rating, mass, peakRpm) => {
|
|
1150
|
+
const power = type === "motorcycle" ? motorcyclePower(rating) : carPower(rating);
|
|
1151
|
+
return mass * power * 60 / (2 * Math.PI * peakRpm);
|
|
1152
|
+
};
|
|
1153
|
+
var cyclistFor = (top, wheelRadius) => {
|
|
1154
|
+
const topGear = top / (2 * Math.PI * wheelRadius) / (CYCLIST.cadenceRpm / 60);
|
|
1155
|
+
return { ...CYCLIST, gears: [topGear / 1.4 ** 2, topGear / 1.4, topGear] };
|
|
1156
|
+
};
|
|
1157
|
+
var axlesOfBody = (body, twoWheeler) => body.axles ?? [{ x: body.wheelbase / 2, track: twoWheeler ? 0 : body.track, radius: defaultSemiSpec.wheelRadius }, { x: -body.wheelbase / 2, track: twoWheeler ? 0 : body.track, radius: defaultSemiSpec.wheelRadius }];
|
|
1158
|
+
var drivenRadius = (axles, driveAll, twoWheeler) => {
|
|
1159
|
+
const driven = twoWheeler ? axles.slice(-1) : driveAll ? axles : axles.slice(1);
|
|
1160
|
+
return driven.reduce((sum, axle) => sum + axle.radius, 0) / driven.length;
|
|
1161
|
+
};
|
|
1099
1162
|
function semiSpecFromStats(stats, body, base = {}) {
|
|
1100
|
-
const
|
|
1101
|
-
const
|
|
1102
|
-
const
|
|
1163
|
+
const type = body.type ?? "car";
|
|
1164
|
+
const mass = body.mass + (type === "motorcycle" ? RIDER_MASS_KG : 0);
|
|
1165
|
+
const twoWheeler = isTwoWheeler(type);
|
|
1166
|
+
const drivetrain = drivetrainOfType(type);
|
|
1167
|
+
const tracks = type === "tracked" && body.tracks ? tracksOfBody(body.tracks) : void 0;
|
|
1168
|
+
const axles = axlesOfBody(body, twoWheeler);
|
|
1103
1169
|
const driveAll = !!body.fourWheelDrive;
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
{
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1170
|
+
const wheelRadius = tracks?.roadRadius ?? drivenRadius(axles, driveAll, twoWheeler);
|
|
1171
|
+
const spec = {
|
|
1172
|
+
...defaultSemiSpec,
|
|
1173
|
+
...drivetrain ? { engine: { ...defaultSemiSpec.engine, ...drivetrain.engine }, gears: drivetrain.gears, finalDrive: drivetrain.finalDrive, efficiency: drivetrain.efficiency, upshiftFraction: drivetrain.upshift, downshiftFraction: drivetrain.downshift } : {},
|
|
1174
|
+
...type === "bicycle" ? { finalDrive: 1, efficiency: 0.95 } : {},
|
|
1175
|
+
wheelRadius,
|
|
1176
|
+
centreHeight: twoWheeler ? 0.6 : Math.max(defaultSemiSpec.centreHeight, wheelRadius + 0.1),
|
|
1177
|
+
...base
|
|
1178
|
+
};
|
|
1179
|
+
const wheels = tracks ? trackStandIn(tracks) : wheelsOfAxles({ axles, fourWheelDrive: driveAll, twoWheeler });
|
|
1180
|
+
const pedal = type === "bicycle" ? cyclistFor(stats.maxSpeedKmh / 3.6, wheelRadius) : void 0;
|
|
1181
|
+
const peakTorque = pedal ? pedal.watts * 60 / (2 * Math.PI * pedal.cadenceRpm) : peakTorqueOf(type, stats.acceleration, mass, spec.engine.peakRpm);
|
|
1182
|
+
const engine = pedal ? { idleRpm: 40, peakRpm: pedal.cadenceRpm, redlineRpm: pedal.cadenceRpm * 1.5, peakTorque } : { ...spec.engine, peakTorque };
|
|
1112
1183
|
const top = stats.maxSpeedKmh / 3.6;
|
|
1113
|
-
const
|
|
1114
|
-
const
|
|
1115
|
-
const
|
|
1116
|
-
const
|
|
1117
|
-
const
|
|
1184
|
+
const topShare = drivetrain?.topShare ?? 0.95;
|
|
1185
|
+
const lastRatio = engine.redlineRpm * topShare * 2 * Math.PI * spec.wheelRadius / (60 * top * spec.finalDrive);
|
|
1186
|
+
const stack = drivetrain?.gears ?? spec.gears;
|
|
1187
|
+
const step = drivetrain?.step ?? 1.25;
|
|
1188
|
+
const gears = pedal ? pedal.gears.map((ratio) => 1 / ratio) : [...stack.slice(0, -1).map((g, i, all) => Math.max(g, lastRatio * step ** (all.length - i))), lastRatio];
|
|
1189
|
+
const torqueAtTop = type === "car" ? peakTorque * 0.76 : torqueAt({ ...spec, engine }, engine.redlineRpm * topShare);
|
|
1190
|
+
const topRatio = pedal ? gears[gears.length - 1] : lastRatio;
|
|
1191
|
+
const thrust = pedal ? pedal.watts * spec.efficiency / top : torqueAtTop * topRatio * spec.finalDrive * spec.efficiency / spec.wheelRadius;
|
|
1192
|
+
const rollingForce = spec.rolling * mass * 9.81;
|
|
1118
1193
|
const drag = Math.max(0.01, (thrust - rollingForce) / (top * top));
|
|
1119
1194
|
const carRatio = defaultSemiSpec.brakeForce / (defaultSemiSpec.mass * 9.81);
|
|
1120
|
-
const heavyShare = Math.max(0, Math.min(1, (
|
|
1121
|
-
const brakeForce = base.brakeForce ??
|
|
1122
|
-
return {
|
|
1195
|
+
const heavyShare = Math.max(0, Math.min(1, (mass - 2e3) / 8e3));
|
|
1196
|
+
const brakeForce = base.brakeForce ?? mass * 9.81 * (carRatio + (0.6 - carRatio) * heavyShare);
|
|
1197
|
+
return {
|
|
1198
|
+
...spec,
|
|
1199
|
+
mass,
|
|
1200
|
+
wheels,
|
|
1201
|
+
fourWheelDrive: driveAll,
|
|
1202
|
+
engine,
|
|
1203
|
+
gears,
|
|
1204
|
+
drag,
|
|
1205
|
+
brakeForce,
|
|
1206
|
+
tyre: { ...spec.tyre, friction: 0.8 + 0.03 * stats.handling },
|
|
1207
|
+
...pedal ? { pedal } : {},
|
|
1208
|
+
...tracks ? { tracks } : {}
|
|
1209
|
+
};
|
|
1123
1210
|
}
|
|
1211
|
+
var GRAVITY = 9.81;
|
|
1212
|
+
var CURVE_CUT_GAP_RPM = 1;
|
|
1213
|
+
var FRONT_BRAKE_SHARE = 0.6;
|
|
1214
|
+
var HANDBRAKE_SHARE = 0.5;
|
|
1215
|
+
var SUSPENSION_MIN_SHARE = 0.4;
|
|
1216
|
+
var MAX_SAG = 0.5;
|
|
1217
|
+
var LEAN_SPRING_PER_INERTIA = 400;
|
|
1218
|
+
var LEAN_DAMPING_PER_INERTIA = 40;
|
|
1219
|
+
var LEAN_LIMIT = 0.7;
|
|
1220
|
+
var TRACK_LATERAL_FRICTION = 0.5;
|
|
1221
|
+
var WHEEL_WIDTH = 0.2;
|
|
1222
|
+
var CLUTCH_STRENGTH = 10;
|
|
1223
|
+
var CLUTCH_SLIP = 0.03;
|
|
1224
|
+
var BICYCLE_WHEEL_INERTIA = 0.1;
|
|
1225
|
+
var WHEEL_INERTIA_PER_MASS = 8e-4;
|
|
1226
|
+
var REFERENCE_RADIUS = 0.32;
|
|
1227
|
+
var MIN_WHEEL_INERTIA = 0.02;
|
|
1228
|
+
var WHEEL_DAMPING = 0.02;
|
|
1229
|
+
var ENGINE_DAMPING = 5e-3;
|
|
1230
|
+
var ENGINE_INERTIA_PER_TORQUE = 1e-3;
|
|
1231
|
+
var ENGINE_FLOOR = 0.55;
|
|
1232
|
+
var SUSPENSION_FLOOR = 0.5;
|
|
1233
|
+
var CAR_TRANSMISSION = { switchTime: 0.1, clutchReleaseTime: 0.1, switchLatency: 0.1 };
|
|
1234
|
+
var MOTORCYCLE_TRANSMISSION = { switchTime: 0.05, clutchReleaseTime: 0.07, switchLatency: 0.05 };
|
|
1235
|
+
var clutchFor = (peakTorque, maxRpm) => Math.max(CLUTCH_STRENGTH, peakTorque / (CLUTCH_SLIP * (maxRpm * 2 * Math.PI / 60)));
|
|
1236
|
+
var clamp5 = (x, low, high) => Math.max(low, Math.min(high, x));
|
|
1237
|
+
var torqueCurve = (spec) => {
|
|
1238
|
+
const { idleRpm, peakRpm, redlineRpm, peakTorque } = spec.engine;
|
|
1239
|
+
const at = (rpm) => torqueAt(spec, rpm) / peakTorque;
|
|
1240
|
+
return [[0, at(0)], [idleRpm / redlineRpm, at(idleRpm)], [peakRpm / redlineRpm, at(peakRpm)], [(redlineRpm - CURVE_CUT_GAP_RPM) / redlineRpm, at(redlineRpm - CURVE_CUT_GAP_RPM)], [1, 0]];
|
|
1241
|
+
};
|
|
1242
|
+
var lateralCurve = (friction, corneringStiffness) => [[0, 0], [friction / corneringStiffness * 180 / Math.PI, friction], [90, 0.75 * friction]];
|
|
1243
|
+
var longitudinalCurve = (friction) => [[0, 0], [0.06, friction], [1, 0.8 * friction]];
|
|
1244
|
+
var isFlat = (condition, index) => (condition.tyres?.[index] ?? 1) < FLAT_BELOW || condition.rims?.[index] === true;
|
|
1245
|
+
var wheelOf = (wheel, index, context) => {
|
|
1246
|
+
const { spec, condition, options } = context;
|
|
1247
|
+
const cornerMass = spec.mass / spec.wheels.length;
|
|
1248
|
+
const wear = SUSPENSION_FLOOR + (1 - SUSPENSION_FLOOR) * clamp5(condition.suspension ?? 1, 0, 1);
|
|
1249
|
+
const free = spec.suspension.restLength;
|
|
1250
|
+
const stiffening = Math.max(1, cornerMass * GRAVITY / (MAX_SAG * free * spec.suspension.spring * wear));
|
|
1251
|
+
const spring = spec.suspension.spring * wear * stiffening;
|
|
1252
|
+
const damper = spec.suspension.damper * wear * stiffening;
|
|
1253
|
+
const sag = cornerMass * GRAVITY / spring;
|
|
1254
|
+
const flat = isFlat(condition, index);
|
|
1255
|
+
const rimRadius = spec.rimRadius ?? RIM_RADIUS_SHARE * spec.wheelRadius;
|
|
1256
|
+
const friction = flat ? RIM_FRICTION : spec.tyre.friction;
|
|
1257
|
+
const front = wheel.x >= context.frontFrom;
|
|
1258
|
+
const brakeShare = front ? FRONT_BRAKE_SHARE / context.frontCount : (1 - FRONT_BRAKE_SHARE) / context.rearCount;
|
|
1259
|
+
const brakeTorque = spec.brakeForce * clamp5(condition.brakes ?? 1, 0, 1) * spec.wheelRadius * brakeShare;
|
|
1260
|
+
return {
|
|
1261
|
+
// x is to the vehicle's left and z ahead; the semi-simulation has z to the right
|
|
1262
|
+
position: [-wheel.z, spec.wheelRadius - spec.centreHeight + (free - sag), wheel.x],
|
|
1263
|
+
radius: flat ? rimRadius : spec.wheelRadius,
|
|
1264
|
+
width: options.wheelWidth ?? WHEEL_WIDTH,
|
|
1265
|
+
suspensionMin: free * SUSPENSION_MIN_SHARE,
|
|
1266
|
+
suspensionMax: free,
|
|
1267
|
+
frequency: Math.sqrt(spring / cornerMass) / (2 * Math.PI),
|
|
1268
|
+
damping: damper / (2 * Math.sqrt(spring * cornerMass)),
|
|
1269
|
+
maxSteer: wheel.steer ? spec.maxSteer : 0,
|
|
1270
|
+
driven: spec.fourWheelDrive || wheel.drive === true,
|
|
1271
|
+
maxBrakeTorque: brakeTorque,
|
|
1272
|
+
maxHandBrakeTorque: wheel.handbrake ? spec.brakeForce * spec.wheelRadius * HANDBRAKE_SHARE / context.handbrakeCount : 0,
|
|
1273
|
+
inertia: options.wheelInertia ?? (options.pedal ? BICYCLE_WHEEL_INERTIA : Math.max(MIN_WHEEL_INERTIA, WHEEL_INERTIA_PER_MASS * spec.mass * (spec.wheelRadius / REFERENCE_RADIUS) ** 2)),
|
|
1274
|
+
angularDamping: WHEEL_DAMPING,
|
|
1275
|
+
longitudinalFriction: longitudinalCurve(friction),
|
|
1276
|
+
lateralFriction: lateralCurve(friction, spec.tyre.corneringStiffness)
|
|
1277
|
+
};
|
|
1278
|
+
};
|
|
1279
|
+
var wheelContext = (spec, options) => {
|
|
1280
|
+
const meanX = spec.wheels.reduce((sum, wheel) => sum + wheel.x, 0) / spec.wheels.length;
|
|
1281
|
+
const frontCount = spec.wheels.filter((wheel) => wheel.x >= meanX).length;
|
|
1282
|
+
return {
|
|
1283
|
+
spec,
|
|
1284
|
+
condition: options.condition ?? {},
|
|
1285
|
+
options,
|
|
1286
|
+
frontFrom: meanX,
|
|
1287
|
+
frontCount,
|
|
1288
|
+
rearCount: Math.max(1, spec.wheels.length - frontCount),
|
|
1289
|
+
handbrakeCount: Math.max(1, spec.wheels.filter((wheel) => wheel.handbrake).length)
|
|
1290
|
+
};
|
|
1291
|
+
};
|
|
1292
|
+
var inertiaOf = (spec) => {
|
|
1293
|
+
const xs = spec.wheels.map((wheel) => wheel.x);
|
|
1294
|
+
const zs = spec.wheels.map((wheel) => wheel.z);
|
|
1295
|
+
const wheelbase = Math.max(...xs) - Math.min(...xs);
|
|
1296
|
+
const track = Math.max(...zs) - Math.min(...zs);
|
|
1297
|
+
return [spec.mass * (wheelbase * wheelbase + 1) / 12, spec.yawInertia ?? spec.mass * (wheelbase * wheelbase + track * track) / 12, spec.mass * (track * track + 1) / 12];
|
|
1298
|
+
};
|
|
1299
|
+
var drivetrainOf = (spec, options) => {
|
|
1300
|
+
const pedal = options.pedal ?? spec.pedal;
|
|
1301
|
+
if (pedal) {
|
|
1302
|
+
const crankSpeed = pedal.cadenceRpm * 2 * Math.PI / 60;
|
|
1303
|
+
return {
|
|
1304
|
+
engineDamping: ENGINE_DAMPING,
|
|
1305
|
+
engineInertia: ENGINE_INERTIA_PER_TORQUE * (pedal.watts / crankSpeed),
|
|
1306
|
+
maxTorque: pedal.watts / crankSpeed * spec.efficiency,
|
|
1307
|
+
minRpm: 0,
|
|
1308
|
+
maxRpm: pedal.cadenceRpm * 1.5,
|
|
1309
|
+
// the engine turns once for every wheel turn / ratio: a gear of 2 turns the wheel twice a pedal turn
|
|
1310
|
+
gears: pedal.gears.map((ratio) => 1 / ratio),
|
|
1311
|
+
reverseGears: [],
|
|
1312
|
+
differentialRatio: 1,
|
|
1313
|
+
torqueCurve: [[0, 1], [0.67, 1], [1, 0]],
|
|
1314
|
+
transmission: { shiftUpRpm: pedal.cadenceRpm * 0.95, shiftDownRpm: pedal.cadenceRpm * 0.5, clutchStrength: clutchFor(pedal.watts / crankSpeed, pedal.cadenceRpm * 1.5) }
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
const health = clamp5(options.condition?.engine ?? 1, 0, 1);
|
|
1318
|
+
return {
|
|
1319
|
+
engineDamping: ENGINE_DAMPING,
|
|
1320
|
+
engineInertia: ENGINE_INERTIA_PER_TORQUE * spec.engine.peakTorque,
|
|
1321
|
+
maxTorque: spec.engine.peakTorque * spec.efficiency * (ENGINE_FLOOR + (1 - ENGINE_FLOOR) * health),
|
|
1322
|
+
minRpm: spec.engine.idleRpm,
|
|
1323
|
+
maxRpm: spec.engine.redlineRpm,
|
|
1324
|
+
gears: spec.gears,
|
|
1325
|
+
reverseGears: [-spec.reverseRatio],
|
|
1326
|
+
differentialRatio: spec.finalDrive,
|
|
1327
|
+
torqueCurve: torqueCurve(spec),
|
|
1328
|
+
transmission: {
|
|
1329
|
+
shiftUpRpm: spec.engine.redlineRpm * spec.upshiftFraction,
|
|
1330
|
+
shiftDownRpm: spec.engine.redlineRpm * spec.downshiftFraction,
|
|
1331
|
+
clutchStrength: clutchFor(spec.engine.peakTorque, spec.engine.redlineRpm),
|
|
1332
|
+
...spec.wheels.length === 2 ? MOTORCYCLE_TRANSMISSION : CAR_TRANSMISSION
|
|
1333
|
+
}
|
|
1334
|
+
};
|
|
1335
|
+
};
|
|
1336
|
+
var trackedOf = (spec, tracks) => {
|
|
1337
|
+
const count = Math.max(2, tracks.roadWheels);
|
|
1338
|
+
const alongX = (index) => tracks.rearX + (tracks.frontX - tracks.rearX) * index / (count - 1);
|
|
1339
|
+
const wheels = [-1, 1].flatMap((side2) => Array.from({ length: count }, (_, index) => ({ x: alongX(index), z: side2 * tracks.gauge / 2 })));
|
|
1340
|
+
const friction = spec.tyre.friction;
|
|
1341
|
+
const side = (first) => ({ wheels: Array.from({ length: count }, (_, index) => first + index), drivenWheel: first, longitudinalFriction: friction, lateralFriction: TRACK_LATERAL_FRICTION, maxBrakeTorque: spec.brakeForce * spec.wheelRadius / 2 });
|
|
1342
|
+
return { spec: { ...spec, wheels }, tracks: [side(0), side(count)] };
|
|
1343
|
+
};
|
|
1344
|
+
var vehicleDescFromSemi = (spec, options) => {
|
|
1345
|
+
const tracked = spec.tracks ? trackedOf(spec, spec.tracks) : void 0;
|
|
1346
|
+
const body = tracked ? tracked.spec : spec;
|
|
1347
|
+
const context = wheelContext(body, options);
|
|
1348
|
+
const inertia = inertiaOf(spec);
|
|
1349
|
+
const bike = body.wheels.length === 2;
|
|
1350
|
+
return {
|
|
1351
|
+
// no damping of the body's own: it would be a drag of 0.05 m/s per m/s (1.8 kN at 28 m/s on a 1.3 t car) the spec never asked for; `resistanceImpulse` is the drag
|
|
1352
|
+
chassis: { linearDamping: 0, angularDamping: 0, ...options.chassis, motion: "dynamic", mass: spec.mass, inertia, centreAtOrigin: true, allowSleep: true },
|
|
1353
|
+
wheels: body.wheels.map((wheel, index) => wheelOf(wheel, index, context)),
|
|
1354
|
+
...drivetrainOf(spec, options),
|
|
1355
|
+
...tracked ? { controller: "tracked", tracks: tracked.tracks } : {},
|
|
1356
|
+
...bike ? { controller: "motorcycle", motorcycle: { maxLeanAngle: LEAN_LIMIT, leanSpring: LEAN_SPRING_PER_INERTIA * inertia[2], leanDamping: LEAN_DAMPING_PER_INERTIA * inertia[2] } } : {}
|
|
1357
|
+
};
|
|
1358
|
+
};
|
|
1359
|
+
var DEFAULT_PHYSICS_INPUT = { steerResponse: 5, steerFalloff: 0.012, steerFloor: 0.4, reverseBelow: 0.5, pullShare: 0.2 };
|
|
1360
|
+
var clamp6 = (x, low, high) => Math.max(low, Math.min(high, x));
|
|
1361
|
+
var createPhysicsInputMapper = (options = {}) => {
|
|
1362
|
+
const rules = { ...DEFAULT_PHYSICS_INPUT, ...options };
|
|
1363
|
+
let steering = 0;
|
|
1364
|
+
return {
|
|
1365
|
+
reset() {
|
|
1366
|
+
steering = 0;
|
|
1367
|
+
},
|
|
1368
|
+
map({ input, speed, dt, status }) {
|
|
1369
|
+
const pedal = clamp6(input.throttle, 0, 1) - clamp6(input.brake, 0, 1);
|
|
1370
|
+
const powerLimit = clamp6(input.powerLimit ?? 1, 0, 1);
|
|
1371
|
+
const canDrive = status?.canDrive ?? true;
|
|
1372
|
+
const brakeSoftness = 1 / Math.max(1, status?.brakeFactor ?? 1);
|
|
1373
|
+
let forward = 0;
|
|
1374
|
+
let brake = 0;
|
|
1375
|
+
if (pedal > 0) {
|
|
1376
|
+
if (speed < -rules.reverseBelow) brake = pedal * brakeSoftness;
|
|
1377
|
+
else forward = pedal * powerLimit;
|
|
1378
|
+
} else if (pedal < 0) {
|
|
1379
|
+
if (speed > rules.reverseBelow) brake = -pedal * brakeSoftness;
|
|
1380
|
+
else forward = pedal * powerLimit;
|
|
1381
|
+
}
|
|
1382
|
+
const lock = Math.max(rules.steerFloor, 1 - rules.steerFalloff * Math.abs(speed));
|
|
1383
|
+
const target = -clamp6(input.steer, -1, 1) * lock;
|
|
1384
|
+
steering += (target - steering) * Math.min(1, dt * rules.steerResponse);
|
|
1385
|
+
const pull = clamp6(status?.steerPull ?? 0, -1, 1) * rules.pullShare;
|
|
1386
|
+
return { forward: canDrive ? forward : 0, right: clamp6(steering + pull, -1, 1), brake, handBrake: input.handbrake ? 1 : 0 };
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
};
|
|
1390
|
+
var GRAVITY2 = 9.81;
|
|
1391
|
+
var ROLLING_FADE_SPEED = 0.5;
|
|
1392
|
+
var resistanceImpulse = (spec, velocity, dt) => {
|
|
1393
|
+
const speed = Math.hypot(velocity[0], velocity[2]);
|
|
1394
|
+
if (speed === 0) return [0, 0, 0];
|
|
1395
|
+
const rolling = spec.rolling * spec.mass * GRAVITY2 * Math.min(1, speed / ROLLING_FADE_SPEED);
|
|
1396
|
+
const along = -(spec.drag * speed * speed + rolling) * dt;
|
|
1397
|
+
return [velocity[0] / speed * along, 0, velocity[2] / speed * along];
|
|
1398
|
+
};
|
|
1124
1399
|
|
|
1125
1400
|
// src/ranges.ts
|
|
1126
1401
|
var lerpTable = (table, x) => {
|
|
@@ -1133,6 +1408,11 @@ var GameVehiclesProving = (() => {
|
|
|
1133
1408
|
return table[table.length - 1][1];
|
|
1134
1409
|
};
|
|
1135
1410
|
var defaultRangeTable = {
|
|
1411
|
+
accelerationByClass: {
|
|
1412
|
+
cars: [[1, 15.5], [10, 4.8]],
|
|
1413
|
+
suvs: [[1, 12.7], [10, 6.7]],
|
|
1414
|
+
motorcycles: [[1, 19.5], [10, 4.35]]
|
|
1415
|
+
},
|
|
1136
1416
|
accelerationSeconds: [
|
|
1137
1417
|
[1, 34],
|
|
1138
1418
|
[3, 21],
|
|
@@ -1150,7 +1430,7 @@ var GameVehiclesProving = (() => {
|
|
|
1150
1430
|
};
|
|
1151
1431
|
var byClass = (table, category) => table[category] ?? table.default;
|
|
1152
1432
|
var expectedAcceleration = (table, subject, target) => {
|
|
1153
|
-
const base = lerpTable(table.accelerationSeconds, subject.stats.acceleration);
|
|
1433
|
+
const base = lerpTable(table.accelerationByClass[subject.category] ?? table.accelerationSeconds, subject.stats.acceleration);
|
|
1154
1434
|
return base * (target / 100);
|
|
1155
1435
|
};
|
|
1156
1436
|
var accelerationRange = (table, subject, target) => {
|
|
@@ -1180,6 +1460,18 @@ var GameVehiclesProving = (() => {
|
|
|
1180
1460
|
// src/run.ts
|
|
1181
1461
|
var subjectSpec = (subject) => ({ ...semiSpecFromStats(subject.stats, subject.body), ...subject.spec });
|
|
1182
1462
|
var STEPS_PER_TICK = 2;
|
|
1463
|
+
function resultOf({ test, subject, memo, trace, done, state, time }) {
|
|
1464
|
+
const procedure = test.procedure;
|
|
1465
|
+
if (!procedure) throw new Error(`resultOf: ${test.id} is not a measured test`);
|
|
1466
|
+
const range = test.range?.(subject) ?? {};
|
|
1467
|
+
const base = { test: test.id, kind: test.kind, unit: test.unit, range, trace: [...trace] };
|
|
1468
|
+
if (!done) return { ...base, verdict: "pending", value: null, note: "running" };
|
|
1469
|
+
const value = procedure.value(state, time, memo);
|
|
1470
|
+
const lowered = memo.target > 0 && /_100|_80/.test(test.id) && memo.target < (test.id.includes("80") ? 80 : 100);
|
|
1471
|
+
const note = lowered ? `target ${memo.target} km/h` : void 0;
|
|
1472
|
+
if (value == null) return { ...base, verdict: "fail", value: null, note: `did not finish in ${procedure.maxSeconds} s` };
|
|
1473
|
+
return { ...base, verdict: inRange(value, range) ? "pass" : "fail", value, ...note ? { note } : {} };
|
|
1474
|
+
}
|
|
1183
1475
|
function startRun(test, subject, options = {}) {
|
|
1184
1476
|
const procedure = test.procedure;
|
|
1185
1477
|
if (test.kind !== "measured" || !procedure) throw new Error(`startRun: ${test.id} is not a measured test`);
|
|
@@ -1238,14 +1530,7 @@ var GameVehiclesProving = (() => {
|
|
|
1238
1530
|
scheduler.frame(seconds, { exact: true, render: false });
|
|
1239
1531
|
},
|
|
1240
1532
|
result() {
|
|
1241
|
-
|
|
1242
|
-
const base = { test: test.id, kind: test.kind, unit: test.unit, range, trace: [...trace] };
|
|
1243
|
-
if (!done) return { ...base, verdict: "pending", value: null, note: "running" };
|
|
1244
|
-
const value = procedure.value(driver.state, time, memo);
|
|
1245
|
-
const lowered = memo.target > 0 && /_100|_80/.test(test.id) && memo.target < (test.id.includes("80") ? 80 : 100);
|
|
1246
|
-
const note = lowered ? `target ${memo.target} km/h` : void 0;
|
|
1247
|
-
if (value == null) return { ...base, verdict: "fail", value: null, note: `did not finish in ${procedure.maxSeconds} s` };
|
|
1248
|
-
return { ...base, verdict: inRange(value, range) ? "pass" : "fail", value, ...note ? { note } : {} };
|
|
1533
|
+
return resultOf({ test, subject, memo, trace, done, state: driver.state, time });
|
|
1249
1534
|
}
|
|
1250
1535
|
};
|
|
1251
1536
|
}
|
|
@@ -1469,6 +1754,147 @@ var GameVehiclesProving = (() => {
|
|
|
1469
1754
|
}
|
|
1470
1755
|
};
|
|
1471
1756
|
}
|
|
1757
|
+
|
|
1758
|
+
// src/physics-run.ts
|
|
1759
|
+
var GROUND_HALF = 2e4;
|
|
1760
|
+
var CHASSIS_MARGIN_SIDE = 0.1;
|
|
1761
|
+
var CHASSIS_MARGIN_END = 0.6;
|
|
1762
|
+
var CHASSIS_HALF_HEIGHT = 0.35;
|
|
1763
|
+
var chassisOf = (spec) => {
|
|
1764
|
+
const xs = spec.wheels.map((wheel) => wheel.x);
|
|
1765
|
+
const zs = spec.wheels.map((wheel) => Math.abs(wheel.z));
|
|
1766
|
+
return { half: [Math.max(...zs) + CHASSIS_MARGIN_SIDE, CHASSIS_HALF_HEIGHT, (Math.max(...xs) - Math.min(...xs)) / 2 + CHASSIS_MARGIN_END] };
|
|
1767
|
+
};
|
|
1768
|
+
var emptyState = (spec) => ({
|
|
1769
|
+
x: 0,
|
|
1770
|
+
z: 0,
|
|
1771
|
+
yaw: 0,
|
|
1772
|
+
u: 0,
|
|
1773
|
+
w: 0,
|
|
1774
|
+
yawRate: 0,
|
|
1775
|
+
height: spec.centreHeight,
|
|
1776
|
+
heightRate: 0,
|
|
1777
|
+
pitch: 0,
|
|
1778
|
+
pitchRate: 0,
|
|
1779
|
+
roll: 0,
|
|
1780
|
+
rollRate: 0,
|
|
1781
|
+
rpm: 0,
|
|
1782
|
+
gear: 0,
|
|
1783
|
+
engineOn: true,
|
|
1784
|
+
bogged: false,
|
|
1785
|
+
fuel: spec.tank.capacity,
|
|
1786
|
+
loads: spec.wheels.map(() => 0),
|
|
1787
|
+
slip: spec.wheels.map(() => 0),
|
|
1788
|
+
steerAngle: 0
|
|
1789
|
+
});
|
|
1790
|
+
var makeGround = (world, grip) => world.createBody({
|
|
1791
|
+
shape: { kind: "box", half: [GROUND_HALF, 0.5, GROUND_HALF] },
|
|
1792
|
+
motion: "static",
|
|
1793
|
+
position: [0, -0.5, 0],
|
|
1794
|
+
user: -1,
|
|
1795
|
+
material: { frictionStatic: grip, frictionDynamic: grip, restitution: 0 }
|
|
1796
|
+
});
|
|
1797
|
+
function startPhysicsRun(test, subject, options) {
|
|
1798
|
+
const procedure = test.procedure;
|
|
1799
|
+
if (test.kind !== "measured" || !procedure) throw new Error(`startPhysicsRun: ${test.id} is not a measured test`);
|
|
1800
|
+
const spec = subjectSpec(subject);
|
|
1801
|
+
const surfaces = options.surfaces ?? createSurfaces();
|
|
1802
|
+
const surfaceId = procedure.surface ?? "dry_asphalt";
|
|
1803
|
+
const surface = surfaces.get(surfaceId);
|
|
1804
|
+
const world = options.createWorld();
|
|
1805
|
+
const ground = makeGround(world, surface.grip);
|
|
1806
|
+
const half = chassisOf(spec).half;
|
|
1807
|
+
const desc = vehicleDescFromSemi(spec, { chassis: { shape: { kind: "box", half }, position: [0, spec.centreHeight + 0.05, 0], user: 1 } });
|
|
1808
|
+
const vehicle = world.createVehicle(desc);
|
|
1809
|
+
const body = world.vehicleBody(vehicle);
|
|
1810
|
+
const mapper = createPhysicsInputMapper();
|
|
1811
|
+
const memo = { target: procedure.target?.(subject) ?? 0, subject };
|
|
1812
|
+
const trace = [];
|
|
1813
|
+
const state = emptyState(spec);
|
|
1814
|
+
const pose = new Float64Array(7);
|
|
1815
|
+
const velocity = new Float64Array(6);
|
|
1816
|
+
const fixed = options.fixedStep ?? 1 / 120;
|
|
1817
|
+
const sampleEvery = options.sampleEvery ?? 0.1;
|
|
1818
|
+
let time = 0;
|
|
1819
|
+
let nextSample = 0;
|
|
1820
|
+
let done = false;
|
|
1821
|
+
let last = { throttle: 0, brake: 0, steer: 0, handbrake: false };
|
|
1822
|
+
let groundGrip = surface.grip;
|
|
1823
|
+
const readState = () => {
|
|
1824
|
+
world.readPose(body, pose, 0);
|
|
1825
|
+
world.readVelocity(body, velocity, 0);
|
|
1826
|
+
const [qx, qy, qz, qw] = [pose[3], pose[4], pose[5], pose[6]];
|
|
1827
|
+
const forward = [2 * (qx * qz + qw * qy), 2 * (qy * qz - qw * qx), 1 - 2 * (qx * qx + qy * qy)];
|
|
1828
|
+
state.u = velocity[0] * forward[0] + velocity[1] * forward[1] + velocity[2] * forward[2];
|
|
1829
|
+
state.w = 0;
|
|
1830
|
+
state.x = pose[2];
|
|
1831
|
+
state.z = pose[0];
|
|
1832
|
+
state.yaw = Math.atan2(forward[0], forward[2]);
|
|
1833
|
+
state.yawRate = velocity[4];
|
|
1834
|
+
state.height = pose[1];
|
|
1835
|
+
state.pitch = Math.asin(Math.max(-1, Math.min(1, forward[1])));
|
|
1836
|
+
state.roll = Math.asin(Math.max(-1, Math.min(1, 2 * (qx * qy + qw * qz))));
|
|
1837
|
+
};
|
|
1838
|
+
const tick = (h) => {
|
|
1839
|
+
const input = procedure.input(state, time, memo);
|
|
1840
|
+
last = input;
|
|
1841
|
+
const grip = surfaceGrip(surface, state.u);
|
|
1842
|
+
if (grip !== groundGrip) {
|
|
1843
|
+
groundGrip = grip;
|
|
1844
|
+
world.setMaterial(ground, { frictionStatic: grip, frictionDynamic: grip, restitution: 0 });
|
|
1845
|
+
}
|
|
1846
|
+
world.driveVehicle(vehicle, mapper.map({ input, speed: state.u, dt: h }));
|
|
1847
|
+
const v = [velocity[0], velocity[1], velocity[2]];
|
|
1848
|
+
world.addImpulse(body, resistanceImpulse(spec, v, h));
|
|
1849
|
+
if (surface.bogs && !spec.fourWheelDrive && input.throttle > 0) {
|
|
1850
|
+
const extra = resistanceImpulse({ drag: 0, rolling: spec.bogResistance - spec.rolling, mass: spec.mass }, v, h);
|
|
1851
|
+
world.addImpulse(body, extra);
|
|
1852
|
+
}
|
|
1853
|
+
world.step(h);
|
|
1854
|
+
readState();
|
|
1855
|
+
time += h;
|
|
1856
|
+
if (time >= nextSample) {
|
|
1857
|
+
trace.push([Math.round(time * 1e3) / 1e3, procedure.sample(state, time, memo)]);
|
|
1858
|
+
nextSample += sampleEvery;
|
|
1859
|
+
}
|
|
1860
|
+
if (procedure.finished(state, time, memo) || time >= procedure.maxSeconds) done = true;
|
|
1861
|
+
};
|
|
1862
|
+
readState();
|
|
1863
|
+
return {
|
|
1864
|
+
test,
|
|
1865
|
+
subject,
|
|
1866
|
+
surface: surfaceId,
|
|
1867
|
+
memo,
|
|
1868
|
+
state,
|
|
1869
|
+
fixedStep: fixed,
|
|
1870
|
+
get time() {
|
|
1871
|
+
return time;
|
|
1872
|
+
},
|
|
1873
|
+
get done() {
|
|
1874
|
+
return done;
|
|
1875
|
+
},
|
|
1876
|
+
get trace() {
|
|
1877
|
+
return trace;
|
|
1878
|
+
},
|
|
1879
|
+
get input() {
|
|
1880
|
+
return last;
|
|
1881
|
+
},
|
|
1882
|
+
stepFixed(steps) {
|
|
1883
|
+
for (let i = 0; i < steps && !done; i++) tick(fixed);
|
|
1884
|
+
},
|
|
1885
|
+
result: () => resultOf({ test, subject, memo, trace, done, state, time }),
|
|
1886
|
+
dispose: () => world.dispose()
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
function runTestOnPhysics(test, subject, options) {
|
|
1890
|
+
const run = startPhysicsRun(test, subject, options);
|
|
1891
|
+
try {
|
|
1892
|
+
while (!run.done) run.stepFixed(1);
|
|
1893
|
+
return run.result();
|
|
1894
|
+
} finally {
|
|
1895
|
+
run.dispose();
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1472
1898
|
return __toCommonJS(index_exports);
|
|
1473
1899
|
})();
|
|
1474
1900
|
//# sourceMappingURL=index.global.js.map
|