API reference / @jsprismarine/worldgen / CornerCache
Class: CornerCache
Defined in: density/SampleContext.ts:76
The cell-corner values an interpolated function has already computed.
Corners sit on a regular lattice, so the slot is the cell index masked per axis rather than a hash of the position. A chunk's lattice is 5 by 5 cells across and 49 up at vanilla's cell size, which lands inside one window of the 8 by 8 by 64 the masks carve out, so no two corners a chunk is working on can collide. A hashed index collided often enough to compute a chunk's 1225 corners 6139 times, and a corner is the most expensive thing the density stack does.
The window is sized to that working set and no larger, because every interpolated node builds one of these per chunk and the zeroing and collection of the buffers is paid per chunk too. The cache is direct-mapped, so a position outside the window evicts rather than grows, and the stored cell indices are compared exactly before a value is reused. Eviction costs a recomputation, never an answer, because a density function tree is deterministic for one context. Java fills a whole cell grid up front; this covers the same working set without having to visit the chunk in Java's cell order.
Constructors
Constructor
new CornerCache():
CornerCache
Returns
CornerCache
Methods
clear()
clear():
void
Defined in: density/SampleContext.ts:122
Drops every memoized corner.
Returns
void
getOrCompute()
getOrCompute(
context,input,cellX,cellY,cellZ,x,y,z):number
Defined in: density/SampleContext.ts:89
Returns the corner value, computing it through input when the slot does not hold it.
Parameters
context
input
cellX
number
The corner's lattice index across x, which is x / cellSizeXz. The caller already has it, and passing it keeps the division out of this path.
cellY
number
cellZ
number
x
number
y
number
z
number
Returns
number