I’m using a grid based system with crossable and non-crossable squares with A* for finding paths, and with flood fill to see if it’s possible to find a path (to see if two areas are connected).
My problem is that new uncrossable areas could be introduced quite frequently (up to 16 times a second) and the grid is fairly large (about 500 by 500) so even the O(mn) flood fill solution would take a fairly long amount of time. I have looked at different implementations of floodfill and couldn’t find anything similar to what I want.
So my question is that is there any way to optimize repeated flood fill calls based on the previous grid and with a list of new uncrossable areas (which will always be rectangular)?
Start by partitioning the crossable squares into connected components with a flood fill algorithm.
When you mark a region as non-crossable, consider the set S of all the crossable squares outside the region adjacent to a previously crossable square in the region. For each component C which has at least two members in S, use flood fill to check if C has been disconnected.
When you mark a region as crossable, consider the set S of all the crossable squares outside the region adjacent to a square in the region.Join all the components with a member in S.