# Efficient way to implement fog of war on a 2D grid with multiple actors

Lets say you have a 2D grid of tiles 100x100 and each tile can toggle fog on/off. To initialize the map you draw the tiles and toggle fog ON for each tile.

Now drop a single actor on the grid and use the actor's vision to determine which tiles need to toggle the fog OFF. As long at the actor stands still there is no further action required. When the actor moves you look ahead and toggle fog OFF on tiles near the destination and toggle the fog back ON for tiles in the area the actor is leaving. This implementation works well when there is a single actor but starts getting tricky when you add multiple actors.

Imagine the same scenario but now you have two actors standing on adjacent tiles. Initialization is the same, the initial vision is just based on each actor's starting point and vision distance. Now lets say one actor moves away while the second actor remains stationary. You can't use the original logic since, as the first actor leaves he will begin toggling the fog ON around the tiles where the second actor is standing (and still has vision).

I can think of two possible solutions and I'm wondering if there is something better that Im missing:

1. You could have the tile search the surrounding area for an actor with vision before toggling fog back ON but since an actor can have an arbitrary vision distance the tile won't know how far out to search unless the tile is aware of the maximum vision distance.

2. Each time an actor moves you could loop through every actor and redraw all vision but that seems inefficient if you have a large number of actors, especially if there is not a lot of simultaneous movement.