The previous implementation:
- Was failing to dispose of pooled layers.
- Was using a finalizer to allow undisposed layers to be reused.
This means all pooled layers are kept alive indefinitely until the map changes. If the finalizer is slow for any reason then the pathfiinder will allocate new layers when the pool runs out. Since these new layers are eventually stuffed back into the pool when the finalizer does run, this can theoretically leak unbounded memory until the pool goes out of scope. In practice it would leak tens of megabytes.
The new implementation ensures layers are disposed and pooled correctly to allow proper memory reuse. It also introduces some safeguards against memory leaks:
- A cap is set on the number of pooled layers. If more concurrent layers are needed than this, then the excess layers will not be pooled but instead be allowed to be garbage collected.
- No finalizer. An implementation that fails to call dispose simply allows the layer to be garbage collected instead.
If Tilesets was empty but ExcludeTilesets was not, it would always return false even though that combination is supposed to mean only the excluded tileset(s) is/are not valid for this effect.
Moved RotationBase from tileset definition to WaterPaletteRotation effect.
Unhardcoded rotation range and rotation rate.
Added possibility to exclude Tilesets from effect.
Fixed RA water palette rotation for actors on desert maps (#8872).
In places where arrays were being treated as a set, just create a set directly. This reveals the intention of such collections better, and also improves performance by allowing set based methods to be used.
The path caching works on the assumption that the time saved from reusing a cached path outweights the cost of caching it in the first place.
For unit paths, this assumption holds. For path searchs, we spend more time caching them then we save when we get to reuse these cached paths. This is because they are reused less often, and calculating their key is more expensive in comparison.