Table of Contents

Class ChunkStorage

Namespace
Shard.Gameplay.Universe.World.Chunks
Assembly
Shard.Gameplay.Universe.dll

In-memory store of a world's cubic chunks: holds loaded BlockChunks and generates them on first access (via the TerrainGenerator) for any position inside Bounds. A position outside the bounds has no chunk (the world ends there).

This is the interim holder — persistence (load/save from disk) is being built separately (Nullicorn's ChunkStorage); this generate-on-miss cache slots behind that when it lands, so the rest of the world/ streaming code depends on this shape, not on where a chunk came from.

public sealed class ChunkStorage
Inheritance
ChunkStorage
Inherited Members

Constructors

ChunkStorage(TerrainGenerator, WorldBounds)

In-memory store of a world's cubic chunks: holds loaded BlockChunks and generates them on first access (via the TerrainGenerator) for any position inside Bounds. A position outside the bounds has no chunk (the world ends there).

This is the interim holder — persistence (load/save from disk) is being built separately (Nullicorn's ChunkStorage); this generate-on-miss cache slots behind that when it lands, so the rest of the world/ streaming code depends on this shape, not on where a chunk came from.

public ChunkStorage(TerrainGenerator generator, WorldBounds bounds)

Parameters

generator TerrainGenerator
bounds WorldBounds

Properties

Bounds

The world's chunk-space extent; null sides are unbounded.

public WorldBounds Bounds { get; }

Property Value

WorldBounds

LoadedCount

How many chunks are currently resident in memory.

public int LoadedCount { get; }

Property Value

int

LoadedPositions

A snapshot of the currently-resident chunk positions (safe to iterate while others load/unload).

public IReadOnlyCollection<ChunkPos> LoadedPositions { get; }

Property Value

IReadOnlyCollection<ChunkPos>

Methods

Get(ChunkPos)

The chunk at position, generating (and caching) it on first access. Returns null when the position is outside Bounds — there is no world there.

public BlockChunk? Get(ChunkPos position)

Parameters

position ChunkPos

Returns

BlockChunk

IsInBounds(ChunkPos)

Whether a position lies inside the world (i.e. a chunk can exist there).

public bool IsInBounds(ChunkPos position)

Parameters

position ChunkPos

Returns

bool

TryGetLoaded(ChunkPos, out BlockChunk?)

The chunk only if it is already resident (no generation).

public bool TryGetLoaded(ChunkPos position, out BlockChunk? chunk)

Parameters

position ChunkPos
chunk BlockChunk

Returns

bool

Unload(ChunkPos)

Evict a chunk from memory. Returns whether it was resident.

public bool Unload(ChunkPos position)

Parameters

position ChunkPos

Returns

bool