API reference / @jsprismarine/chunkgen / ChunkHolderMap
Class: ChunkHolderMap<TChunk>
Defined in: ChunkHolderMap.ts:18
The holders a generation run is working on, kept alive by reference count.
This replaces the generator's 128-entry LRU of neighbor terrain. An LRU is the wrong retention rule here for a reason that is measurable rather than stylistic: preload-radius: 5 is 121 chunks, which sits right at the edge of 128, so a feature pass's write into a neighbor could land on a holder that had already been evicted and silently do nothing. A count answers the question that actually matters, which is whether anything still needs the chunk.
Java spends a ticket level on the same job. The shape here is the narrow part of that: a generation task acquires every holder inside its radius before it runs a single step, and releases them all when it finishes, so nothing it depends on can be dropped while it is in flight. A caller that wants a chunk to stay resident past a run acquires its own reference.
Type Parameters
TChunk
TChunk extends StagedChunk
Constructors
Constructor
new ChunkHolderMap<
TChunk>(newChunk):ChunkHolderMap<TChunk>
Defined in: ChunkHolderMap.ts:26
Parameters
newChunk
(chunkX, chunkZ) => TChunk
Allocates the chunk a new holder starts from, called once per holder on its first step. The server passes the dimension's build height through here, and a test passes a short column.
Returns
ChunkHolderMap<TChunk>
Accessors
size
Get Signature
get size():
number
Defined in: ChunkHolderMap.ts:29
How many holders are retained. Zero after every task has released what it took.
Returns
number
Methods
acquire()
acquire(
chunkX,chunkZ):ChunkHolder<TChunk>
Defined in: ChunkHolderMap.ts:48
Takes a reference on a chunk's holder, creating the holder when this is the first one.
Parameters
chunkX
number
chunkZ
number
Returns
ChunkHolder<TChunk>
The holder, which the caller must release exactly once.
acquireSquare()
acquireSquare(
centerX,centerZ,radius): readonlyChunkHolder<TChunk>[]
Defined in: ChunkHolderMap.ts:86
Takes a reference on every chunk in the square of radius chunks around a center.
Java's ChunkGenerationTask.create fills a StaticCache2D the same way and for the same reason: a task that acquired its neighborhood lazily could find a holder it is about to read dropped by whichever task released last.
Parameters
centerX
number
centerZ
number
radius
number
Returns
readonly ChunkHolder<TChunk>[]
The holders, row major with x ascending fastest, each owing one release.
get()
get(
chunkX,chunkZ):ChunkHolder<TChunk> |undefined
Defined in: ChunkHolderMap.ts:34
The holder for a chunk, or undefined when nothing retains it.
Parameters
chunkX
number
chunkZ
number
Returns
ChunkHolder<TChunk> | undefined
release()
release(
chunkX,chunkZ):boolean
Defined in: ChunkHolderMap.ts:65
Gives back a reference, dropping the holder when it was the last one.
Parameters
chunkX
number
chunkZ
number
Returns
boolean
Whether the holder was dropped.
Throws
RangeError when nothing holds a reference on that chunk, which means a task released twice and the next release would drop a holder another task is reading.
releaseAll()
releaseAll(
holders):void
Defined in: ChunkHolderMap.ts:95
Gives back one reference on each of the holders, dropping those that reach zero.
Parameters
holders
Iterable<ChunkHolder<TChunk>>
Returns
void
values()
values():
IterableIterator<ChunkHolder<TChunk>>
Defined in: ChunkHolderMap.ts:39
Every retained holder, in the order the holders were created.
Returns
IterableIterator<ChunkHolder<TChunk>>