From 7396b099989e2806f86dac3ff1fdbe8c49ab6b84 Mon Sep 17 00:00:00 2001 From: Resaec Date: Wed, 29 Apr 2026 23:28:49 +0200 Subject: [PATCH] fix SetTimeOfDaySpeed influencing "current" time fix GetTimeOfDay not considering time speed fix SetTimeOfDay not considering time speed --- .../net/psforever/objects/zones/Zone.scala | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/scala/net/psforever/objects/zones/Zone.scala b/src/main/scala/net/psforever/objects/zones/Zone.scala index 8cad4927f..b7686beb8 100644 --- a/src/main/scala/net/psforever/objects/zones/Zone.scala +++ b/src/main/scala/net/psforever/objects/zones/Zone.scala @@ -573,24 +573,25 @@ class Zone(val id: String, val map: ZoneMap, zoneNumber: Int) { } def GetTimeOfDay(): Float = { - // get time since origin - val timeDiff = System.currentTimeMillis() - timeOfDayOrigin - // get seconds - limit to 24h - val diffSeconds = (timeDiff / 1000) % 86400 + val now = System.currentTimeMillis() + val timeDiff = now - timeOfDayOrigin - diffSeconds.toFloat + // get seconds + val diffSeconds = timeDiff / 1000 + + // apply speed factor + val elapsedTime = diffSeconds * timeOfDaySpeed + + // wrap time to 24h + elapsedTime % 86400 } def SetTimeOfDay(requestedTime: Float) = { - // get current time val now = System.currentTimeMillis() - // get requested time in millis - val requestMillis = requestedTime * 1000 - // substract requestedMillis from now to get new origin - val newOrigin = now - requestMillis + val requestedTimeDiff = requestedTime / timeOfDaySpeed - timeOfDayOrigin = newOrigin.toLong + timeOfDayOrigin = now - (requestedTimeDiff * 1000.0).toLong } def GetTimeOfDaySpeed(): Float = { @@ -598,7 +599,13 @@ class Zone(val id: String, val map: ZoneMap, zoneNumber: Int) { } def SetTimeOfDaySpeed(requestedSpeed: Float) = { + // store current time + val timeOfDay = GetTimeOfDay() + timeOfDaySpeed = requestedSpeed + + // restore old time with new speed considered + SetTimeOfDay(timeOfDay) } /**