nms-scribe / cosmopoeia

A tool to generate fantasy maps for GIS.
MIT License
3 stars 1 forks source link

Possible infinite loop in Lake Fill #44

Open nms-scribe opened 10 months ago

nms-scribe commented 10 months ago

The lake fill algorithm usually takes a second at most. On one world, generated from a heightmap with 100000 tiles, after certain terrain processes are completed on it (Multiple and occasionally Erode), the lake fill would continue for several minutes without finishing. Due to the extreme discrepancy in time, I assumed it was an infinite loop and killed the program and tried again with other settings.

nms-scribe commented 2 weeks ago

I did find one source of the cycle, as written in the code comments:

// Every once in a while, water will fill a lake, the lake's level will rise above the neighbors, causing
// the water to be pushed back into the neighbor that sent the water to the lake originally...

I put in a fix which prevents the tile from being visited more than 100 times the count of tiles. I don't think that's enough though. I think I've just got to find a better algorithm which breaks the flow from fill.