@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/dist/index.js
CHANGED
|
@@ -13,6 +13,11 @@ var lerpTable = (table, x) => {
|
|
|
13
13
|
return table[table.length - 1][1];
|
|
14
14
|
};
|
|
15
15
|
var defaultRangeTable = {
|
|
16
|
+
accelerationByClass: {
|
|
17
|
+
cars: [[1, 15.5], [10, 4.8]],
|
|
18
|
+
suvs: [[1, 12.7], [10, 6.7]],
|
|
19
|
+
motorcycles: [[1, 19.5], [10, 4.35]]
|
|
20
|
+
},
|
|
16
21
|
accelerationSeconds: [
|
|
17
22
|
[1, 34],
|
|
18
23
|
[3, 21],
|
|
@@ -30,7 +35,7 @@ var defaultRangeTable = {
|
|
|
30
35
|
};
|
|
31
36
|
var byClass = (table, category) => table[category] ?? table.default;
|
|
32
37
|
var expectedAcceleration = (table, subject, target) => {
|
|
33
|
-
const base = lerpTable(table.accelerationSeconds, subject.stats.acceleration);
|
|
38
|
+
const base = lerpTable(table.accelerationByClass[subject.category] ?? table.accelerationSeconds, subject.stats.acceleration);
|
|
34
39
|
return base * (target / 100);
|
|
35
40
|
};
|
|
36
41
|
var accelerationRange = (table, subject, target) => {
|
|
@@ -60,6 +65,18 @@ var round = (x, digits = 1) => {
|
|
|
60
65
|
// src/run.ts
|
|
61
66
|
var subjectSpec = (subject) => ({ ...semiSpecFromStats(subject.stats, subject.body), ...subject.spec });
|
|
62
67
|
var STEPS_PER_TICK = 2;
|
|
68
|
+
function resultOf({ test, subject, memo, trace, done, state, time }) {
|
|
69
|
+
const procedure = test.procedure;
|
|
70
|
+
if (!procedure) throw new Error(`resultOf: ${test.id} is not a measured test`);
|
|
71
|
+
const range = test.range?.(subject) ?? {};
|
|
72
|
+
const base = { test: test.id, kind: test.kind, unit: test.unit, range, trace: [...trace] };
|
|
73
|
+
if (!done) return { ...base, verdict: "pending", value: null, note: "running" };
|
|
74
|
+
const value = procedure.value(state, time, memo);
|
|
75
|
+
const lowered = memo.target > 0 && /_100|_80/.test(test.id) && memo.target < (test.id.includes("80") ? 80 : 100);
|
|
76
|
+
const note = lowered ? `target ${memo.target} km/h` : void 0;
|
|
77
|
+
if (value == null) return { ...base, verdict: "fail", value: null, note: `did not finish in ${procedure.maxSeconds} s` };
|
|
78
|
+
return { ...base, verdict: inRange(value, range) ? "pass" : "fail", value, ...note ? { note } : {} };
|
|
79
|
+
}
|
|
63
80
|
function startRun(test, subject, options = {}) {
|
|
64
81
|
const procedure = test.procedure;
|
|
65
82
|
if (test.kind !== "measured" || !procedure) throw new Error(`startRun: ${test.id} is not a measured test`);
|
|
@@ -118,14 +135,7 @@ function startRun(test, subject, options = {}) {
|
|
|
118
135
|
scheduler.frame(seconds, { exact: true, render: false });
|
|
119
136
|
},
|
|
120
137
|
result() {
|
|
121
|
-
|
|
122
|
-
const base = { test: test.id, kind: test.kind, unit: test.unit, range, trace: [...trace] };
|
|
123
|
-
if (!done) return { ...base, verdict: "pending", value: null, note: "running" };
|
|
124
|
-
const value = procedure.value(driver.state, time, memo);
|
|
125
|
-
const lowered = memo.target > 0 && /_100|_80/.test(test.id) && memo.target < (test.id.includes("80") ? 80 : 100);
|
|
126
|
-
const note = lowered ? `target ${memo.target} km/h` : void 0;
|
|
127
|
-
if (value == null) return { ...base, verdict: "fail", value: null, note: `did not finish in ${procedure.maxSeconds} s` };
|
|
128
|
-
return { ...base, verdict: inRange(value, range) ? "pass" : "fail", value, ...note ? { note } : {} };
|
|
138
|
+
return resultOf({ test, subject, memo, trace, done, state: driver.state, time });
|
|
129
139
|
}
|
|
130
140
|
};
|
|
131
141
|
}
|
|
@@ -350,6 +360,148 @@ function subjectFromCard(id, card) {
|
|
|
350
360
|
}
|
|
351
361
|
};
|
|
352
362
|
}
|
|
363
|
+
|
|
364
|
+
// src/physics-run.ts
|
|
365
|
+
import { createPhysicsInputMapper, createSurfaces as createSurfaces2, resistanceImpulse, surfaceGrip, vehicleDescFromSemi } from "@adatechnology/game-vehicles-driving";
|
|
366
|
+
var GROUND_HALF = 2e4;
|
|
367
|
+
var CHASSIS_MARGIN_SIDE = 0.1;
|
|
368
|
+
var CHASSIS_MARGIN_END = 0.6;
|
|
369
|
+
var CHASSIS_HALF_HEIGHT = 0.35;
|
|
370
|
+
var chassisOf = (spec) => {
|
|
371
|
+
const xs = spec.wheels.map((wheel) => wheel.x);
|
|
372
|
+
const zs = spec.wheels.map((wheel) => Math.abs(wheel.z));
|
|
373
|
+
return { half: [Math.max(...zs) + CHASSIS_MARGIN_SIDE, CHASSIS_HALF_HEIGHT, (Math.max(...xs) - Math.min(...xs)) / 2 + CHASSIS_MARGIN_END] };
|
|
374
|
+
};
|
|
375
|
+
var emptyState = (spec) => ({
|
|
376
|
+
x: 0,
|
|
377
|
+
z: 0,
|
|
378
|
+
yaw: 0,
|
|
379
|
+
u: 0,
|
|
380
|
+
w: 0,
|
|
381
|
+
yawRate: 0,
|
|
382
|
+
height: spec.centreHeight,
|
|
383
|
+
heightRate: 0,
|
|
384
|
+
pitch: 0,
|
|
385
|
+
pitchRate: 0,
|
|
386
|
+
roll: 0,
|
|
387
|
+
rollRate: 0,
|
|
388
|
+
rpm: 0,
|
|
389
|
+
gear: 0,
|
|
390
|
+
engineOn: true,
|
|
391
|
+
bogged: false,
|
|
392
|
+
fuel: spec.tank.capacity,
|
|
393
|
+
loads: spec.wheels.map(() => 0),
|
|
394
|
+
slip: spec.wheels.map(() => 0),
|
|
395
|
+
steerAngle: 0
|
|
396
|
+
});
|
|
397
|
+
var makeGround = (world, grip) => world.createBody({
|
|
398
|
+
shape: { kind: "box", half: [GROUND_HALF, 0.5, GROUND_HALF] },
|
|
399
|
+
motion: "static",
|
|
400
|
+
position: [0, -0.5, 0],
|
|
401
|
+
user: -1,
|
|
402
|
+
material: { frictionStatic: grip, frictionDynamic: grip, restitution: 0 }
|
|
403
|
+
});
|
|
404
|
+
function startPhysicsRun(test, subject, options) {
|
|
405
|
+
const procedure = test.procedure;
|
|
406
|
+
if (test.kind !== "measured" || !procedure) throw new Error(`startPhysicsRun: ${test.id} is not a measured test`);
|
|
407
|
+
const spec = subjectSpec(subject);
|
|
408
|
+
const surfaces = options.surfaces ?? createSurfaces2();
|
|
409
|
+
const surfaceId = procedure.surface ?? "dry_asphalt";
|
|
410
|
+
const surface = surfaces.get(surfaceId);
|
|
411
|
+
const world = options.createWorld();
|
|
412
|
+
const ground = makeGround(world, surface.grip);
|
|
413
|
+
const half = chassisOf(spec).half;
|
|
414
|
+
const desc = vehicleDescFromSemi(spec, { chassis: { shape: { kind: "box", half }, position: [0, spec.centreHeight + 0.05, 0], user: 1 } });
|
|
415
|
+
const vehicle = world.createVehicle(desc);
|
|
416
|
+
const body = world.vehicleBody(vehicle);
|
|
417
|
+
const mapper = createPhysicsInputMapper();
|
|
418
|
+
const memo = { target: procedure.target?.(subject) ?? 0, subject };
|
|
419
|
+
const trace = [];
|
|
420
|
+
const state = emptyState(spec);
|
|
421
|
+
const pose = new Float64Array(7);
|
|
422
|
+
const velocity = new Float64Array(6);
|
|
423
|
+
const fixed = options.fixedStep ?? 1 / 120;
|
|
424
|
+
const sampleEvery = options.sampleEvery ?? 0.1;
|
|
425
|
+
let time = 0;
|
|
426
|
+
let nextSample = 0;
|
|
427
|
+
let done = false;
|
|
428
|
+
let last = { throttle: 0, brake: 0, steer: 0, handbrake: false };
|
|
429
|
+
let groundGrip = surface.grip;
|
|
430
|
+
const readState = () => {
|
|
431
|
+
world.readPose(body, pose, 0);
|
|
432
|
+
world.readVelocity(body, velocity, 0);
|
|
433
|
+
const [qx, qy, qz, qw] = [pose[3], pose[4], pose[5], pose[6]];
|
|
434
|
+
const forward = [2 * (qx * qz + qw * qy), 2 * (qy * qz - qw * qx), 1 - 2 * (qx * qx + qy * qy)];
|
|
435
|
+
state.u = velocity[0] * forward[0] + velocity[1] * forward[1] + velocity[2] * forward[2];
|
|
436
|
+
state.w = 0;
|
|
437
|
+
state.x = pose[2];
|
|
438
|
+
state.z = pose[0];
|
|
439
|
+
state.yaw = Math.atan2(forward[0], forward[2]);
|
|
440
|
+
state.yawRate = velocity[4];
|
|
441
|
+
state.height = pose[1];
|
|
442
|
+
state.pitch = Math.asin(Math.max(-1, Math.min(1, forward[1])));
|
|
443
|
+
state.roll = Math.asin(Math.max(-1, Math.min(1, 2 * (qx * qy + qw * qz))));
|
|
444
|
+
};
|
|
445
|
+
const tick = (h) => {
|
|
446
|
+
const input = procedure.input(state, time, memo);
|
|
447
|
+
last = input;
|
|
448
|
+
const grip = surfaceGrip(surface, state.u);
|
|
449
|
+
if (grip !== groundGrip) {
|
|
450
|
+
groundGrip = grip;
|
|
451
|
+
world.setMaterial(ground, { frictionStatic: grip, frictionDynamic: grip, restitution: 0 });
|
|
452
|
+
}
|
|
453
|
+
world.driveVehicle(vehicle, mapper.map({ input, speed: state.u, dt: h }));
|
|
454
|
+
const v = [velocity[0], velocity[1], velocity[2]];
|
|
455
|
+
world.addImpulse(body, resistanceImpulse(spec, v, h));
|
|
456
|
+
if (surface.bogs && !spec.fourWheelDrive && input.throttle > 0) {
|
|
457
|
+
const extra = resistanceImpulse({ drag: 0, rolling: spec.bogResistance - spec.rolling, mass: spec.mass }, v, h);
|
|
458
|
+
world.addImpulse(body, extra);
|
|
459
|
+
}
|
|
460
|
+
world.step(h);
|
|
461
|
+
readState();
|
|
462
|
+
time += h;
|
|
463
|
+
if (time >= nextSample) {
|
|
464
|
+
trace.push([Math.round(time * 1e3) / 1e3, procedure.sample(state, time, memo)]);
|
|
465
|
+
nextSample += sampleEvery;
|
|
466
|
+
}
|
|
467
|
+
if (procedure.finished(state, time, memo) || time >= procedure.maxSeconds) done = true;
|
|
468
|
+
};
|
|
469
|
+
readState();
|
|
470
|
+
return {
|
|
471
|
+
test,
|
|
472
|
+
subject,
|
|
473
|
+
surface: surfaceId,
|
|
474
|
+
memo,
|
|
475
|
+
state,
|
|
476
|
+
fixedStep: fixed,
|
|
477
|
+
get time() {
|
|
478
|
+
return time;
|
|
479
|
+
},
|
|
480
|
+
get done() {
|
|
481
|
+
return done;
|
|
482
|
+
},
|
|
483
|
+
get trace() {
|
|
484
|
+
return trace;
|
|
485
|
+
},
|
|
486
|
+
get input() {
|
|
487
|
+
return last;
|
|
488
|
+
},
|
|
489
|
+
stepFixed(steps) {
|
|
490
|
+
for (let i = 0; i < steps && !done; i++) tick(fixed);
|
|
491
|
+
},
|
|
492
|
+
result: () => resultOf({ test, subject, memo, trace, done, state, time }),
|
|
493
|
+
dispose: () => world.dispose()
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function runTestOnPhysics(test, subject, options) {
|
|
497
|
+
const run = startPhysicsRun(test, subject, options);
|
|
498
|
+
try {
|
|
499
|
+
while (!run.done) run.stepFixed(1);
|
|
500
|
+
return run.result();
|
|
501
|
+
} finally {
|
|
502
|
+
run.dispose();
|
|
503
|
+
}
|
|
504
|
+
}
|
|
353
505
|
export {
|
|
354
506
|
DEFAULT_DENSITY,
|
|
355
507
|
STEPS_PER_TICK,
|
|
@@ -363,7 +515,10 @@ export {
|
|
|
363
515
|
expectedAcceleration,
|
|
364
516
|
gateVehicles,
|
|
365
517
|
inRange,
|
|
518
|
+
resultOf,
|
|
366
519
|
runTest,
|
|
520
|
+
runTestOnPhysics,
|
|
521
|
+
startPhysicsRun,
|
|
367
522
|
startRun,
|
|
368
523
|
statusOf,
|
|
369
524
|
subjectFromCard,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/run.ts","../src/ranges.ts","../src/tests.ts","../src/certificate.ts","../src/fleet.ts"],"sourcesContent":["import { createScheduler } from '@adatechnology/game-runtime'\nimport type { Scheduler } from '@adatechnology/game-runtime'\nimport { createSemiSimDriver, createSurfaces, semiSpecFromStats } from '@adatechnology/game-vehicles-driving'\nimport type { SemiDriver, SemiInput, SemiSimSpec, SurfaceRegistry } from '@adatechnology/game-vehicles-driving'\n\nimport { inRange } from './ranges'\nimport type { ProvingMemo, ProvingResult, ProvingSubject, ProvingTest } from './types'\n\n/** The semi-simulation spec the runner drives a subject with: from the card's ratings and the body, with the subject's own overrides. */\nexport const subjectSpec = (subject: ProvingSubject): SemiSimSpec => ({ ...semiSpecFromStats(subject.stats, subject.body), ...subject.spec })\n\n/** Physics steps of one scheduler tick (1/60 s): the proving run steps its driver at twice the tick, as the room's physics loop does. */\nexport const STEPS_PER_TICK = 2\n\n/**\n * One measured test in progress. It owns no clock: a host registers `stepFixed(STEPS_PER_TICK)` in its scheduler's `fixedSimulate` and draws `driver.state`;\n * standalone (tests, CLI) the caller drives `stepFixed` or the thin `advance(seconds)`. `runTest` steps it to the end in one go.\n */\nexport interface ProvingRun {\n readonly test: ProvingTest\n readonly subject: ProvingSubject\n readonly driver: SemiDriver\n readonly surface: string\n readonly time: number\n readonly done: boolean\n /** [seconds, sample] of the run so far. */\n readonly trace: ReadonlyArray<[number, number]>\n readonly memo: ProvingMemo\n /** What the procedure asked of the controls on the last step (all zero before the first): a host plays the brakes and the engine from it. */\n readonly input: SemiInput\n /** Seconds of one physics step (`RunOptions.fixedStep`, default 1/120). */\n readonly fixedStep: number\n /** Runs `steps` physics steps now (stops at the end of the run); no accumulator, no time scale: the caller's scheduler decides how many. */\n stepFixed(steps: number): void\n /** Standalone helper: feeds `seconds` to a private `game-runtime` scheduler (exact, no render) whose fixed tick runs `STEPS_PER_TICK` steps; the remainder waits for the next call. */\n advance(seconds: number): void\n /** The result so far; pending while the run has not ended. */\n result(): ProvingResult\n}\n\nexport interface RunOptions {\n surfaces?: SurfaceRegistry\n /** Seconds between two trace samples (default 0.1). */\n sampleEvery?: number\n /** Fixed step of the simulation (default 1/120 s): the seconds one `stepFixed` step integrates. */\n fixedStep?: number\n}\n\nexport function startRun(test: ProvingTest, subject: ProvingSubject, options: RunOptions = {}): ProvingRun {\n const procedure = test.procedure\n if (test.kind !== 'measured' || !procedure) throw new Error(`startRun: ${test.id} is not a measured test`)\n const surfaces = options.surfaces ?? createSurfaces()\n const driver = createSemiSimDriver(subjectSpec(subject), { surfaces })\n driver.place(0, 0, 0)\n const surface = procedure.surface ?? 'dry_asphalt'\n const world = { ground: () => ({ surface }) }\n const memo: ProvingMemo = { target: procedure.target?.(subject) ?? 0, subject }\n const trace: Array<[number, number]> = []\n const sampleEvery = options.sampleEvery ?? 0.1\n const fixed = options.fixedStep ?? 1 / 120\n let time = 0\n let done = false\n let nextSample = 0\n let scheduler: Scheduler | undefined\n let last: SemiInput = { throttle: 0, brake: 0, steer: 0, handbrake: false }\n const tick = (h: number): void => {\n const input = procedure.input(driver.state, time, memo)\n last = input\n driver.step(input, h, world)\n time += h\n if (time >= nextSample) {\n trace.push([Math.round(time * 1000) / 1000, procedure.sample(driver.state, time, memo)])\n nextSample += sampleEvery\n }\n if (procedure.finished(driver.state, time, memo) || time >= procedure.maxSeconds) done = true\n }\n return {\n test,\n subject,\n driver,\n surface,\n memo,\n get time() {\n return time\n },\n get done() {\n return done\n },\n get trace() {\n return trace\n },\n get input() {\n return last\n },\n fixedStep: fixed,\n stepFixed(steps) {\n for (let i = 0; i < steps && !done; i++) tick(fixed)\n },\n advance(seconds) {\n if (!scheduler) {\n scheduler = createScheduler({ fixedDt: fixed * STEPS_PER_TICK })\n scheduler.add(() => this.stepFixed(STEPS_PER_TICK), { phase: 'fixedSimulate', id: 'proving.run' })\n }\n scheduler.frame(seconds, { exact: true, render: false })\n },\n result() {\n const range = test.range?.(subject) ?? {}\n const base = { test: test.id, kind: test.kind, unit: test.unit, range, trace: [...trace] }\n if (!done) return { ...base, verdict: 'pending', value: null, note: 'running' }\n const value = procedure.value(driver.state, time, memo)\n const lowered = memo.target > 0 && /_100|_80/.test(test.id) && memo.target < (test.id.includes('80') ? 80 : 100)\n const note = lowered ? `target ${memo.target} km/h` : undefined\n if (value == null) return { ...base, verdict: 'fail', value: null, note: `did not finish in ${procedure.maxSeconds} s` }\n return { ...base, verdict: inRange(value, range) ? 'pass' : 'fail', value, ...(note ? { note } : {}) }\n },\n }\n}\n\n/** Runs a measured test to its end and returns the result. */\nexport function runTest(test: ProvingTest, subject: ProvingSubject, options: RunOptions = {}): ProvingResult {\n const run = startRun(test, subject, options)\n while (!run.done) run.stepFixed(STEPS_PER_TICK)\n return run.result()\n}\n","import type { ProvingRange, ProvingSubject } from './types'\n\nconst lerpTable = (table: ReadonlyArray<readonly [number, number]>, x: number): number => {\n if (x <= table[0]![0]) return table[0]![1]\n for (let i = 1; i < table.length; i++) {\n const [x1, y1] = table[i]!\n const [x0, y0] = table[i - 1]!\n if (x <= x1) return y0 + ((y1 - y0) * (x - x0)) / (x1 - x0)\n }\n return table[table.length - 1]![1]\n}\n\n/**\n * The numbers the ranges come from. Real-world bands for road vehicles (a family car stops from 100 km/h in 35-45 m, turns in 10-11 m, a hatch reaches 100 km/h in about 10 s); every one can\n * be replaced per class through `createProvingTests({ ranges })`.\n */\nexport interface RangeTable {\n /** 0-100 km/h seconds by the card's acceleration rating (0-10). */\n accelerationSeconds: ReadonlyArray<readonly [number, number]>\n /** Accepted spread around the expected 0-100 time (0.35 = ±35 %). */\n accelerationSpread: number\n /** Accepted spread around the card's top speed. */\n topSpeedSpread: number\n /** Braking deceleration on dry asphalt, m/s², by class. */\n dryBrake: Readonly<Record<string, readonly [number, number]>>\n /** Braking deceleration on wet asphalt, m/s², by class. */\n wetBrake: Readonly<Record<string, readonly [number, number]>>\n /** Turning circle diameter, metres, by class. */\n turnCircle: Readonly<Record<string, readonly [number, number]>>\n /** Metres a four-wheel-drive vehicle has to cover in the mud test. */\n mudFourWheelDrive: number\n}\n\nexport const defaultRangeTable: RangeTable = {\n accelerationSeconds: [\n [1, 34],\n [3, 21],\n [5, 14],\n [7, 10],\n [9, 6],\n [10, 4.2],\n ],\n accelerationSpread: 0.35,\n topSpeedSpread: 0.1,\n dryBrake: { default: [6.5, 11], heavy: [4.5, 8.5], agricultural: [3.5, 7.5], military: [4.5, 9] },\n wetBrake: { default: [3.5, 8.5], heavy: [2.5, 7], agricultural: [2, 6], military: [2.5, 7] },\n turnCircle: { default: [7, 13.5], motorcycles: [3, 9], suvs: [9, 15], pickups: [9, 16], vans: [9, 15], heavy: [10, 26], military: [9, 24], agricultural: [6, 16] },\n mudFourWheelDrive: 10,\n}\n\nconst byClass = <T>(table: Readonly<Record<string, T>>, category: string): T => (table[category] ?? table.default) as T\n\n/** Expected 0-100 (or 0-`target`) seconds for a subject. Below 100 km/h the time scales linearly with the target speed. */\nexport const expectedAcceleration = (table: RangeTable, subject: ProvingSubject, target: number): number => {\n const base = lerpTable(table.accelerationSeconds, subject.stats.acceleration)\n return base * (target / 100)\n}\n\nexport const accelerationRange = (table: RangeTable, subject: ProvingSubject, target: number): ProvingRange => {\n const t = expectedAcceleration(table, subject, target)\n return { min: round(t * (1 - table.accelerationSpread)), max: round(t * (1 + table.accelerationSpread)) }\n}\n\nexport const topSpeedRange = (table: RangeTable, subject: ProvingSubject): ProvingRange => ({\n min: round(subject.stats.maxSpeedKmh * (1 - table.topSpeedSpread)),\n max: round(subject.stats.maxSpeedKmh * (1 + table.topSpeedSpread)),\n})\n\n/** Stopping distance band from `kmh` for the class's deceleration band. */\nexport const brakeRange = (decel: readonly [number, number], kmh: number): ProvingRange => {\n const v = kmh / 3.6\n return { min: round((v * v) / (2 * decel[1])), max: round((v * v) / (2 * decel[0])) }\n}\n\nexport const dryBrakeRange = (table: RangeTable, subject: ProvingSubject, kmh: number): ProvingRange => brakeRange(byClass(table.dryBrake, subject.category), kmh)\nexport const wetBrakeRange = (table: RangeTable, subject: ProvingSubject, kmh: number): ProvingRange => brakeRange(byClass(table.wetBrake, subject.category), kmh)\nexport const turnCircleRange = (table: RangeTable, subject: ProvingSubject): ProvingRange => {\n const [min, max] = byClass(table.turnCircle, subject.category)\n return { min, max }\n}\n\nexport const inRange = (value: number, range: ProvingRange): boolean => (range.min == null || value >= range.min) && (range.max == null || value <= range.max)\n\nexport const round = (x: number, digits = 1): number => {\n const k = 10 ** digits\n return Math.round(x * k) / k\n}\n","import { applyPatches, mergeById, removeIds } from '@adatechnology/game-contracts'\nimport type { SemiInput, SemiState } from '@adatechnology/game-vehicles-driving'\n\nimport { accelerationRange, defaultRangeTable, dryBrakeRange, round, topSpeedRange, turnCircleRange, wetBrakeRange } from './ranges'\nimport type { RangeTable } from './ranges'\nimport type { ProvingMemo, ProvingProcedure, ProvingSubject, ProvingTest } from './types'\n\nconst KMH = 3.6\nconst idle: SemiInput = { throttle: 0, brake: 0, steer: 0, handbrake: false }\nconst kmh = (s: SemiState): number => Math.abs(s.u) * KMH\nconst travelled = (s: SemiState, memo: ProvingMemo, key: string): number => Math.hypot(s.x - (memo[`${key}X`] as number), s.z - (memo[`${key}Z`] as number))\n\n/** Speed a run aims for: `wanted`, or 80 % of the vehicle's top speed when it cannot reach it (a tractor, a bicycle). */\nconst reachable = (subject: ProvingSubject, wanted: number): number => Math.min(wanted, Math.round(subject.stats.maxSpeedKmh * 0.8))\n\n/** Accelerates to the target, then brakes flat out in a straight line; the value is the distance from the first metre of braking to the stop. */\nconst brakeFrom = (wanted: number, surface?: string): ProvingProcedure => ({\n ...(surface ? { surface } : {}),\n maxSeconds: 90,\n target: (subject) => reachable(subject, wanted),\n input(state, _time, memo) {\n if (!memo.braking && kmh(state) >= memo.target) {\n memo.braking = true\n memo.brakeX = state.x\n memo.brakeZ = state.z\n }\n return memo.braking ? { ...idle, brake: 1 } : { ...idle, throttle: 1 }\n },\n sample: (state) => kmh(state),\n finished: (state, _t, memo) => !!memo.braking && kmh(state) < 0.3,\n value: (state, _t, memo) => (memo.braking ? round(travelled(state, memo, 'brake')) : null),\n})\n\n/** The tests of the kit. Every number comes from the range table; a game replaces the table, patches a test or adds its own. */\nexport function defaultProvingTests(ranges: RangeTable = defaultRangeTable): ProvingTest[] {\n return [\n {\n id: 'accel_0_100',\n kind: 'measured',\n domains: ['land'],\n unit: 's',\n procedure: {\n maxSeconds: 90,\n target: (subject) => reachable(subject, 100),\n input: () => ({ ...idle, throttle: 1 }),\n sample: (state) => kmh(state),\n finished: (state, _t, memo) => kmh(state) >= memo.target,\n value: (state, time, memo) => (kmh(state) >= memo.target ? round(time, 2) : null),\n },\n range: (subject) => accelerationRange(ranges, subject, reachable(subject, 100)),\n },\n {\n id: 'top_speed',\n kind: 'measured',\n domains: ['land'],\n unit: 'km/h',\n procedure: {\n maxSeconds: 150,\n input: () => ({ ...idle, throttle: 1 }),\n sample: (state) => kmh(state),\n // stops when the speed has grown less than 0.5 km/h in the last 4 seconds\n finished(state, time, memo) {\n const history = (memo.history ??= []) as Array<[number, number]>\n history.push([time, kmh(state)])\n while (history.length > 1 && time - history[0]![0] > 4) history.shift()\n memo.best = Math.max((memo.best as number | undefined) ?? 0, kmh(state))\n return time > 8 && history.length > 1 && kmh(state) - history[0]![1] < 0.5\n },\n value: (_state, _t, memo) => round((memo.best as number | undefined) ?? 0),\n },\n range: (subject) => topSpeedRange(ranges, subject),\n },\n {\n id: 'brake_100_0',\n kind: 'measured',\n domains: ['land'],\n unit: 'm',\n procedure: brakeFrom(100),\n range: (subject) => dryBrakeRange(ranges, subject, reachable(subject, 100)),\n },\n {\n id: 'turn_circle',\n kind: 'measured',\n domains: ['land'],\n unit: 'm',\n procedure: {\n maxSeconds: 30,\n target: () => 12,\n // full lock at a walking pace, the throttle holding 12 km/h; after the circle settles the diameter is twice the speed over the yaw rate\n input: (state, _t, memo) => ({ ...idle, steer: 1, throttle: kmh(state) < memo.target ? 0.5 : 0, brake: kmh(state) > memo.target + 3 ? 0.3 : 0 }),\n sample: (state) => (Math.abs(state.yawRate) > 1e-3 ? (2 * Math.abs(state.u)) / Math.abs(state.yawRate) : 0),\n finished(state, time, memo) {\n if (time < 6) return false\n const d = Math.abs(state.yawRate) > 1e-3 ? (2 * Math.abs(state.u)) / Math.abs(state.yawRate) : Infinity\n const samples = (memo.samples ??= []) as number[]\n samples.push(d)\n return samples.length > 240\n },\n value(_state, _t, memo) {\n const samples = (memo.samples as number[] | undefined) ?? []\n if (!samples.length) return null\n return round(samples.reduce((a, b) => a + b, 0) / samples.length)\n },\n },\n range: (subject) => turnCircleRange(ranges, subject),\n },\n {\n id: 'wet_brake_80_0',\n kind: 'measured',\n domains: ['land'],\n unit: 'm',\n procedure: brakeFrom(80, 'wet_asphalt'),\n range: (subject) => wetBrakeRange(ranges, subject, reachable(subject, 80)),\n },\n {\n id: 'mud_traction',\n kind: 'measured',\n domains: ['land'],\n unit: 'm',\n procedure: {\n surface: 'mud',\n maxSeconds: 10,\n input: () => ({ ...idle, throttle: 1 }),\n sample: (state) => kmh(state),\n finished: () => false,\n value: (state) => round(Math.hypot(state.x, state.z)),\n },\n // a four-wheel-drive vehicle has to get through; a two-wheel-drive one sinks, which is right, so it has no band\n range: (subject) => (subject.body.fourWheelDrive ? { min: ranges.mudFourWheelDrive } : {}),\n },\n // seen by a person in the test room and signed off with a print\n { id: 'cabin', kind: 'visual', domains: ['land', 'water', 'air'], unit: '' },\n { id: 'cameras', kind: 'visual', domains: ['land', 'water', 'air'], unit: '' },\n { id: 'mirrors', kind: 'visual', domains: ['land'], unit: '' },\n // rooms of the next phases: pending until each room reports\n { id: 'terrain', kind: 'room', domains: ['land'], unit: '', available: false },\n { id: 'wind_tunnel', kind: 'room', domains: ['land', 'air'], unit: '', available: false },\n { id: 'crash_test', kind: 'room', domains: ['land'], unit: '', available: false },\n { id: 'pedestrian', kind: 'room', domains: ['land'], unit: '', available: false },\n { id: 'performance', kind: 'room', domains: ['land', 'water', 'air'], unit: '', available: false },\n { id: 'buoyancy', kind: 'room', domains: ['water'], unit: '', available: false },\n { id: 'flight', kind: 'room', domains: ['air'], unit: '', available: false },\n ]\n}\n\nexport interface ProvingTestOptions {\n /** Replaces numbers of the range table (`{ turnCircle: { heavy: [12, 28] } }`). Nested tables are merged by class. */\n ranges?: Partial<RangeTable>\n /** Tests a game adds (or replaces by id). */\n packs?: ReadonlyArray<{ tests?: readonly ProvingTest[] }>\n patch?: Readonly<Record<string, Partial<ProvingTest>>>\n remove?: readonly string[]\n}\n\nexport interface ProvingTestRegistry {\n readonly tests: readonly ProvingTest[]\n get(id: string): ProvingTest | undefined\n /** The tests that apply to a domain, in order. */\n forDomain(domain: ProvingSubject['domain']): ProvingTest[]\n readonly ranges: RangeTable\n}\n\nexport function createProvingTests(options: ProvingTestOptions = {}): ProvingTestRegistry {\n const given = options.ranges ?? {}\n const ranges: RangeTable = {\n ...defaultRangeTable,\n ...given,\n dryBrake: { ...defaultRangeTable.dryBrake, ...given.dryBrake },\n wetBrake: { ...defaultRangeTable.wetBrake, ...given.wetBrake },\n turnCircle: { ...defaultRangeTable.turnCircle, ...given.turnCircle },\n }\n const entries = mergeById(defaultProvingTests(ranges), options.packs?.flatMap((pack) => pack.tests ?? []))\n applyPatches(entries, options.patch)\n removeIds(entries, options.remove)\n const list = (): ProvingTest[] => [...entries.values()]\n return {\n get tests() {\n return list()\n },\n get: (id) => entries.get(id),\n forDomain: (domain) => list().filter((t) => t.domains.includes(domain)),\n ranges,\n }\n}\n","import { runTest } from './run'\nimport type { RunOptions } from './run'\nimport { createProvingTests } from './tests'\nimport type { ProvingTestRegistry } from './tests'\nimport type { ProvingCertificate, ProvingResult, ProvingSubject } from './types'\n\n/** A person's verdict on a visual check (or on a room test run by hand), with the print that shows it. */\nexport interface SignOff {\n vehicle: string\n test: string\n ok: boolean\n by?: string\n evidence?: string\n note?: string\n}\n\nexport interface CertifyOptions extends RunOptions {\n tests?: ProvingTestRegistry\n /** Visual and room checks already signed off. */\n signOffs?: readonly SignOff[]\n /** Results reported by rooms of later phases (terrain, crash test), by test id. */\n reports?: readonly ProvingResult[]\n}\n\n/** approved when every result passed, rejected when any failed, pending otherwise. */\nexport const statusOf = (results: readonly ProvingResult[]): ProvingCertificate['status'] =>\n results.some((r) => r.verdict === 'fail') ? 'rejected' : results.every((r) => r.verdict === 'pass') ? 'approved' : 'pending'\n\n/** Runs every measured test of the subject's domain, takes the sign-offs and the room reports, and gives the certificate. */\nexport function certify(subject: ProvingSubject, options: CertifyOptions = {}): ProvingCertificate {\n const tests = options.tests ?? createProvingTests()\n const results: ProvingResult[] = tests.forDomain(subject.domain).map((test): ProvingResult => {\n const signed = options.signOffs?.find((s) => s.vehicle === subject.id && s.test === test.id)\n const reported = options.reports?.find((r) => r.test === test.id)\n if (reported) return reported\n if (test.kind === 'measured' && test.procedure && subject.domain === 'land') return runTest(test, subject, options)\n if (signed)\n return {\n test: test.id,\n kind: test.kind,\n unit: test.unit,\n range: {},\n value: null,\n verdict: signed.ok ? 'pass' : 'fail',\n ...(signed.by ? { signedBy: signed.by } : {}),\n ...(signed.evidence ? { evidence: signed.evidence } : {}),\n ...(signed.note ? { note: signed.note } : {}),\n }\n const note = test.kind === 'visual' ? 'awaiting sign-off in the test room' : test.kind === 'room' ? 'room not built yet' : 'no runner for this domain yet'\n return { test: test.id, kind: test.kind, unit: test.unit, range: {}, value: null, verdict: 'pending', note }\n })\n return { vehicle: subject.id, domain: subject.domain, category: subject.category, status: statusOf(results), results }\n}\n\n/** Replaces (or adds) one result of a certificate and recomputes its status. */\nexport function withResult(certificate: ProvingCertificate, result: ProvingResult): ProvingCertificate {\n const results = certificate.results.some((r) => r.test === result.test) ? certificate.results.map((r) => (r.test === result.test ? result : r)) : [...certificate.results, result]\n return { ...certificate, results, status: statusOf(results) }\n}\n\nexport interface GateOptions {\n /** Lets pending vehicles in too (a game in development). Rejected vehicles never get in unless listed in `allow`. */\n allowPending?: boolean\n /** Ids a game lets in whatever their certificate says. */\n allow?: readonly string[]\n /** Ids a game keeps out whatever their certificate says. */\n deny?: readonly string[]\n}\n\n/** The ids, of `ids`, that a game lets in: approved ones (and pending ones with `allowPending`), with the game's own allow and deny lists. An id without a certificate counts as pending. */\nexport function gateVehicles(ids: readonly string[], certificates: readonly ProvingCertificate[], options: GateOptions = {}): string[] {\n const byId = new Map(certificates.map((c) => [c.vehicle, c]))\n return ids.filter((id) => {\n if (options.deny?.includes(id)) return false\n if (options.allow?.includes(id)) return true\n const status = byId.get(id)?.status ?? 'pending'\n return status === 'approved' || (status === 'pending' && !!options.allowPending)\n })\n}\n","import type { DesignStats } from '@adatechnology/game-vehicles-driving'\n\nimport type { ProvingDomain, ProvingSubject } from './types'\n\n/** Kilograms per cubic metre of the bounding box, by group: only used when the card has no mass. */\nexport const DEFAULT_DENSITY: Readonly<Record<string, number>> = { motorcycles: 90, cars: 88, suvs: 90, pickups: 95, vans: 80, heavy: 120, agricultural: 150, military: 260, water: 60, air: 40 }\n\n/** What a catalogue knows of a vehicle: its design ratings, its measured size and its group (a content pack fills it; see `fleetProvingSubject` of game-vehicles-fleet). */\nexport interface VehicleCardData {\n stats: DesignStats\n dims: { length: number; width: number; height: number }\n /** Group of the catalogue (`cars`, `heavy`, `water`, `air`…): the class the ranges are read for, and the domain (water and air groups are not land). */\n group: string\n /** Kilograms. Estimated from the size and the group when absent. */\n mass?: number\n /** Metres between the axles and between the wheels, measured on the built vehicle. Estimated from the size when absent. */\n wheelbase?: number\n track?: number\n fourWheelDrive?: boolean\n /** Groups whose vehicles float or fly (default `water` and `air`). */\n domains?: Readonly<Record<string, ProvingDomain>>\n}\n\nconst DEFAULT_DOMAINS: Readonly<Record<string, ProvingDomain>> = { water: 'water', air: 'air' }\n\n/** A proving subject from what a catalogue knows of a vehicle. */\nexport function subjectFromCard(id: string, card: VehicleCardData): ProvingSubject {\n const { dims, group } = card\n const mass = card.mass ?? Math.round((DEFAULT_DENSITY[group] ?? 90) * dims.length * dims.width * dims.height)\n return {\n id,\n domain: (card.domains ?? DEFAULT_DOMAINS)[group] ?? 'land',\n category: group,\n stats: { acceleration: card.stats.acceleration, handling: card.stats.handling, maxSpeedKmh: card.stats.maxSpeedKmh },\n body: {\n mass,\n wheelbase: card.wheelbase ?? Math.round(dims.length * 0.6 * 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OAAO,SAAS,EAAE,EAAG,QAAO;AACxC,UAAM,SAAS,KAAK,IAAI,EAAE,GAAG,UAAU;AACvC,WAAO,WAAW,cAAe,WAAW,aAAa,CAAC,CAAC,QAAQ;AAAA,EACrE,CAAC;AACH;;;ACzEO,IAAM,kBAAoD,EAAE,aAAa,IAAI,MAAM,IAAI,MAAM,IAAI,SAAS,IAAI,MAAM,IAAI,OAAO,KAAK,cAAc,KAAK,UAAU,KAAK,OAAO,IAAI,KAAK,GAAG;AAkBhM,IAAM,kBAA2D,EAAE,OAAO,SAAS,KAAK,MAAM;AAGvF,SAAS,gBAAgB,IAAY,MAAuC;AACjF,QAAM,EAAE,MAAM,MAAM,IAAI;AACxB,QAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,gBAAgB,KAAK,KAAK,MAAM,KAAK,SAAS,KAAK,QAAQ,KAAK,MAAM;AAC5G,SAAO;AAAA,IACL;AAAA,IACA,SAAS,KAAK,WAAW,iBAAiB,KAAK,KAAK;AAAA,IACpD,UAAU;AAAA,IACV,OAAO,EAAE,cAAc,KAAK,MAAM,cAAc,UAAU,KAAK,MAAM,UAAU,aAAa,KAAK,MAAM,YAAY;AAAA,IACnH,MAAM;AAAA,MACJ;AAAA,MACA,WAAW,KAAK,aAAa,KAAK,MAAM,KAAK,SAAS,MAAM,GAAG,IAAI;AAAA,MACnE,OAAO,KAAK,SAAS,KAAK,MAAM,KAAK,QAAQ,OAAO,GAAG,IAAI;AAAA,MAC3D,gBAAgB,CAAC,CAAC,KAAK;AAAA,IACzB;AAAA,EACF;AACF;","names":["kmh"]}
|
|
1
|
+
{"version":3,"sources":["../src/run.ts","../src/ranges.ts","../src/tests.ts","../src/certificate.ts","../src/fleet.ts","../src/physics-run.ts"],"sourcesContent":["import { createScheduler } from '@adatechnology/game-runtime'\nimport type { Scheduler } from '@adatechnology/game-runtime'\nimport { createSemiSimDriver, createSurfaces, semiSpecFromStats } from '@adatechnology/game-vehicles-driving'\nimport type { SemiDriver, SemiInput, SemiSimSpec, SemiState, SurfaceRegistry } from '@adatechnology/game-vehicles-driving'\n\nimport { inRange } from './ranges'\nimport type { ProvingMemo, ProvingResult, ProvingSubject, ProvingTest } from './types'\n\n/** The semi-simulation spec the runner drives a subject with: from the card's ratings and the body, with the subject's own overrides. */\nexport const subjectSpec = (subject: ProvingSubject): SemiSimSpec => ({ ...semiSpecFromStats(subject.stats, subject.body), ...subject.spec })\n\n/** Physics steps of one scheduler tick (1/60 s): the proving run steps its driver at twice the tick, as the room's physics loop does. */\nexport const STEPS_PER_TICK = 2\n\n/**\n * One measured test in progress. It owns no clock: a host registers `stepFixed(STEPS_PER_TICK)` in its scheduler's `fixedSimulate` and draws `driver.state`;\n * standalone (tests, CLI) the caller drives `stepFixed` or the thin `advance(seconds)`. `runTest` steps it to the end in one go.\n */\nexport interface ProvingRun {\n readonly test: ProvingTest\n readonly subject: ProvingSubject\n readonly driver: SemiDriver\n readonly surface: string\n readonly time: number\n readonly done: boolean\n /** [seconds, sample] of the run so far. */\n readonly trace: ReadonlyArray<[number, number]>\n readonly memo: ProvingMemo\n /** What the procedure asked of the controls on the last step (all zero before the first): a host plays the brakes and the engine from it. */\n readonly input: SemiInput\n /** Seconds of one physics step (`RunOptions.fixedStep`, default 1/120). */\n readonly fixedStep: number\n /** Runs `steps` physics steps now (stops at the end of the run); no accumulator, no time scale: the caller's scheduler decides how many. */\n stepFixed(steps: number): void\n /** Standalone helper: feeds `seconds` to a private `game-runtime` scheduler (exact, no render) whose fixed tick runs `STEPS_PER_TICK` steps; the remainder waits for the next call. */\n advance(seconds: number): void\n /** The result so far; pending while the run has not ended. */\n result(): ProvingResult\n}\n\nexport interface RunOptions {\n surfaces?: SurfaceRegistry\n /** Seconds between two trace samples (default 0.1). */\n sampleEvery?: number\n /** Fixed step of the simulation (default 1/120 s): the seconds one `stepFixed` step integrates. */\n fixedStep?: number\n}\n\n/** What a measured test's result is made from: shared by the semi-simulation run and the physics-engine run. */\nexport interface ResultInput {\n readonly test: ProvingTest\n readonly subject: ProvingSubject\n readonly memo: ProvingMemo\n readonly trace: ReadonlyArray<[number, number]>\n readonly done: boolean\n readonly state: SemiState\n readonly time: number\n}\n\nexport function resultOf({ test, subject, memo, trace, done, state, time }: ResultInput): ProvingResult {\n const procedure = test.procedure\n if (!procedure) throw new Error(`resultOf: ${test.id} is not a measured test`)\n const range = test.range?.(subject) ?? {}\n const base = { test: test.id, kind: test.kind, unit: test.unit, range, trace: [...trace] }\n if (!done) return { ...base, verdict: 'pending', value: null, note: 'running' }\n const value = procedure.value(state, time, memo)\n const lowered = memo.target > 0 && /_100|_80/.test(test.id) && memo.target < (test.id.includes('80') ? 80 : 100)\n const note = lowered ? `target ${memo.target} km/h` : undefined\n if (value == null) return { ...base, verdict: 'fail', value: null, note: `did not finish in ${procedure.maxSeconds} s` }\n return { ...base, verdict: inRange(value, range) ? 'pass' : 'fail', value, ...(note ? { note } : {}) }\n}\n\nexport function startRun(test: ProvingTest, subject: ProvingSubject, options: RunOptions = {}): ProvingRun {\n const procedure = test.procedure\n if (test.kind !== 'measured' || !procedure) throw new Error(`startRun: ${test.id} is not a measured test`)\n const surfaces = options.surfaces ?? createSurfaces()\n const driver = createSemiSimDriver(subjectSpec(subject), { surfaces })\n driver.place(0, 0, 0)\n const surface = procedure.surface ?? 'dry_asphalt'\n const world = { ground: () => ({ surface }) }\n const memo: ProvingMemo = { target: procedure.target?.(subject) ?? 0, subject }\n const trace: Array<[number, number]> = []\n const sampleEvery = options.sampleEvery ?? 0.1\n const fixed = options.fixedStep ?? 1 / 120\n let time = 0\n let done = false\n let nextSample = 0\n let scheduler: Scheduler | undefined\n let last: SemiInput = { throttle: 0, brake: 0, steer: 0, handbrake: false }\n const tick = (h: number): void => {\n const input = procedure.input(driver.state, time, memo)\n last = input\n driver.step(input, h, world)\n time += h\n if (time >= nextSample) {\n trace.push([Math.round(time * 1000) / 1000, procedure.sample(driver.state, time, memo)])\n nextSample += sampleEvery\n }\n if (procedure.finished(driver.state, time, memo) || time >= procedure.maxSeconds) done = true\n }\n return {\n test,\n subject,\n driver,\n surface,\n memo,\n get time() {\n return time\n },\n get done() {\n return done\n },\n get trace() {\n return trace\n },\n get input() {\n return last\n },\n fixedStep: fixed,\n stepFixed(steps) {\n for (let i = 0; i < steps && !done; i++) tick(fixed)\n },\n advance(seconds) {\n if (!scheduler) {\n scheduler = createScheduler({ fixedDt: fixed * STEPS_PER_TICK })\n scheduler.add(() => this.stepFixed(STEPS_PER_TICK), { phase: 'fixedSimulate', id: 'proving.run' })\n }\n scheduler.frame(seconds, { exact: true, render: false })\n },\n result() {\n return resultOf({ test, subject, memo, trace, done, state: driver.state, time })\n },\n }\n}\n\n/** Runs a measured test to its end and returns the result. */\nexport function runTest(test: ProvingTest, subject: ProvingSubject, options: RunOptions = {}): ProvingResult {\n const run = startRun(test, subject, options)\n while (!run.done) run.stepFixed(STEPS_PER_TICK)\n return run.result()\n}\n","import type { ProvingRange, ProvingSubject } from './types'\n\nconst lerpTable = (table: ReadonlyArray<readonly [number, number]>, x: number): number => {\n if (x <= table[0]![0]) return table[0]![1]\n for (let i = 1; i < table.length; i++) {\n const [x1, y1] = table[i]!\n const [x0, y0] = table[i - 1]!\n if (x <= x1) return y0 + ((y1 - y0) * (x - x0)) / (x1 - x0)\n }\n return table[table.length - 1]![1]\n}\n\n/**\n * The numbers the ranges come from. Real-world bands for road vehicles (a family car stops from 100 km/h in 35-45 m, turns in 10-11 m, a hatch reaches 100 km/h in about 10 s); every one can\n * be replaced per class through `createProvingTests({ ranges })`.\n */\nexport interface RangeTable {\n /** 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). */\n accelerationSeconds: ReadonlyArray<readonly [number, number]>\n /** 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. */\n accelerationByClass: Readonly<Record<string, ReadonlyArray<readonly [number, number]>>>\n /** Accepted spread around the expected 0-100 time (0.35 = ±35 %). */\n accelerationSpread: number\n /** Accepted spread around the card's top speed. */\n topSpeedSpread: number\n /** Braking deceleration on dry asphalt, m/s², by class. */\n dryBrake: Readonly<Record<string, readonly [number, number]>>\n /** Braking deceleration on wet asphalt, m/s², by class. */\n wetBrake: Readonly<Record<string, readonly [number, number]>>\n /** Turning circle diameter, metres, by class. */\n turnCircle: Readonly<Record<string, readonly [number, number]>>\n /** Metres a four-wheel-drive vehicle has to cover in the mud test. */\n mudFourWheelDrive: number\n}\n\n/**\n * Real 0-100 km/h times that anchor each class: rating 1 at the slowest, rating 10 at the fastest, in between linearly.\n * 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);\n * 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).\n * 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);\n * fastest 6.7 s, Toyota Land Cruiser 300 (Toyota's figure, via https://www.motor1.com/news/515260/2022-toyota-land-cruiser-acceleration-test/).\n * 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).\n * 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`.\n */\nexport const defaultRangeTable: RangeTable = {\n accelerationByClass: {\n cars: [[1, 15.5], [10, 4.8]],\n suvs: [[1, 12.7], [10, 6.7]],\n motorcycles: [[1, 19.5], [10, 4.35]],\n },\n accelerationSeconds: [\n [1, 34],\n [3, 21],\n [5, 14],\n [7, 10],\n [9, 6],\n [10, 4.2],\n ],\n accelerationSpread: 0.35,\n topSpeedSpread: 0.1,\n dryBrake: { default: [6.5, 11], heavy: [4.5, 8.5], agricultural: [3.5, 7.5], military: [4.5, 9] },\n wetBrake: { default: [3.5, 8.5], heavy: [2.5, 7], agricultural: [2, 6], military: [2.5, 7] },\n turnCircle: { default: [7, 13.5], motorcycles: [3, 9], suvs: [9, 15], pickups: [9, 16], vans: [9, 15], heavy: [10, 26], military: [9, 24], agricultural: [6, 16] },\n mudFourWheelDrive: 10,\n}\n\nconst byClass = <T>(table: Readonly<Record<string, T>>, category: string): T => (table[category] ?? table.default) as T\n\n/** Expected 0-100 (or 0-`target`) seconds for a subject. Below 100 km/h the time scales linearly with the target speed. */\nexport const expectedAcceleration = (table: RangeTable, subject: ProvingSubject, target: number): number => {\n const base = lerpTable(table.accelerationByClass[subject.category] ?? table.accelerationSeconds, subject.stats.acceleration)\n return base * (target / 100)\n}\n\nexport const accelerationRange = (table: RangeTable, subject: ProvingSubject, target: number): ProvingRange => {\n const t = expectedAcceleration(table, subject, target)\n return { min: round(t * (1 - table.accelerationSpread)), max: round(t * (1 + table.accelerationSpread)) }\n}\n\nexport const topSpeedRange = (table: RangeTable, subject: ProvingSubject): ProvingRange => ({\n min: round(subject.stats.maxSpeedKmh * (1 - table.topSpeedSpread)),\n max: round(subject.stats.maxSpeedKmh * (1 + table.topSpeedSpread)),\n})\n\n/** Stopping distance band from `kmh` for the class's deceleration band. */\nexport const brakeRange = (decel: readonly [number, number], kmh: number): ProvingRange => {\n const v = kmh / 3.6\n return { min: round((v * v) / (2 * decel[1])), max: round((v * v) / (2 * decel[0])) }\n}\n\nexport const dryBrakeRange = (table: RangeTable, subject: ProvingSubject, kmh: number): ProvingRange => brakeRange(byClass(table.dryBrake, subject.category), kmh)\nexport const wetBrakeRange = (table: RangeTable, subject: ProvingSubject, kmh: number): ProvingRange => brakeRange(byClass(table.wetBrake, subject.category), kmh)\nexport const turnCircleRange = (table: RangeTable, subject: ProvingSubject): ProvingRange => {\n const [min, max] = byClass(table.turnCircle, subject.category)\n return { min, max }\n}\n\nexport const inRange = (value: number, range: ProvingRange): boolean => (range.min == null || value >= range.min) && (range.max == null || value <= range.max)\n\nexport const round = (x: number, digits = 1): number => {\n const k = 10 ** digits\n return Math.round(x * k) / k\n}\n","import { applyPatches, mergeById, removeIds } from '@adatechnology/game-contracts'\nimport type { SemiInput, SemiState } from '@adatechnology/game-vehicles-driving'\n\nimport { accelerationRange, defaultRangeTable, dryBrakeRange, round, topSpeedRange, turnCircleRange, wetBrakeRange } from './ranges'\nimport type { RangeTable } from './ranges'\nimport type { ProvingMemo, ProvingProcedure, ProvingSubject, ProvingTest } from './types'\n\nconst KMH = 3.6\nconst idle: SemiInput = { throttle: 0, brake: 0, steer: 0, handbrake: false }\nconst kmh = (s: SemiState): number => Math.abs(s.u) * KMH\nconst travelled = (s: SemiState, memo: ProvingMemo, key: string): number => Math.hypot(s.x - (memo[`${key}X`] as number), s.z - (memo[`${key}Z`] as number))\n\n/** Speed a run aims for: `wanted`, or 80 % of the vehicle's top speed when it cannot reach it (a tractor, a bicycle). */\nconst reachable = (subject: ProvingSubject, wanted: number): number => Math.min(wanted, Math.round(subject.stats.maxSpeedKmh * 0.8))\n\n/** Accelerates to the target, then brakes flat out in a straight line; the value is the distance from the first metre of braking to the stop. */\nconst brakeFrom = (wanted: number, surface?: string): ProvingProcedure => ({\n ...(surface ? { surface } : {}),\n maxSeconds: 90,\n target: (subject) => reachable(subject, wanted),\n input(state, _time, memo) {\n if (!memo.braking && kmh(state) >= memo.target) {\n memo.braking = true\n memo.brakeX = state.x\n memo.brakeZ = state.z\n }\n return memo.braking ? { ...idle, brake: 1 } : { ...idle, throttle: 1 }\n },\n sample: (state) => kmh(state),\n finished: (state, _t, memo) => !!memo.braking && kmh(state) < 0.3,\n value: (state, _t, memo) => (memo.braking ? round(travelled(state, memo, 'brake')) : null),\n})\n\n/** The tests of the kit. Every number comes from the range table; a game replaces the table, patches a test or adds its own. */\nexport function defaultProvingTests(ranges: RangeTable = defaultRangeTable): ProvingTest[] {\n return [\n {\n id: 'accel_0_100',\n kind: 'measured',\n domains: ['land'],\n unit: 's',\n procedure: {\n maxSeconds: 90,\n target: (subject) => reachable(subject, 100),\n input: () => ({ ...idle, throttle: 1 }),\n sample: (state) => kmh(state),\n finished: (state, _t, memo) => kmh(state) >= memo.target,\n value: (state, time, memo) => (kmh(state) >= memo.target ? round(time, 2) : null),\n },\n range: (subject) => accelerationRange(ranges, subject, reachable(subject, 100)),\n },\n {\n id: 'top_speed',\n kind: 'measured',\n domains: ['land'],\n unit: 'km/h',\n procedure: {\n maxSeconds: 150,\n input: () => ({ ...idle, throttle: 1 }),\n sample: (state) => kmh(state),\n // stops when the speed has grown less than 0.5 km/h in the last 4 seconds\n finished(state, time, memo) {\n const history = (memo.history ??= []) as Array<[number, number]>\n history.push([time, kmh(state)])\n while (history.length > 1 && time - history[0]![0] > 4) history.shift()\n memo.best = Math.max((memo.best as number | undefined) ?? 0, kmh(state))\n return time > 8 && history.length > 1 && kmh(state) - history[0]![1] < 0.5\n },\n value: (_state, _t, memo) => round((memo.best as number | undefined) ?? 0),\n },\n range: (subject) => topSpeedRange(ranges, subject),\n },\n {\n id: 'brake_100_0',\n kind: 'measured',\n domains: ['land'],\n unit: 'm',\n procedure: brakeFrom(100),\n range: (subject) => dryBrakeRange(ranges, subject, reachable(subject, 100)),\n },\n {\n id: 'turn_circle',\n kind: 'measured',\n domains: ['land'],\n unit: 'm',\n procedure: {\n maxSeconds: 30,\n target: () => 12,\n // full lock at a walking pace, the throttle holding 12 km/h; after the circle settles the diameter is twice the speed over the yaw rate\n input: (state, _t, memo) => ({ ...idle, steer: 1, throttle: kmh(state) < memo.target ? 0.5 : 0, brake: kmh(state) > memo.target + 3 ? 0.3 : 0 }),\n sample: (state) => (Math.abs(state.yawRate) > 1e-3 ? (2 * Math.abs(state.u)) / Math.abs(state.yawRate) : 0),\n finished(state, time, memo) {\n if (time < 6) return false\n const d = Math.abs(state.yawRate) > 1e-3 ? (2 * Math.abs(state.u)) / Math.abs(state.yawRate) : Infinity\n const samples = (memo.samples ??= []) as number[]\n samples.push(d)\n return samples.length > 240\n },\n value(_state, _t, memo) {\n const samples = (memo.samples as number[] | undefined) ?? []\n if (!samples.length) return null\n return round(samples.reduce((a, b) => a + b, 0) / samples.length)\n },\n },\n range: (subject) => turnCircleRange(ranges, subject),\n },\n {\n id: 'wet_brake_80_0',\n kind: 'measured',\n domains: ['land'],\n unit: 'm',\n procedure: brakeFrom(80, 'wet_asphalt'),\n range: (subject) => wetBrakeRange(ranges, subject, reachable(subject, 80)),\n },\n {\n id: 'mud_traction',\n kind: 'measured',\n domains: ['land'],\n unit: 'm',\n procedure: {\n surface: 'mud',\n maxSeconds: 10,\n input: () => ({ ...idle, throttle: 1 }),\n sample: (state) => kmh(state),\n finished: () => false,\n value: (state) => round(Math.hypot(state.x, state.z)),\n },\n // a four-wheel-drive vehicle has to get through; a two-wheel-drive one sinks, which is right, so it has no band\n range: (subject) => (subject.body.fourWheelDrive ? { min: ranges.mudFourWheelDrive } : {}),\n },\n // seen by a person in the test room and signed off with a print\n { id: 'cabin', kind: 'visual', domains: ['land', 'water', 'air'], unit: '' },\n { id: 'cameras', kind: 'visual', domains: ['land', 'water', 'air'], unit: '' },\n { id: 'mirrors', kind: 'visual', domains: ['land'], unit: '' },\n // rooms of the next phases: pending until each room reports\n { id: 'terrain', kind: 'room', domains: ['land'], unit: '', available: false },\n { id: 'wind_tunnel', kind: 'room', domains: ['land', 'air'], unit: '', available: false },\n { id: 'crash_test', kind: 'room', domains: ['land'], unit: '', available: false },\n { id: 'pedestrian', kind: 'room', domains: ['land'], unit: '', available: false },\n { id: 'performance', kind: 'room', domains: ['land', 'water', 'air'], unit: '', available: false },\n { id: 'buoyancy', kind: 'room', domains: ['water'], unit: '', available: false },\n { id: 'flight', kind: 'room', domains: ['air'], unit: '', available: false },\n ]\n}\n\nexport interface ProvingTestOptions {\n /** Replaces numbers of the range table (`{ turnCircle: { heavy: [12, 28] } }`). Nested tables are merged by class. */\n ranges?: Partial<RangeTable>\n /** Tests a game adds (or replaces by id). */\n packs?: ReadonlyArray<{ tests?: readonly ProvingTest[] }>\n patch?: Readonly<Record<string, Partial<ProvingTest>>>\n remove?: readonly string[]\n}\n\nexport interface ProvingTestRegistry {\n readonly tests: readonly ProvingTest[]\n get(id: string): ProvingTest | undefined\n /** The tests that apply to a domain, in order. */\n forDomain(domain: ProvingSubject['domain']): ProvingTest[]\n readonly ranges: RangeTable\n}\n\nexport function createProvingTests(options: ProvingTestOptions = {}): ProvingTestRegistry {\n const given = options.ranges ?? {}\n const ranges: RangeTable = {\n ...defaultRangeTable,\n ...given,\n dryBrake: { ...defaultRangeTable.dryBrake, ...given.dryBrake },\n wetBrake: { ...defaultRangeTable.wetBrake, ...given.wetBrake },\n turnCircle: { ...defaultRangeTable.turnCircle, ...given.turnCircle },\n }\n const entries = mergeById(defaultProvingTests(ranges), options.packs?.flatMap((pack) => pack.tests ?? []))\n applyPatches(entries, options.patch)\n removeIds(entries, options.remove)\n const list = (): ProvingTest[] => [...entries.values()]\n return {\n get tests() {\n return list()\n },\n get: (id) => entries.get(id),\n forDomain: (domain) => list().filter((t) => t.domains.includes(domain)),\n ranges,\n }\n}\n","import { runTest } from './run'\nimport type { RunOptions } from './run'\nimport { createProvingTests } from './tests'\nimport type { ProvingTestRegistry } from './tests'\nimport type { ProvingCertificate, ProvingResult, ProvingSubject } from './types'\n\n/** A person's verdict on a visual check (or on a room test run by hand), with the print that shows it. */\nexport interface SignOff {\n vehicle: string\n test: string\n ok: boolean\n by?: string\n evidence?: string\n note?: string\n}\n\nexport interface CertifyOptions extends RunOptions {\n tests?: ProvingTestRegistry\n /** Visual and room checks already signed off. */\n signOffs?: readonly SignOff[]\n /** Results reported by rooms of later phases (terrain, crash test), by test id. */\n reports?: readonly ProvingResult[]\n}\n\n/** approved when every result passed, rejected when any failed, pending otherwise. */\nexport const statusOf = (results: readonly ProvingResult[]): ProvingCertificate['status'] =>\n results.some((r) => r.verdict === 'fail') ? 'rejected' : results.every((r) => r.verdict === 'pass') ? 'approved' : 'pending'\n\n/** Runs every measured test of the subject's domain, takes the sign-offs and the room reports, and gives the certificate. */\nexport function certify(subject: ProvingSubject, options: CertifyOptions = {}): ProvingCertificate {\n const tests = options.tests ?? createProvingTests()\n const results: ProvingResult[] = tests.forDomain(subject.domain).map((test): ProvingResult => {\n const signed = options.signOffs?.find((s) => s.vehicle === subject.id && s.test === test.id)\n const reported = options.reports?.find((r) => r.test === test.id)\n if (reported) return reported\n if (test.kind === 'measured' && test.procedure && subject.domain === 'land') return runTest(test, subject, options)\n if (signed)\n return {\n test: test.id,\n kind: test.kind,\n unit: test.unit,\n range: {},\n value: null,\n verdict: signed.ok ? 'pass' : 'fail',\n ...(signed.by ? { signedBy: signed.by } : {}),\n ...(signed.evidence ? { evidence: signed.evidence } : {}),\n ...(signed.note ? { note: signed.note } : {}),\n }\n const note = test.kind === 'visual' ? 'awaiting sign-off in the test room' : test.kind === 'room' ? 'room not built yet' : 'no runner for this domain yet'\n return { test: test.id, kind: test.kind, unit: test.unit, range: {}, value: null, verdict: 'pending', note }\n })\n return { vehicle: subject.id, domain: subject.domain, category: subject.category, status: statusOf(results), results }\n}\n\n/** Replaces (or adds) one result of a certificate and recomputes its status. */\nexport function withResult(certificate: ProvingCertificate, result: ProvingResult): ProvingCertificate {\n const results = certificate.results.some((r) => r.test === result.test) ? certificate.results.map((r) => (r.test === result.test ? result : r)) : [...certificate.results, result]\n return { ...certificate, results, status: statusOf(results) }\n}\n\nexport interface GateOptions {\n /** Lets pending vehicles in too (a game in development). Rejected vehicles never get in unless listed in `allow`. */\n allowPending?: boolean\n /** Ids a game lets in whatever their certificate says. */\n allow?: readonly string[]\n /** Ids a game keeps out whatever their certificate says. */\n deny?: readonly string[]\n}\n\n/** The ids, of `ids`, that a game lets in: approved ones (and pending ones with `allowPending`), with the game's own allow and deny lists. An id without a certificate counts as pending. */\nexport function gateVehicles(ids: readonly string[], certificates: readonly ProvingCertificate[], options: GateOptions = {}): string[] {\n const byId = new Map(certificates.map((c) => [c.vehicle, c]))\n return ids.filter((id) => {\n if (options.deny?.includes(id)) return false\n if (options.allow?.includes(id)) return true\n const status = byId.get(id)?.status ?? 'pending'\n return status === 'approved' || (status === 'pending' && !!options.allowPending)\n })\n}\n","import type { DesignStats } from '@adatechnology/game-vehicles-driving'\n\nimport type { ProvingDomain, ProvingSubject } from './types'\n\n/** Kilograms per cubic metre of the bounding box, by group: only used when the card has no mass. */\nexport const DEFAULT_DENSITY: Readonly<Record<string, number>> = { motorcycles: 90, cars: 88, suvs: 90, pickups: 95, vans: 80, heavy: 120, agricultural: 150, military: 260, water: 60, air: 40 }\n\n/** What a catalogue knows of a vehicle: its design ratings, its measured size and its group (a content pack fills it; see `fleetProvingSubject` of game-vehicles-fleet). */\nexport interface VehicleCardData {\n stats: DesignStats\n dims: { length: number; width: number; height: number }\n /** Group of the catalogue (`cars`, `heavy`, `water`, `air`…): the class the ranges are read for, and the domain (water and air groups are not land). */\n group: string\n /** Kilograms. Estimated from the size and the group when absent. */\n mass?: number\n /** Metres between the axles and between the wheels, measured on the built vehicle. Estimated from the size when absent. */\n wheelbase?: number\n track?: number\n fourWheelDrive?: boolean\n /** Groups whose vehicles float or fly (default `water` and `air`). */\n domains?: Readonly<Record<string, ProvingDomain>>\n}\n\nconst DEFAULT_DOMAINS: Readonly<Record<string, ProvingDomain>> = { water: 'water', air: 'air' }\n\n/** A proving subject from what a catalogue knows of a vehicle. */\nexport function subjectFromCard(id: string, card: VehicleCardData): ProvingSubject {\n const { dims, group } = card\n const mass = card.mass ?? Math.round((DEFAULT_DENSITY[group] ?? 90) * dims.length * dims.width * dims.height)\n return {\n id,\n domain: (card.domains ?? DEFAULT_DOMAINS)[group] ?? 'land',\n category: group,\n stats: { acceleration: card.stats.acceleration, handling: card.stats.handling, maxSpeedKmh: card.stats.maxSpeedKmh },\n body: {\n mass,\n wheelbase: card.wheelbase ?? Math.round(dims.length * 0.6 * 100) / 100,\n track: card.track ?? Math.round(dims.width * 0.82 * 100) / 100,\n fourWheelDrive: !!card.fourWheelDrive,\n },\n }\n}\n","import type { BodyId, PhysicsWorld, VehicleId } from '@adatechnology/game-physics'\nimport { createPhysicsInputMapper, createSurfaces, resistanceImpulse, surfaceGrip, vehicleDescFromSemi } from '@adatechnology/game-vehicles-driving'\nimport type { SemiInput, SemiSimSpec, SemiState, Surface, SurfaceRegistry } from '@adatechnology/game-vehicles-driving'\n\nimport { resultOf, subjectSpec } from './run'\nimport type { ProvingMemo, ProvingResult, ProvingSubject, ProvingTest } from './types'\n\n/** The ground is a slab this big (half the side, m): the longest run (top speed, 150 s) covers about 8 km. */\nconst GROUND_HALF = 20000\n/** Chassis box around the spec's wheels: this much beyond the outermost wheels in x, and half the height of the box above and below the centre of mass. */\nconst CHASSIS_MARGIN_SIDE = 0.1\nconst CHASSIS_MARGIN_END = 0.6\nconst CHASSIS_HALF_HEIGHT = 0.35\n\nexport interface PhysicsRunOptions {\n /** 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. */\n readonly createWorld: () => PhysicsWorld\n readonly surfaces?: SurfaceRegistry\n /** Seconds between two trace samples (default 0.1). */\n readonly sampleEvery?: number\n /** Fixed step of the simulation (default 1/120 s): the world's own. */\n readonly fixedStep?: number\n}\n\n/** A measured test in progress on the physics engine: the same procedures as `ProvingRun`, driven through the vehicle the engine simulates. */\nexport interface PhysicsProvingRun {\n readonly test: ProvingTest\n readonly subject: ProvingSubject\n readonly surface: string\n readonly time: number\n readonly done: boolean\n readonly trace: ReadonlyArray<[number, number]>\n readonly memo: ProvingMemo\n readonly input: SemiInput\n readonly fixedStep: number\n /**\n * 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`\n * the heading, `height`, `pitch` and `roll` from the pose. The engine and gearbox have no reading in the contract: `rpm` and `gear` stay 0.\n */\n readonly state: SemiState\n stepFixed(steps: number): void\n result(): ProvingResult\n /** Lets go of the world; `runTestOnPhysics` calls it. */\n dispose(): void\n}\n\nconst chassisOf = (spec: SemiSimSpec): { half: readonly [number, number, number] } => {\n const xs = spec.wheels.map((wheel) => wheel.x)\n const zs = spec.wheels.map((wheel) => Math.abs(wheel.z))\n return { half: [Math.max(...zs) + CHASSIS_MARGIN_SIDE, CHASSIS_HALF_HEIGHT, (Math.max(...xs) - Math.min(...xs)) / 2 + CHASSIS_MARGIN_END] }\n}\n\nconst emptyState = (spec: SemiSimSpec): SemiState => ({\n x: 0, z: 0, yaw: 0, u: 0, w: 0, yawRate: 0, height: spec.centreHeight, heightRate: 0, pitch: 0, pitchRate: 0, roll: 0, rollRate: 0, rpm: 0, gear: 0,\n engineOn: true, bogged: false, fuel: spec.tank.capacity, loads: spec.wheels.map(() => 0), slip: spec.wheels.map(() => 0), steerAngle: 0,\n})\n\n/** Puts the ground of the run's surface in the world: a slab whose friction is the surface's grip (the wheels' own grip curves multiply it). */\nconst makeGround = (world: PhysicsWorld, grip: number): BodyId =>\n world.createBody({\n shape: { kind: 'box', half: [GROUND_HALF, 0.5, GROUND_HALF] }, motion: 'static', position: [0, -0.5, 0], user: -1,\n material: { frictionStatic: grip, frictionDynamic: grip, restitution: 0 },\n })\n\nexport function startPhysicsRun(test: ProvingTest, subject: ProvingSubject, options: PhysicsRunOptions): PhysicsProvingRun {\n const procedure = test.procedure\n if (test.kind !== 'measured' || !procedure) throw new Error(`startPhysicsRun: ${test.id} is not a measured test`)\n const spec = subjectSpec(subject)\n const surfaces = options.surfaces ?? createSurfaces()\n const surfaceId = procedure.surface ?? 'dry_asphalt'\n const surface: Surface = surfaces.get(surfaceId)\n const world = options.createWorld()\n const ground = makeGround(world, surface.grip)\n const half = chassisOf(spec).half\n const desc = vehicleDescFromSemi(spec, { chassis: { shape: { kind: 'box', half }, position: [0, spec.centreHeight + 0.05, 0], user: 1 } })\n const vehicle: VehicleId = world.createVehicle(desc)\n const body = world.vehicleBody(vehicle)\n const mapper = createPhysicsInputMapper()\n const memo: ProvingMemo = { target: procedure.target?.(subject) ?? 0, subject }\n const trace: Array<[number, number]> = []\n const state = emptyState(spec)\n const pose = new Float64Array(7)\n const velocity = new Float64Array(6)\n const fixed = options.fixedStep ?? 1 / 120\n const sampleEvery = options.sampleEvery ?? 0.1\n let time = 0\n let nextSample = 0\n let done = false\n let last: SemiInput = { throttle: 0, brake: 0, steer: 0, handbrake: false }\n let groundGrip = surface.grip\n\n const readState = (): void => {\n world.readPose(body, pose, 0)\n world.readVelocity(body, velocity, 0)\n const [qx, qy, qz, qw] = [pose[3]!, pose[4]!, pose[5]!, pose[6]!]\n // the chassis' front is its local z: the speed along it, and the heading of that axis\n const forward: readonly [number, number, number] = [2 * (qx * qz + qw * qy), 2 * (qy * qz - qw * qx), 1 - 2 * (qx * qx + qy * qy)]\n state.u = velocity[0]! * forward[0] + velocity[1]! * forward[1] + velocity[2]! * forward[2]\n state.w = 0\n state.x = pose[2]!\n state.z = pose[0]!\n state.yaw = Math.atan2(forward[0], forward[2])\n state.yawRate = velocity[4]!\n state.height = pose[1]!\n state.pitch = Math.asin(Math.max(-1, Math.min(1, forward[1])))\n // the chassis' left (local x) pointing up is the right side down\n state.roll = Math.asin(Math.max(-1, Math.min(1, 2 * (qx * qy + qw * qz))))\n }\n\n const tick = (h: number): void => {\n const input = procedure.input(state, time, memo)\n last = input\n // aquaplaning: the surface's grip falls with the speed\n const grip = surfaceGrip(surface, state.u)\n if (grip !== groundGrip) {\n groundGrip = grip\n world.setMaterial(ground, { frictionStatic: grip, frictionDynamic: grip, restitution: 0 })\n }\n world.driveVehicle(vehicle, mapper.map({ input, speed: state.u, dt: h }))\n const v: readonly [number, number, number] = [velocity[0]!, velocity[1]!, velocity[2]!]\n world.addImpulse(body, resistanceImpulse(spec, v, h))\n // a vehicle without four-wheel drive sinks in a surface that bogs it while it tries to move: the spec's bog resistance in place of the tyres' rolling resistance\n if (surface.bogs && !spec.fourWheelDrive && input.throttle > 0) {\n const extra = resistanceImpulse({ drag: 0, rolling: spec.bogResistance - spec.rolling, mass: spec.mass }, v, h)\n world.addImpulse(body, extra)\n }\n world.step(h)\n readState()\n time += h\n if (time >= nextSample) {\n trace.push([Math.round(time * 1000) / 1000, procedure.sample(state, time, memo)])\n nextSample += sampleEvery\n }\n if (procedure.finished(state, time, memo) || time >= procedure.maxSeconds) done = true\n }\n readState()\n return {\n test, subject, surface: surfaceId, memo, state, fixedStep: fixed,\n get time() { return time },\n get done() { return done },\n get trace() { return trace },\n get input() { return last },\n stepFixed(steps) {\n for (let i = 0; i < steps && !done; i++) tick(fixed)\n },\n result: () => resultOf({ test, subject, memo, trace, done, state, time }),\n dispose: () => world.dispose(),\n }\n}\n\n/** Runs a measured test on the physics engine to its end and returns the result; the world is let go. */\nexport function runTestOnPhysics(test: ProvingTest, subject: ProvingSubject, options: PhysicsRunOptions): ProvingResult {\n const run = startPhysicsRun(test, subject, options)\n try {\n while (!run.done) run.stepFixed(1)\n return run.result()\n } finally {\n run.dispose()\n }\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;AAEhC,SAAS,qBAAqB,gBAAgB,yBAAyB;;;ACAvE,IAAM,YAAY,CAAC,OAAiD,MAAsB;AACxF,MAAI,KAAK,MAAM,CAAC,EAAG,CAAC,EAAG,QAAO,MAAM,CAAC,EAAG,CAAC;AACzC,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,UAAM,CAAC,IAAI,EAAE,IAAI,MAAM,CAAC;AACxB,UAAM,CAAC,IAAI,EAAE,IAAI,MAAM,IAAI,CAAC;AAC5B,QAAI,KAAK,GAAI,QAAO,MAAO,KAAK,OAAO,IAAI,OAAQ,KAAK;AAAA,EAC1D;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KAAK;AAAA,IAC9B;AACA,UAAM,KAAK,CAAC;AACZ,cAAU;AACV,YAAQ;AACR,QAAI,QAAQ,YAAY;AACtB,YAAM,KAAK,CAAC,KAAK,MAAM,OAAO,GAAI,IAAI,KAAM,UAAU,OAAO,OAAO,MAAM,IAAI,CAAC,CAAC;AAChF,oBAAc;AAAA,IAChB;AACA,QAAI,UAAU,SAAS,OAAO,MAAM,IAAI,KAAK,QAAQ,UAAU,WAAY,QAAO;AAAA,EACpF;AACA,YAAU;AACV,SAAO;AAAA,IACL;AAAA,IAAM;AAAA,IAAS,SAAS;AAAA,IAAW;AAAA,IAAM;AAAA,IAAO,WAAW;AAAA,IAC3D,IAAI,OAAO;AAAE,aAAO;AAAA,IAAK;AAAA,IACzB,IAAI,OAAO;AAAE,aAAO;AAAA,IAAK;AAAA,IACzB,IAAI,QAAQ;AAAE,aAAO;AAAA,IAAM;AAAA,IAC3B,IAAI,QAAQ;AAAE,aAAO;AAAA,IAAK;AAAA,IAC1B,UAAU,OAAO;AACf,eAAS,IAAI,GAAG,IAAI,SAAS,CAAC,MAAM,IAAK,MAAK,KAAK;AAAA,IACrD;AAAA,IACA,QAAQ,MAAM,SAAS,EAAE,MAAM,SAAS,MAAM,OAAO,MAAM,OAAO,KAAK,CAAC;AAAA,IACxE,SAAS,MAAM,MAAM,QAAQ;AAAA,EAC/B;AACF;AAGO,SAAS,iBAAiB,MAAmB,SAAyB,SAA2C;AACtH,QAAM,MAAM,gBAAgB,MAAM,SAAS,OAAO;AAClD,MAAI;AACF,WAAO,CAAC,IAAI,KAAM,KAAI,UAAU,CAAC;AACjC,WAAO,IAAI,OAAO;AAAA,EACpB,UAAE;AACA,QAAI,QAAQ;AAAA,EACd;AACF;","names":["kmh","createSurfaces","createSurfaces"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adatechnology/game-vehicles-proving",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Vehicle proving ground without three.js: measured tests (0-100, top speed, braking, turning circle, wet braking, mud) run on the semi-simulation driver, ranges by class and design card, visual checks signed off by a person, a certificate per vehicle and the list of approved vehicles a game lets in. Land, water and air. Knows nothing about any game.",
|
|
6
6
|
"keywords": [
|
|
@@ -39,12 +39,14 @@
|
|
|
39
39
|
"@types/node": "^22.10.7",
|
|
40
40
|
"tsup": "^8.5.1",
|
|
41
41
|
"typescript": "^5.7.3",
|
|
42
|
-
"vitest": "^3.2.4"
|
|
42
|
+
"vitest": "^3.2.4",
|
|
43
|
+
"@adatechnology/game-physics-jolt": "^0.3.1"
|
|
43
44
|
},
|
|
44
45
|
"dependencies": {
|
|
45
|
-
"@adatechnology/game-contracts": "^0.
|
|
46
|
-
"@adatechnology/game-
|
|
47
|
-
"@adatechnology/game-
|
|
46
|
+
"@adatechnology/game-contracts": "^0.42.0",
|
|
47
|
+
"@adatechnology/game-physics": "^0.4.0",
|
|
48
|
+
"@adatechnology/game-runtime": "^0.3.6",
|
|
49
|
+
"@adatechnology/game-vehicles-driving": "^0.2.29"
|
|
48
50
|
},
|
|
49
51
|
"scripts": {
|
|
50
52
|
"build": "tsup",
|