World sections
This commit is contained in:
+11
-6
@@ -6,6 +6,7 @@
|
||||
import { Alea } from "@paulaboks/rng";
|
||||
import { AIR, CHUNK_AREA, CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
|
||||
import type { WorldShape } from "@/common/world_shape.ts";
|
||||
import { ChunkColumn } from "@/common/section.ts";
|
||||
import type { FeatureChunk, Position } from "@/common/mod_api/worldgen.ts";
|
||||
import type { OreJson } from "@/common/mod_data.ts";
|
||||
import { generate_noise_chunk } from "./worldgen/noise_chunk.ts";
|
||||
@@ -37,17 +38,20 @@ export interface SetupFeature {
|
||||
}
|
||||
|
||||
export interface RawChunk {
|
||||
// numeric block ids, only what this chunk generated itself, indexed (y - min_y) * CHUNK_AREA + z * CHUNK_SIZE + x
|
||||
blocks: Uint32Array;
|
||||
// only what this chunk generated itself, with each column's biome
|
||||
column: ChunkColumn;
|
||||
// blocks it generated in other chunks (from features like a mod's trees), flattened as x, y, z, numeric id
|
||||
spills: Int32Array;
|
||||
// each column's biome id, x then z
|
||||
biomes: string[];
|
||||
}
|
||||
|
||||
// features that threw, so each is only reported once
|
||||
const failed_features = new Set<string>();
|
||||
|
||||
// what a chunk is generated into before it's made sections, indexed (y - min_y) * CHUNK_AREA + z * CHUNK_SIZE + x. a
|
||||
// column at a time is how terrain is worked out, and features set blocks one at a time. kept for the next chunk, so
|
||||
// generating isn't reentrant
|
||||
let scratch = new Uint32Array(0);
|
||||
|
||||
// generates one chunk on its own. neighbors' spills get merged in by whoever assembles the world:
|
||||
// a chunk's own blocks always win and spills only fill air, so the result doesn't depend on load order
|
||||
export function generate_raw_chunk(
|
||||
@@ -60,7 +64,8 @@ export function generate_raw_chunk(
|
||||
default_values?: number[],
|
||||
): RawChunk {
|
||||
const shape = worldgen.shape;
|
||||
const blocks = new Uint32Array(shape.volume);
|
||||
if (scratch.length !== shape.volume) scratch = new Uint32Array(shape.volume);
|
||||
const blocks = scratch.fill(AIR);
|
||||
const spills: number[] = [];
|
||||
const heights = new Int32Array(CHUNK_AREA);
|
||||
const biomes: string[] = new Array(CHUNK_AREA);
|
||||
@@ -92,7 +97,7 @@ export function generate_raw_chunk(
|
||||
}
|
||||
generate_features(blocks, heights, biomes, set, chunk_x, chunk_z, seed, block_ids, worldgen);
|
||||
|
||||
return { blocks, spills: new Int32Array(spills), biomes };
|
||||
return { column: ChunkColumn.from_flat(chunk_x, chunk_z, shape, blocks, biomes), spills: new Int32Array(spills) };
|
||||
}
|
||||
|
||||
// each block an ore replaces becomes the first ore whose noise is above its threshold
|
||||
|
||||
Reference in New Issue
Block a user