[Refactoring]: Improvements to visibility calculation for large and complex geometry #3459
Labels
code-maintenance
Adding/editing javadocs, unit tests, formatting.
performance
A performance or quality of life improvement
tested
This issue has been QA tested by someone other than the developer.
Describe the problem
The algorithm in
FogUtil::calculateVisibility()
has many inefficiencies that become noticeable when map topology gets complex.Point2D
andAreaFace
) only to produce JTS geometry in the end. JTS geometry is generally more efficient, and any conversion from one to the other is also a point of inefficiency.The improvement you'd like to see
There are a few main ways I see to improve the visibility calculation:
VisibleAreaSegment
s to only those within the token's range of vision. Also, cut out individual faces within a segment that lie outside of vision.VisibleAreaSegment
/AreaFace
in the algorithm and instead work onLineString
s. Then we can rely on that JTS geometry to perform the intersection checks needed for (1).Expected Benefits
There are some significant performance gains to be had in the presence of large and complicated topology, and even with not-so-complicated topology.
E.g., an experimental implementation of improvement (1) brings the test case time down from ~21 seconds to ~13 seconds. Improvements (2) and (3) look like they may bring that down further to ~10 seconds. That sounds like a lot, but most of the remaining time is spent elsewhere, specifically in the
Area
unions performed to reveal all the FoW along the path.Additional Context
Here is a test map which demonstrates a cave system (complicated topology) with a token with darkvision (limited range): 80x80 Cave.zip
A simple test case is as follows:
exposeLastPath-Hero
.I am getting a consistent result of ~21.2 seconds with the current
develop
code.The text was updated successfully, but these errors were encountered: