feat: add real-time ETA interpolation for block reader
This commit is contained in:
+10
-2
@@ -2247,6 +2247,14 @@ function Main.loop()
|
||||
if Peripherals.blockReader then
|
||||
local ok, data = pcall(Peripherals.blockReader.getBlockData)
|
||||
if ok and data and data.TrainStops then
|
||||
-- Real-time interpolation: calculate exact current tick even if NBT is cached
|
||||
if not State.lastRefreshed or State.lastRefreshed ~= data.LastRefreshed then
|
||||
State.lastRefreshed = data.LastRefreshed
|
||||
State.lastRefreshedEpoch = now
|
||||
end
|
||||
local elapsedTicks = math.floor((now - (State.lastRefreshedEpoch or now)) / 50)
|
||||
local currentTick = (data.LastRefreshed or 0) + elapsedTicks
|
||||
|
||||
for k, v in pairs(State.announcedApproaching) do
|
||||
if now - v > 300000 then
|
||||
State.announcedApproaching[k] = nil
|
||||
@@ -2260,10 +2268,10 @@ function Main.loop()
|
||||
local destination = st.Destination or "Unknown"
|
||||
local platform = stop.StationInfo and stop.StationInfo.Platform or State.stationPlatform or "1"
|
||||
|
||||
-- Calculate ETA in seconds
|
||||
-- Calculate ETA in seconds using interpolated currentTick
|
||||
local scheduledArrival = st.ScheduledArrival or 0
|
||||
local realArrival = st.RealTimeArrival or 0
|
||||
local etaTicks = realArrival - (data.LastRefreshed or 0)
|
||||
local etaTicks = realArrival - currentTick
|
||||
local etaSeconds = math.floor(etaTicks / 20)
|
||||
|
||||
-- Calculate Delay in minutes
|
||||
|
||||
Reference in New Issue
Block a user