Round TOT/start time as needed.

The increased precision that we had everywhere except the UI and the
interface with DCS was causing issues with ASAP creating barely
negative start times. The main cause of this was that we'd compute the
earliest possible TOT, it would result in, for example, 23:10.002.
When we then set the QTimeEdit for the TOT, we have to round because
it does not support (nor do we really want to display) sub-second
values, which then caused the previously 0 start time to be -0.002.

Instead, since the sub-second values aren't really interesting anyway,
we now just round TOTs up and start times down. This should prevent
negative start times from occurring (except when they've been manually
planned as such), and also prevents start times of 00:00:01.

Also rounds the package waypoint times to avoid the same issues, but
it's not really important which direction we round these.

Fixes https://github.com/Khopa/dcs_liberation/issues/295
This commit is contained in:
Dan Albert
2020-11-01 13:09:33 -08:00
parent ab67a38ca5
commit 5ba633c8a1
2 changed files with 42 additions and 22 deletions

View File

@@ -7,6 +7,7 @@ generating the waypoints for the mission.
"""
from __future__ import annotations
import math
from datetime import timedelta
from functools import cached_property
import logging
@@ -93,29 +94,31 @@ class PackageWaypointTiming:
if group_ground_speed is None:
return None
ingress = package.time_over_target - TravelTime.between_points(
package.waypoints.ingress,
package.target.position,
group_ground_speed
)
# Round each waypoint TOT since DCS doesn't support sub-second timing
# and it's not interesting to the user.
ingress = timedelta(seconds=math.floor(
(package.time_over_target - TravelTime.between_points(
package.waypoints.ingress,
package.target.position,
group_ground_speed)).total_seconds()))
join = ingress - TravelTime.between_points(
package.waypoints.join,
package.waypoints.ingress,
group_ground_speed
)
join = timedelta(seconds=math.floor(
(ingress - TravelTime.between_points(
package.waypoints.join,
package.waypoints.ingress,
group_ground_speed)).total_seconds()))
egress = package.time_over_target + TravelTime.between_points(
package.target.position,
package.waypoints.egress,
group_ground_speed
)
egress = timedelta(seconds=math.floor(
(package.time_over_target + TravelTime.between_points(
package.target.position,
package.waypoints.egress,
group_ground_speed)).total_seconds()))
split = egress + TravelTime.between_points(
package.waypoints.egress,
package.waypoints.split,
group_ground_speed
)
split = timedelta(seconds=math.floor(
(egress + TravelTime.between_points(
package.waypoints.egress,
package.waypoints.split,
group_ground_speed)).total_seconds()))
return cls(package, join, ingress, egress, split)