function onTick() {
mutable totalMsElapsed = mutable totalMsElapsed + msPerTick;
const oldGasPedal = mutable gasPedal;
const oldX = mutable x;
const oldV = mutable v;
mutable x = oldX + actualV * sPerTick;
mutable v = Math.max(0, oldV + a * sPerTick);
mutable gasPedal = desiredGasPedal;
console.log(mutable gasPedal, oldGasPedal);
if (roundV(oldV) === roundV(v)) {
mutable vRetainedFor = mutable vRetainedFor + msPerTick;
} else {
mutable vRetainedFor = 0;
}
if (
!mutable cruiseControlIsActive &&
!brakePedal &&
actualV >= minCruiseControlV &&
vRetainedFor > minCruiseControlActivationT
) {
mutable cruiseControlV = actualV;
mutable cruiseControlIsActive = true;
}
if (mutable cruiseControlIsActive && brakePedal) {
mutable cruiseControlIsActive = false;
}
if (mutable cruiseControlIsActive && mutable gasPedal > oldGasPedal) {
mutable vRetainedFor = 0;
mutable cruiseControlIsActive = false;
}
}