Speed up computation of front line positions.

Needs to be properly measured, but this has made a multi-second speedup
in turn times.
This commit is contained in:
Dan Albert 2022-09-11 17:49:29 -07:00 committed by Raffson
parent ac49772584
commit d6bd5184b6
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99

View File

@ -6,11 +6,12 @@ from typing import Optional, Tuple
from dcs.mapping import Point from dcs.mapping import Point
from shapely.geometry import LineString, Point as ShapelyPoint from shapely.geometry import LineString, Point as ShapelyPoint
from shapely.ops import nearest_points
from game.settings import Settings from game.settings import Settings
from game.theater.conflicttheater import ConflictTheater, FrontLine from game.theater.conflicttheater import ConflictTheater, FrontLine
from game.theater.controlpoint import ControlPoint from game.theater.controlpoint import ControlPoint
from game.utils import Heading from game.utils import Heading, dcs_to_shapely_point
@dataclass(frozen=True) @dataclass(frozen=True)
@ -151,16 +152,23 @@ class FrontLineConflictDescription:
Checks for positions along the front line first. If none succeed, the nearest Checks for positions along the front line first. If none succeed, the nearest
land position to the initial point is used. land position to the initial point is used.
""" """
pos = initial if theater.landmap is None:
if theater.is_on_land(pos): return initial
return pos
for distance in range(0, int(max_distance), 100):
pos = initial.point_from_heading(heading.degrees, distance)
if theater.is_on_land(pos):
return pos
pos = initial.point_from_heading(heading.opposite.degrees, distance)
if theater.is_on_land(pos):
return pos
pos = theater.nearest_land_pos(initial) line = LineString(
return pos [
dcs_to_shapely_point(
initial.point_from_heading(heading.degrees, max_distance)
),
dcs_to_shapely_point(
initial.point_from_heading(heading.opposite.degrees, max_distance)
),
]
)
masked_front_line = theater.landmap.inclusion_zone_only.intersection(line)
if masked_front_line.is_empty:
return theater.nearest_land_pos(initial)
nearest_good, _ = nearest_points(
masked_front_line, dcs_to_shapely_point(initial)
)
return initial.new_in_same_map(nearest_good.x, nearest_good.y)