Rework biome generation according to tectonic
This commit is contained in:
+16
-21
@@ -1,30 +1,24 @@
|
||||
// minecraft's CubicSpline: a smooth curve through points, where a point's value can itself be a spline of another
|
||||
// input. that nesting is how its terrain (and terralith's) turns continentalness, erosion and peaks and valleys into
|
||||
// heights: a spline over continentalness whose points are splines over erosion, whose points are splines over pv
|
||||
// input. that nesting is how its terrain (and tectonic's) turns continentalness, erosion and ridges into heights:
|
||||
// a spline over continentalness whose points are splines over erosion, whose points are splines over ridges.
|
||||
// K names the inputs, see TerrainInputs
|
||||
|
||||
export interface SplineInputs {
|
||||
continentalness: number;
|
||||
erosion: number;
|
||||
pv: number;
|
||||
weirdness: number;
|
||||
}
|
||||
export type SplineValue<K extends string> = number | Spline<K>;
|
||||
|
||||
export type SplineValue = number | Spline;
|
||||
|
||||
export interface SplinePoint {
|
||||
export interface SplinePoint<K extends string> {
|
||||
at: number;
|
||||
value: SplineValue;
|
||||
value: SplineValue<K>;
|
||||
// the slope there, worked out from the neighbors when not given
|
||||
slope?: number;
|
||||
}
|
||||
|
||||
export class Spline {
|
||||
readonly input: keyof SplineInputs;
|
||||
export class Spline<K extends string> {
|
||||
readonly input: K;
|
||||
#locations: number[];
|
||||
#values: SplineValue[];
|
||||
#values: SplineValue<K>[];
|
||||
#slopes: number[];
|
||||
|
||||
constructor(input: keyof SplineInputs, points: SplinePoint[]) {
|
||||
constructor(input: K, points: SplinePoint<K>[]) {
|
||||
this.input = input;
|
||||
this.#locations = points.map((point) => point.at);
|
||||
this.#values = points.map((point) => point.value);
|
||||
@@ -40,7 +34,7 @@ export class Spline {
|
||||
});
|
||||
}
|
||||
|
||||
get(inputs: SplineInputs): number {
|
||||
get(inputs: Readonly<Record<K, number>>): number {
|
||||
const x = inputs[this.input];
|
||||
const locations = this.#locations;
|
||||
const last = locations.length - 1;
|
||||
@@ -67,11 +61,12 @@ export class Spline {
|
||||
}
|
||||
}
|
||||
|
||||
function value_of(value: SplineValue, inputs: SplineInputs) {
|
||||
function value_of<K extends string>(value: SplineValue<K>, inputs: Readonly<Record<K, number>>) {
|
||||
return typeof value === "number" ? value : value.get(inputs);
|
||||
}
|
||||
|
||||
// a spline through evenly spaced values of one input
|
||||
export function spline(input: keyof SplineInputs, at: number[], values: SplineValue[]) {
|
||||
return new Spline(input, at.map((location, i) => ({ at: location, value: values[i] })));
|
||||
// a spline through points given as [at, value, slope], like minecraft's json with its derivatives. slope is 0 when
|
||||
// left out, like minecraft's
|
||||
export function spline<K extends string>(input: K, points: [number, SplineValue<K>, number?][]) {
|
||||
return new Spline(input, points.map(([at, value, slope]) => ({ at, value, slope: slope ?? 0 })));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user