A Walker Based Map Generator

godotgdscriptprocedural_generation

Inspired by a video tutorial on walker based map generation, I took the opportunity to see how Godots editor plugins are created. I kept things simple with one custom view with a main view, few action buttons, some option toggles, sliders and number inputs, accessible through the top bar in the main screen:

I started by writing a GUI to test the algorithm and see the output, but quickly decided to turn it into an editor plugin just to see how it's done. Following the text tutorials got me well through the process. Starting out as a GUI scene that I could run and transitioning into a plugin also felt like a natural workflow.

Cave Generator: The plugin

The plugin itself creates cave-like maps using a walker based algorithm, which means all the walkable areas can be reached from the starting point. Parameters are tweakable before starting the generation and during the run. Optionally walls can be placed around the cave (instead of just empty). These can then be exported into a tilemap (searched from the currently active scene), where floor corresponds to one tile value and wall to another. A fun extension would be to create multiple layers, e.g. for water and let them mark different tile values.

Code is available for the interested. It hasn't been cleaned up or made presentable in any way, so expect feeling like you're walking into someones bedroom while they're out shopping groceries.

For the future

Editor plugins in general

For future plugins I would come up with a better debugging and testing scheme. In my experience reloading the plugin script requires toggling it on and off from the settings. This was annoying enough that I ended up running the scene instead. That wouldn't work in all cases, since the script won't then run in editor context and some functionality will be missing. The two approaches don't work well together either. When I had run the script as an editor plugin once, the scene would no longer respond when ran separately. This leads me to speculate that the solution to better debugging might be in more careful handling of the plugins instances and initialization. As stated, I'm not sure what a good solution would be, but one is definitely needed for a bigger (or more numerous) project(s).

Performance

Wall generation is very slow. Unlike the inspiration video, the plugin doesn't assume a clear outer area, so walking from outside in would leave holes. Thus we need to go from inside out; For every floor tile we step for each four cardinal directions until we hit empty or wall. An improvement option could be to assume everything is wall at the start, let walkers carve the cave and then use the outside-in strategy to clear the outer map if so desired. For general performance I'd be curious how a C++ version would compare. I don't have a good sense of the GDScript overhead. The actual walking isn't too fast either. Most of it could just be the visualization and it's just the right speed on my machine to make for a pleasing watch.