@adatechnology/game-vehicles-proving 0.1.1 → 0.1.3
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/dist/index.global.js +28 -9
- package/dist/index.global.js.map +1 -1
- package/package.json +3 -3
package/dist/index.global.js
CHANGED
|
@@ -44,6 +44,7 @@ var GameVehiclesProving = (() => {
|
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
// ../game-contracts/dist/index.js
|
|
47
|
+
var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
|
|
47
48
|
var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
|
|
48
49
|
var DEFERRED_QUEUE_ID = {
|
|
49
50
|
DESTRUCTION_EVENTS: "destruction.events",
|
|
@@ -181,7 +182,15 @@ var GameVehiclesProving = (() => {
|
|
|
181
182
|
var clamp2 = (x, a, b) => Math.max(a, Math.min(b, x));
|
|
182
183
|
var MAX_SUBSTEP = 1 / 240;
|
|
183
184
|
var FLAT_BELOW = 0.2;
|
|
185
|
+
var RIM_RADIUS_SHARE = 0.7;
|
|
186
|
+
var RIM_FRICTION = 0.4;
|
|
187
|
+
var RIM_ROLLING = 0.25;
|
|
188
|
+
var FLAT_SAG = 0.05;
|
|
189
|
+
var FLAT_ROLLING = 6;
|
|
184
190
|
var STALL_HEALTH = 0.3;
|
|
191
|
+
var CLUTCH_BITE = 0.7;
|
|
192
|
+
var STALL_RPM = 0.5;
|
|
193
|
+
var STALL_GAS = 0.35;
|
|
185
194
|
var defaultSemiSpec = {
|
|
186
195
|
mass: 1300,
|
|
187
196
|
centreHeight: 0.5,
|
|
@@ -322,7 +331,14 @@ var GameVehiclesProving = (() => {
|
|
|
322
331
|
const accelInput = reversing ? input.brake : input.throttle;
|
|
323
332
|
const brakeInput = clamp2(reversing ? input.throttle : input.brake, 0, 1);
|
|
324
333
|
const ratio = ratioOf(state.gear) * spec.finalDrive;
|
|
325
|
-
state.
|
|
334
|
+
const engaged = input.clutch == null || state.gear === 0 ? 1 : 1 - clamp2(input.clutch, 0, 1);
|
|
335
|
+
const coupled = wheelRpm * ratio;
|
|
336
|
+
const free = spec.engine.idleRpm + clamp2(accelInput, 0, 1) * (spec.engine.redlineRpm * 0.7 - spec.engine.idleRpm);
|
|
337
|
+
state.rpm = clamp2(coupled * engaged + Math.max(coupled, free) * (1 - engaged), spec.engine.idleRpm, spec.engine.redlineRpm + 200);
|
|
338
|
+
if (input.clutch != null && state.gear !== 0 && state.engineOn && engaged > CLUTCH_BITE && coupled < spec.engine.idleRpm * STALL_RPM && accelInput < STALL_GAS) {
|
|
339
|
+
state.engineOn = false;
|
|
340
|
+
events.push({ type: "stall" });
|
|
341
|
+
}
|
|
326
342
|
if (!state.engineOn || state.fuel <= 0) state.rpm = 0;
|
|
327
343
|
let throttle = clamp2(accelInput, 0, 1);
|
|
328
344
|
if (engineHealth < STALL_HEALTH && throttle > 0.8) {
|
|
@@ -333,12 +349,13 @@ var GameVehiclesProving = (() => {
|
|
|
333
349
|
}
|
|
334
350
|
throttle *= 0.5;
|
|
335
351
|
} else stallWatch.throttleTime = 0;
|
|
336
|
-
|
|
352
|
+
const starting = input.start ?? (accelInput > 0 && Math.abs(state.u) < 0.5);
|
|
353
|
+
if (!state.engineOn && starting && engineHealth >= STALL_HEALTH && state.fuel > 0) state.engineOn = true;
|
|
337
354
|
if (state.fuel <= 0 && state.engineOn) {
|
|
338
355
|
state.engineOn = false;
|
|
339
356
|
events.push({ type: "out_of_fuel" });
|
|
340
357
|
}
|
|
341
|
-
const engineTorque = state.engineOn ? torqueAt(spec, state.rpm) * throttle * (0.55 + 0.45 * engineHealth) : 0;
|
|
358
|
+
const engineTorque = state.engineOn ? torqueAt(spec, state.rpm) * throttle * (0.55 + 0.45 * engineHealth) * clamp2(input.powerLimit ?? 1, 0, 1) * engaged : 0;
|
|
342
359
|
const driveForceTotal = state.gear === 0 ? 0 : (reversing ? -1 : 1) * engineTorque * ratio * spec.efficiency / spec.wheelRadius;
|
|
343
360
|
if (state.engineOn) {
|
|
344
361
|
const burned = fuelRate(fuelModel, state.rpm / spec.engine.redlineRpm, throttle, cargo / baseMass, engineHealth) * dt;
|
|
@@ -356,19 +373,21 @@ var GameVehiclesProving = (() => {
|
|
|
356
373
|
const wz = state.z - w.x * sn + w.z * cs;
|
|
357
374
|
const ground = world.ground ? world.ground(wx, wz) : {};
|
|
358
375
|
const surface = surfaces.get(contamination && contamination.left > 0 && surfaces.get(contamination.id).grip < surfaces.get(ground.surface ?? "dry_asphalt").grip ? contamination.id : ground.surface ?? "dry_asphalt");
|
|
376
|
+
const tyreHealth = cond.tyres ? clamp2(cond.tyres[i] ?? 1, 0, 1) : 1;
|
|
377
|
+
const rim = !!cond.rims?.[i];
|
|
378
|
+
const flat = rim || tyreHealth < FLAT_BELOW;
|
|
379
|
+
const radius = rim ? spec.rimRadius ?? spec.wheelRadius * RIM_RADIUS_SHARE : flat ? spec.wheelRadius - FLAT_SAG : spec.wheelRadius;
|
|
359
380
|
const top = state.height + w.x * state.pitch - w.z * state.roll;
|
|
360
|
-
const length = top - (ground.height ?? 0) -
|
|
381
|
+
const length = top - (ground.height ?? 0) - radius;
|
|
361
382
|
const compression = ride - length;
|
|
362
383
|
const rate = -(state.heightRate + w.x * state.pitchRate - w.z * state.rollRate);
|
|
363
384
|
const k = spec.suspension.spring * (0.5 + 0.5 * suspensionHealth);
|
|
364
385
|
const c = spec.suspension.damper * (0.5 + 0.5 * suspensionHealth);
|
|
365
386
|
const load = Math.max(0, k * compression + c * rate);
|
|
366
|
-
const tyreHealth = cond.tyres ? clamp2(cond.tyres[i] ?? 1, 0, 1) : 1;
|
|
367
|
-
const flat = tyreHealth < FLAT_BELOW;
|
|
368
387
|
const bog = !!surface.bogs && !spec.fourWheelDrive;
|
|
369
388
|
if (bog) bogging = true;
|
|
370
|
-
const grip = surfaceGrip(surface, state.u) * (flat ? 0.5 : 1);
|
|
371
|
-
wheelState.push({ n: load, grip, surface: surface.id, bog, flat });
|
|
389
|
+
const grip = surfaceGrip(surface, state.u) * (rim ? RIM_FRICTION / spec.tyre.friction : flat ? 0.5 : 1);
|
|
390
|
+
wheelState.push({ n: load, grip, surface: surface.id, bog, flat, rim });
|
|
372
391
|
sumN += load;
|
|
373
392
|
sumNA += load * w.x;
|
|
374
393
|
sumNB += load * w.z;
|
|
@@ -404,7 +423,7 @@ var GameVehiclesProving = (() => {
|
|
|
404
423
|
if (locked || lockedByBrake) fl += moving ? -Math.sign(vl) * capacity * (lockedByBrake ? SLIDING_GRIP : 1) : 0;
|
|
405
424
|
else if (brakeShare > 0 && moving) fl += -Math.sign(vl) * brakeShare;
|
|
406
425
|
if (brakeShare > 0 && moving) brakeWork += Math.min(brakeShare, capacity) * Math.abs(vl) * dt;
|
|
407
|
-
const rolling = ws.bog && accelInput > 0 ? spec.bogResistance : spec.rolling * (ws.flat ?
|
|
426
|
+
const rolling = ws.bog && accelInput > 0 ? spec.bogResistance : ws.rim ? RIM_ROLLING : spec.rolling * (ws.flat ? FLAT_ROLLING : 1);
|
|
408
427
|
const alpha = Math.atan2(vc, Math.abs(vl) + 0.5);
|
|
409
428
|
let fc = -Math.tanh(spec.tyre.corneringStiffness * alpha) * capacity;
|
|
410
429
|
if (locked) fc *= 0.6;
|