Skip to main content

FastChunkLookup

A class in Root.Township, Alta.Chunks.

Fast lookup from positions or bounds to location chunks. Overworld chunks sit in a grid indexed by position; other chunks (caves and so on) are checked one by one. LocationChunkHelper holds the one the game uses.

Constructors​

MemberWhat it is
FastChunkLookup(IEnumerable<LocationChunk> chunks)Creates a FastChunkLookup from chunks.

Fields​

8 private and internal fields
MemberWhat it is
private float chunkSizeWidth of one overworld chunk, taken from the first grid chunk's bounds.
private int chunksPerSideNumber of overworld chunks along each side of the square grid.
private Vector3 mapOriginMinimum corner of the overworld grid in world space.
private float maxYTop of the overworld chunks' bounds. Positions above it skip the grid lookup.
private float minYBottom of the overworld chunks' bounds. Positions below it skip the grid lookup.
private Bounds otherChunkBoundsBounds that enclose all non-overworld chunks, rebuilt by ResetOtherChunksBounds.
private HashSet<LocationChunk> otherChunksLocation chunks that aren't part of the overworld grid. These are checked one by one by bounds.
private OverworldChunk[,] overworldChunksThe overworld chunks as a 2D grid by x and z index, for direct lookup by position.

Properties​

MemberWhat it is
static FastChunkLookup EmptyLookup { get; }A shared lookup with no chunks.

Methods​

MemberWhat it is
void DeregisterOtherChunk(LocationChunk chunk)Removes a non-overworld chunk from the lookup.
IEnumerable<LocationChunk> GetAllChunksByIndex(int xIndex, int zIndex, int xMaxIndex, int zMaxIndex) (iterator)Overworld chunks in a range of grid indexes, clamped to the grid.
IEnumerable<LocationChunk> GetAllChunksContainingPosition(Vector3 position, LocationChunk currentChunk = null) (iterator)Chunks whose bounds contain the position. Checks the current chunk and its neighbours first and stops there if any match.
IEnumerable<LocationChunk> GetAllChunksIntersectingBounds(Bounds bounds) (iterator)Overworld grid chunks overlapping the bounds, plus other chunks that intersect them.
LocationChunk GetBestChunkContainingPosition(Vector3 position, LocationChunk currentChunk = null)The highest priority chunk containing the position, or null.
LocationChunk GetBestChunkIntersectingBounds(Bounds bounds)The highest priority chunk intersecting the bounds, or null.
void GetChunksToLoadWithinRadius(OverworldChunk center, float radius, HashSet<Chunk> result)Adds overworld chunks within a radius (in chunks) of a centre chunk to the set, plus chunks reached through forced adjacent connections.
OverworldChunk GetOverworldChunkAtPosition(Vector3 position)The overworld grid chunk at the position, or null if it is outside the grid or its height range.
bool IsInOverworldChunk(Vector3 position)True unless the position is inside a non-overworld chunk.
bool IsOutdated()True if the grid is empty or its first chunk has been destroyed.
void RegisterOtherChunk(LocationChunk chunk)Adds a non-overworld chunk to the lookup.
void RemoveOtherChunk(LocationChunk otherChunk)Same as DeregisterOtherChunk.
void ResetOtherChunksBounds()Recomputes the combined bounds of all non-overworld chunks.
4 private and internal methods
MemberWhat it is
private void AddChunksInGrid(HashSet<Chunk> chunks, int xMin, int xMax, int z, int xCenter, int zCenter, float totalRadius)Adds one row of overworld chunks to the load set, and follows each chunk's forced-adjacent connections with the remaining radius budget.
private static LocationChunk GetBestChunk(IEnumerable<LocationChunk> chunks)Returns the chunk with the highest Priority from a list, or null.
private int GetXIndex(float x)Converts a world x position to an overworld grid column.
private int GetZIndex(float z)Converts a world z position to an overworld grid row.

Used in​

Members of other types that take, return or hold a FastChunkLookup: