World shape for dimension
This commit is contained in:
+22
-18
@@ -6,7 +6,8 @@
|
||||
// map.png: 4096 blocks across from the terrain's heights and biomes (fast, no caves or 3d noise)
|
||||
// blocks.png: 768 blocks across from real generated chunks, top block with hill shading
|
||||
// section.png: a slice down through the world along x, showing caves, overhangs and underground rivers
|
||||
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, SEA_LEVEL } from "@/common/constants.ts";
|
||||
import { CHUNK_AREA, CHUNK_SIZE, SEA_LEVEL } from "@/common/constants.ts";
|
||||
import { dimension_shape } from "@/common/worldgen/data.ts";
|
||||
import { generate_raw_chunk } from "@/common/generation.ts";
|
||||
import { load_worldgen } from "@/common/worldgen_loader.ts";
|
||||
import { register_mod_data } from "@/common/mod_loader.ts";
|
||||
@@ -44,12 +45,17 @@ register_mod_data([{
|
||||
features: jsons(bworld.features),
|
||||
},
|
||||
}]);
|
||||
const dimension = jsons(bworld.dimensions).find((json) => json.default)!;
|
||||
const shape = dimension_shape(dimension);
|
||||
const worldgen = await load_worldgen({
|
||||
mods: ["bworld"],
|
||||
scripts: [{ mod: "bworld", url: new URL("../mods/bworld/scripts/worldgen.ts", import.meta.url).href }],
|
||||
ores: [jsons(bworld.ores)],
|
||||
generator: "bworld:overworld",
|
||||
generator: dimension.generator,
|
||||
shape,
|
||||
});
|
||||
// a block's place in a chunk's blocks
|
||||
const at = (lx: number, y: number, lz: number) => (y - shape.min_y) * CHUNK_AREA + lz * CHUNK_SIZE + lx;
|
||||
|
||||
const NAMES = [
|
||||
"bworld:stone",
|
||||
@@ -212,7 +218,8 @@ const shade = (color: [number, number, number], factor: number): [number, number
|
||||
const top = new Int32Array(size * size);
|
||||
const top_block = new Uint8Array(size * size);
|
||||
const water_depth = new Int32Array(size * size);
|
||||
const section = new Uint8Array(size * CHUNK_HEIGHT);
|
||||
// rows from the top of the world down
|
||||
const section = new Uint8Array(size * shape.height);
|
||||
const section_z = size / 2;
|
||||
const origin = -size / 2;
|
||||
const counts = new Map<number, number>();
|
||||
@@ -229,20 +236,20 @@ const shade = (color: [number, number, number], factor: number): [number, number
|
||||
for (let lx = 0; lx < CHUNK_SIZE; lx++) {
|
||||
const px = cx * CHUNK_SIZE + lx;
|
||||
const pz = cz * CHUNK_SIZE + lz;
|
||||
let y = CHUNK_HEIGHT - 1;
|
||||
let y = shape.max_y - 1;
|
||||
let depth = 0;
|
||||
while (y > 0) {
|
||||
const b = blocks[y * CHUNK_AREA + lz * CHUNK_SIZE + lx];
|
||||
while (y > shape.min_y) {
|
||||
const b = blocks[at(lx, y, lz)];
|
||||
if (b === block_ids["bworld:water"]) depth++;
|
||||
else if (b !== 0) break;
|
||||
y--;
|
||||
}
|
||||
top[pz * size + px] = y;
|
||||
top_block[pz * size + px] = blocks[y * CHUNK_AREA + lz * CHUNK_SIZE + lx];
|
||||
top_block[pz * size + px] = blocks[at(lx, y, lz)];
|
||||
water_depth[pz * size + px] = depth;
|
||||
let seen_ground = false;
|
||||
for (let yy = CHUNK_HEIGHT - 1; yy >= 0; yy--) {
|
||||
const b = blocks[yy * CHUNK_AREA + lz * CHUNK_SIZE + lx];
|
||||
for (let yy = shape.max_y - 1; yy >= shape.min_y; yy--) {
|
||||
const b = blocks[at(lx, yy, lz)];
|
||||
counts.set(b, (counts.get(b) ?? 0) + 1);
|
||||
if (b !== 0 && b !== block_ids["bworld:water"]) {
|
||||
seen_ground = true;
|
||||
@@ -250,7 +257,7 @@ const shade = (color: [number, number, number], factor: number): [number, number
|
||||
} else if (seen_ground && b === 0) {
|
||||
underground_air++;
|
||||
}
|
||||
if (pz === section_z) section[(CHUNK_HEIGHT - 1 - yy) * size + px] = b;
|
||||
if (pz === section_z) section[(shape.max_y - 1 - yy) * size + px] = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,16 +280,13 @@ const shade = (color: [number, number, number], factor: number): [number, number
|
||||
}
|
||||
await write_png(`${out}/blocks.png`, size, size, rgb);
|
||||
|
||||
const section_rgb = new Uint8Array(size * CHUNK_HEIGHT * 3);
|
||||
for (let i = 0; i < size * CHUNK_HEIGHT; i++) {
|
||||
const section_rgb = new Uint8Array(size * shape.height * 3);
|
||||
for (let i = 0; i < size * shape.height; i++) {
|
||||
section_rgb.set(section[i] === 0 ? [30, 30, 40] : COLORS[section[i]] ?? [255, 0, 255], i * 3);
|
||||
if (section[i] === 0 && Math.floor(i / size) < CHUNK_HEIGHT - 1 - SEA_LEVEL + 1) {
|
||||
// sky
|
||||
const row = Math.floor(i / size);
|
||||
if (row < CHUNK_HEIGHT - SEA_LEVEL) section_rgb.set([180, 210, 255], i * 3);
|
||||
}
|
||||
// sky, air from sea level up
|
||||
if (section[i] === 0 && Math.floor(i / size) < shape.max_y - SEA_LEVEL) section_rgb.set([180, 210, 255], i * 3);
|
||||
}
|
||||
await write_png(`${out}/section.png`, size, CHUNK_HEIGHT, section_rgb);
|
||||
await write_png(`${out}/section.png`, size, shape.height, section_rgb);
|
||||
|
||||
console.log(`blocks.png: ${chunks * chunks} chunks, ${(took / (chunks * chunks)).toFixed(2)} ms per chunk`);
|
||||
console.log(`underground air: ${(underground_air / (solid + underground_air) * 100).toFixed(1)}% of the ground`);
|
||||
|
||||
Reference in New Issue
Block a user