I'm in the process of making an RTS game and I've ran into a problem I could use help with. I want to create a fog of war system that reveals an area around a unit that belongs to you like how it's done in Starcraft 2. To do this, I'm using a 2 dimensional influence map that's stored in a 1 dimensional array to communicate with the FoW texture. Currently, every element in the array is a square tile and to find out whether or not it's revealed, I do a simple distance check but this generates a lot of performance demand on the CPU. Is there a clever way to check if a tile is revealed or not more efficiently? I've been thinking of using hexagons for the job, checking in 6 directions and interpolating the space in between but I'm not sure how to check in a single direction nor how to interpolate the space between.
Note: I'm using C# but pseudocode in any language works for me.
You could create a "delta list" that you apply to the current position to determine which square tiles are within the prescribed distance. For example:
OXXXO
XXXXX
XXOXX
XXXXX
OXXXO
There are twenty deltas: $\{(-1,2), (0,2), (1,2),(-2,1), (-1,1), (0,1), (1,1), (2,1), (-2,0),(-1,0),(1,0), (2,0), (-2,-1), (-1,-1), (0,-1), (1,-1), (2,-1), (-1,-2), (0,-2),(1,-2)\}$
Add each element in the list to the current $(x,y)$ position to give the twenty positions to reveal. You can even improve this somewhat by keeping track of movement -- if you move north then there is no need to re-reveal the southern part of the grid.