OpenRA/OpenRA — pull request #5851 by RoosterDragon (2014-07-06 22:15:36+00:00)
Title: Speed up shroud checks

This improves shroud-related performance.

There are two key changes in this PR:
* Carried over from #5542, shroud is only updated within the visible screen region. When scrolling on large maps this prevents a lot of wasted work being performed to update the whole shroud to prep it for rendering since most of it will be thrown away when the shroud changes before it can be used anyway.
* The refactored ```GetEdges``` method accepts a delegate for the visibility function. This removes the duplicate code between ```FoggedEdges``` and ```ShroudedEdges``` but also allows an optimization by allowing the delegate to be specialized. About 50% of the work done in calls to ```IsVisible``` or ```IsExplored``` are the initial checks that the cell is within the map boundary and if the shroud or fog is even enabled. We can avoid repeating these checks by providing a delegate valid over certain cell regions. We can check the map bounds and shroud/fog visibility once upfront and then a faster delegate that just does the core work can be used. In the common scenario where all the cells are in bounds and shroud/fog is enabled the fast core work only delegate is about twice as fast. Since it gets called in loops this makes shroud-related checks about twice as fast. In practise, scrolling around a fair amount on a medium-sized map at the start of a game with a bunch of AI saw the ```RenderShroud``` method take up 28% of CPU time, with 11% being the ```Update``` method. This PR reduced that to 21% with 5% being the ```Update``` method.