Computes the cumulative distribution function of the weighted sum of k
independent, uniformly distributed random variables between 0 and 1. For
each variable i, we use weights[i]
as the weight to give samples[i]
(the
weights should all be positive).
Compute the neighbor “most downhill” from all chunks.
Finds the horizon map for sunlight for the given chunks.
Find all ocean tiles from a height map, using an inductive definition of
ocean as one of:
Iterate through all cells adjacent and including four chunks whose top-left
point is posi. This isn’t just the immediate neighbors of a chunk plus the
center, because it is designed to cover neighbors of a point in the chunk’s
“interior.”
Calculates the smallest distance along an axis (x, y) from an edge of
the world. This value is maximal at map_size_lg.chunks() / 2 and
minimized at the
extremes (0 or map_size_lg.chunks() on one or more axes). It then divides
the quantity by cell_size, so the final result is 1 when we are not in a
cell along the edge of the world, and ranges between 0 and 1 otherwise
(lower when the chunk is closer to the edge).
Compute inverse cumulative distribution function for arbitrary function f,
the hard way. We pre-generate noise values prior to worldgen, then sort
them in order to determine the correct position in the sorted order. That
lets us use (index + 1) / (WORLDSIZE.y * WORLDSIZE.x)
as a uniformly
distributed (from almost-0 to 1) regularization of the chunks. That is, if
we apply the computed “function” F⁻¹(x, y) to (x, y) and get out p, it means
that approximately (100 * p)% of chunks have a lower value for F⁻¹ than p.
The main purpose of doing this is to make sure we are using the entire range
we want, and to allow us to apply the numerous results about distributions
on uniform functions to the procedural noise we generate, which lets us much
more reliably control the number of features in the world while still
letting us play with the shape of those features, without having arbitrary
cutoff points / discontinuities (which tend to produce ugly-looking /
unnatural terrain).