I'm trying to optimize my static FOW code for my 2D tile-based game and the bottleneck seems to be in the rendering of the fog (rather than the circle drawing algorithm or other aspect of the code).
It's a fairly simple implementation - there are two steps.
First, the game renders everything normally as if there is no fog. Then after the fact, the FOW code loops over every row and every column of tiles and if the tile is "hidden" behind fog, it draws black over the tile.
Everywhere on the web I see that this is the method most used - but to me it seems like it'd be much more efficient to set all of the tiles black, and only show through the tiles which are visible.
Although this sounds logical, in my case it turned out to be not very efficient either.
The Fog grid's tile size is different than the actual game's tile size, which provides some special challenges.
Are there any better methods for generating the Fog of War?
(The game's implementation is in Java, I can provide pseudocode if you'd like.)
Any help is appreciated.
EDIT: I've tried 2 circle-drawing algorithms, and there was little difference in performance (the original proved a little faster).
When I moved the fog code into the level drawing loop, I saw a notable performance increase, but it isn't a lasting solution because my fog grid size is larger than my map grid size.
EDIT 2: Here's the pseudocode - I don't feel comfortable posting the real code, as it isn't mine to post.
Level.render
for all x
for all y
if {x,y} is in view of camera
render tile
for all visible entities
if entity is in view of camera
render entity
call FOW.render()
FOW.render
for all x
for all y
if {x,y} is in view of camera
if tile is hidden by fog
render fog
graphics.fillRect(x, y, width, height);
No fancy shaders or anything. \$\endgroup\$