[Refactoring]: Improve ZoneView caching in the presence of many sights #3747
Labels
code-maintenance
Adding/editing javadocs, unit tests, formatting.
performance
A performance or quality of life improvement
Describe the problem
Maps do not perform very well when there are many tokens with sight, particularly when individual views are used. In particular, even deselecting tokens can grind to halt even if nothing has changed since the tokens were selected.
There seems to be a few things at play:
ZoneView
is cleared too eagerly. Even though it can map distinct player views to their own areas, the entire cache is being cleared whenever the player view is changed (such as when selecting / deselecting tokens).The improvement you'd like to see
First, more intelligent invalidation of
ZoneView.visibleAreaMap
. Unless something changes that impacts all views, the cache as a whole should not be cleared. In particular, it should be possible to change views without any invalidation of this cache.Second, improve to the visible area calculations. We can factor out some common results that can be shared across tokens. For example, the heaviest part of the calculation is probably the need to stack up all the light sources and the token's sight. But that doesn't necessarily need to be repeated for all tokens, e.g., if there is no darkenss or sight multipliers in play, than all tokens would agree on the lit area. We could therefore combine that common result with each token's restriction on vision rather than recalculating everything from scratch for each token.
Expected Benefits
Performance would be much better when making heavy use of sights, which will improve the user experience. The caching improvement would avoid pauses when selecting and deselecting tokens, while the algorithm improvement would reduce the length of the pauses whenever the calculation need to be redone.
Additional Context
No response
The text was updated successfully, but these errors were encountered: