fishpondstudio/CivIdle

ensureTileFogOfWar does too much work

Closed this issue · 2 comments

ensureTileFogOfWar in TerrainLogic.ts does not maintain a list of "seen" tiles similar to classic BFS visitor patterns in undirected graphs. This means that it ends up revisiting tiles interior to the region, as well as creating duplicates entries in the target list.

Setting BUILDING_DEFAULT_VISION or the vision of a building higher than 6 causes the game to noticeably freeze.
Higher only gets worse.

I recommend adding the aforementioned check on if a tile has already been visited, or replacing the BFS implementation with iteration across a list generated from the range via a method like the following: https://www.redblobgames.com/grids/hexagons/#range

Yes, this code is done in a quick and dirty way. The range is never designed to be very high and it's not called in a hot loop.

While it's not a high priority on my list to optimize this, if you want to submit a PR, I am happy to take a look and merge this.

Fixed in 0.2.0