Terrain generator

Added a bunch of optimizations and restructuring to the map generation. Caves are hard, so that will be a problem solved another day.
Could maybe add an explicit note that this is a port from that URL. Right not it's not 100% obvious because it looks like a lot more code that I would expect in a stackoverflow question, they were really thorough.