change ChunkWorker to support different terrain generators
This commit is contained in:
parent
d3f630703f
commit
8fc089834f
1 changed files with 8 additions and 20 deletions
|
@ -8,6 +8,9 @@
|
||||||
const { parentPort } = require('worker_threads'),
|
const { parentPort } = require('worker_threads'),
|
||||||
{ deflateSync } = require("zlib");
|
{ deflateSync } = require("zlib");
|
||||||
|
|
||||||
|
const GeneratorFlat = require("../Generators/GeneratorFlat.js");
|
||||||
|
const GeneratorPerlin = require("../Generators/GeneratorPerlin.js");
|
||||||
|
|
||||||
const bufferStuff = require("../bufferStuff.js");
|
const bufferStuff = require("../bufferStuff.js");
|
||||||
|
|
||||||
let busyInterval = null;
|
let busyInterval = null;
|
||||||
|
@ -22,30 +25,15 @@ parentPort.on("message", (data) => {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "generate":
|
case "generate":
|
||||||
parentPort.postMessage([data[0], generateChunk(), data[1], data[2], data[3]]);
|
const startTime = new Date().getTime();
|
||||||
|
parentPort.postMessage([data[0], generateChunk(data[1], data[2]), data[1], data[2], data[3]]);
|
||||||
|
console.log(`Chunk (${data[1]}, ${data[2]}) took ${new Date().getTime() - startTime}ms to generate`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function generateChunk() {
|
function generateChunk(x = 0, z = 0) {
|
||||||
let chunk = {};
|
return GeneratorPerlin(x, z);
|
||||||
for (let y = 0; y < 128; y++) {
|
|
||||||
chunk[y] = {};
|
|
||||||
for (let x = 0; x < 16; x++) {
|
|
||||||
chunk[y][x] = {};
|
|
||||||
for (let z = 0; z < 16; z++) {
|
|
||||||
if (y == 64) {
|
|
||||||
chunk[y][x][z] = 2;
|
|
||||||
}
|
|
||||||
else if (y == 63 || y == 62) chunk[y][x][z] = 3;
|
|
||||||
else if (y == 0) chunk[y][x][z] = 7;
|
|
||||||
else if (y < 62) chunk[y][x][z] = 1;
|
|
||||||
else chunk[y][x][z] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return chunk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function doChunk(chunk) {
|
function doChunk(chunk) {
|
||||||
|
|
Loading…
Reference in a new issue