From afe85231f3047997f52e379754dbbde4e4e6a722 Mon Sep 17 00:00:00 2001 From: Ryan Young Date: Wed, 24 Jul 2024 11:11:03 +0000 Subject: [PATCH] fix(atc): cab signal delay not being affected by time acceleration --- src/lib/nec/adu.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/lib/nec/adu.ts b/src/lib/nec/adu.ts index 0c560669..56ab583e 100644 --- a/src/lib/nec/adu.ts +++ b/src/lib/nec/adu.ts @@ -126,26 +126,24 @@ export function create({ acsesStepsDown: boolean; } & CommonAduOptions): frp.Stream> { const atcAspectBeforeDelay = cs.createCabSignalBehavior(atc, e, pulseCodeControlValue); + // Need to use GetSimulationTime() here so that our delay is affected by + // time acceleration. const atcAspect$ = frp.compose( e.createPlayerWithKeyUpdateStream(), - frp.map(pu => { - const { dt } = pu; - const nextAspect = frp.snapshot(atcAspectBeforeDelay); - return { nextAspect, dt }; - }), + mapBehavior(atcAspectBeforeDelay), frp.fold( - ({ aspect, inS }: { aspect: A; inS: number }, { nextAspect, dt }) => { + ({ aspect, atS }: { aspect: A; atS: number }, nextAspect) => { if (aspect !== nextAspect) { // New signal aspect - return { aspect: nextAspect, inS: randomCabSignalDelayS() }; + return { aspect: nextAspect, atS: e.e.GetSimulationTime() + randomCabSignalDelayS() }; } else { - // Clock update - return { aspect, inS: Math.max(inS - dt, 0) }; + // Nothing to do + return { aspect, atS }; } }, - { aspect: atc.restricting, inS: 0 } + { aspect: atc.restricting, atS: 0 } ), - frp.map(({ aspect, inS }) => (inS <= 0 ? aspect : undefined)), + frp.map(({ aspect, atS }) => (e.e.GetSimulationTime() >= atS ? aspect : undefined)), rejectUndefined() ); const atcAspect = frp.liftN(