Skip to content

Commit

Permalink
Add craters (proto-lakes)
Browse files Browse the repository at this point in the history
  • Loading branch information
deathcap committed Dec 28, 2013
1 parent e1358f1 commit ff38b68
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ ChunkGenerator.prototype.decorate = function(random, chunkX, chunkY, chunkZ, chu
if (!this.opts.populateTrees)
return;

// trees

// TODO: large-scale biomes, with higher tree density? forests
var treeCount = ~~scale(this.noiseTrees.noise2D(chunkX / this.opts.treesScale, chunkZ / this.opts.treesScale), -1, 1, 0, this.opts.treesMaxDensity);

Expand Down Expand Up @@ -111,6 +113,20 @@ ChunkGenerator.prototype.decorate = function(random, chunkX, chunkY, chunkZ, chu
});
}

// "craters" (TODO: fill with water to make lakes)
if (random() < 0.20) {
var radius = ~~(random() * 10);
for (var dx = -radius; dx <= radius; ++dx) {
for (var dy = -radius; dy <= radius; ++dy) {
for (var dz = -radius; dz <= radius; ++dz) {
var distance = Math.sqrt(dx*dx + dy*dy + dz*dz); // TODO: better algorithm
if (distance < radius)
changes.push([[startX+dx, startY+dy, startZ+dz], 0]);
}
}
}
}

return changes;
};

Expand Down Expand Up @@ -155,7 +171,7 @@ ChunkGenerator.prototype.generateChunk = function(pos) {
// features
var random = new Alea(pos[0] + pos[1] * width + pos[2] * width * width); // TODO: sufficient?
this.populateChunk(random, pos[0], pos[1], pos[2], heightMap, voxels);
changes = this.decorate(random, pos[0], pos[1], pos[2], heightMap);
changes = this.decorate(random, pos[0], pos[1], pos[2], heightMap); // TODO: should run in another worker, to not block terrain gen?
} else if (pos[1] > 0) {
// empty space above ground
} else {
Expand Down

0 comments on commit ff38b68

Please sign in to comment.