Sunday, June 6, 2010

Progress, Episode 1: Maximum Recusion Depth and the Problem of Filling a Lake with Tildes

So I've finally begun writing the city generator. First up is terrain, which for the time being will consist of water features. This will include rivers, and a large body of water like a lake or ocean. Typically large urban centres are built around water features, so I think it's a good place to start. I got a random ocean shoreline generator working first, with a parameter controlling where the water will be located. It makes pretty neat shorelines half the time, I was sort of surprised that it worked so well.

Next up was the simple task of filling the lake with water. The little function I have is recursive, spreading water tile by tile from the appropriate edges. Recursive functions are so fun to write and think about, I've loved the concept ever since it finally clicked for me. Unfortunately though, this led to a little problem I was entirely unaware of: Python has a "recursion limit". Apparently you can't go 1000 deep in a recusion loop without fiddling with scary settings. Gah. So for larger lakes, I was getting crashes galore. Oh noes. Luckily enough a quick little reshuffling and a few extra lines of code fixed that up good. I don't like thinking about optomization as I'm doing things, but I have to admit my first lake filling function was a lapse in good judgement on a couple of counts.


The shoreline generator actually draws out what it is doing as it is doing it, so I finally have something cool to look at. As a result, here's a really unimpressive looking screenshot.


You can enlarge that image bby clicking on it. Things are pretty messy right now, but you can see the generated shoreline there. The water doesn't always hug an edge like that, sometimes almost half the total map will be covered in water. Maybe I'll make it so you can get a boat and be a pirate! Of course, should you not like what the generator gives you, you can tell it to try again. In time you'll be able to explicitly tell it how much water to strive for, shoreline straightness/complxeity, etc.

After polishing up a couple issues and fiddling with some display things, the river generator will be up next. Rivers will probably be pretty straight and unnatural for now, it all depends on how tricksy things will be. I am very much flying by the seat of my pants with this stuff, haha.

No comments:

Post a Comment