[Refactoring]: Reduce number of times the exposed area is calculated #3744
Labels
code-maintenance
Adding/editing javadocs, unit tests, formatting.
performance
A performance or quality of life improvement
Describe the problem
When using Individual FoW, the exposed area is recalculated every time fog needs to be rendered. This includes every time the zone is panned or zoomed, even though that has no bearing on the exposed area.
Additionally, we calculate the exposed area twice. We should calculate it at most once per frame because it can be really expensive for complicated FoW.
The improvement you'd like to see
ZoneRenderer
would cache the exposed area associated with a givenPlayerView
. If that view ever changes, the exposed area would be recalculated. Also, if FoW is ever explicitly flushed, then the exposed area would also be recalculated.Expected Benefits
The first frame that renders a given set of exposed areas will still be expensive, but most frames would be very cheap. Panning and zooming the map would be much more responsive.
Additional Context
The expensive call that calculates the exposed area is
zone.getExposedArea(view)
inZoneRenderer.renderFog()
. While we only call that method once, we actually duplicate its logic a little further down when in the calculation oftempArea
. I.e.,tempArea
andcombined
are always equal as far as I can tell, so there is no need to recalculatetempArea
or union it withcombined
as we do.For comparison, I made a prototypical code change (no cache invalidation) to measure the potential impact. Using the sole map in this test campaign, I saw an improvement from ~270-350 ms to <20ms for renderFog in most frames. Just removing
tempArea
gives a 2x speed up (naturally) and caching provided the remaining benefit.The text was updated successfully, but these errors were encountered: