0
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

Instead of binary fog on-off, you can have "tileSeenBy", starting with 0. Every time an actor sees a tile, they increment tileSeenBy by 1. Every time they move and don't have it in their field of view anymore, they decrement. If it's 0, nobody sees it. Super fast to calculate and check.

I know it's a bit costlier in terms of storage, but will save you calculations. For 256 max actors in the level sharing the fog of war, you need a ubyte per fog tile. For 65536, you need a ushort, and so on.

\$\endgroup\$
  • \$\begingroup\$ Great idea. This is exactly the type of feedback I wanted :D \$\endgroup\$ – FSB Dec 9 '14 at 9:50
  • \$\begingroup\$ Glad this was useful :) \$\endgroup\$ – Babis Dec 9 '14 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.