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.
Tiny nit: You don't have to initialize this until immediately before the loop below.