Skip to main content

LocationChunkHelper

A static class in Root.Township, Alta.Chunks.

Static helpers for finding location chunks by position or bounds, and for working out which chunks to load around one. Wraps a FastChunkLookup.

Fields​

3 private and internal fields
MemberWhat it is
private static FastChunkLookup chunkLookupThe fast spatial lookup used to find chunks by position. Rebuilt in the editor when outdated.
private static bool isDelayingTrue while a delayed reset of the other chunks' bounds is queued, so only one is queued at a time.
private static readonly Logger loggerNLog logger for this class.

Methods​

MemberWhat it is
static void DelayedResetOtherChunksBounds()Recomputes the bounds of non-overworld chunks one frame later, once even if called many times.
static void DeregisterOtherChunk(LocationChunk chunk)Removes a non-overworld chunk from the lookup.
static void EnsureChunkLookupIsSetup()Builds the lookup from every LocationChunk in the scene if it is empty (or outdated, in the editor).
static IEnumerable<LocationChunk> GetAllContaining(Bounds bounds)Every chunk whose bounds intersect the given bounds.
static LocationChunk GetBestContaining(Vector3 position, LocationChunk currentChunk = null)The highest priority chunk containing a position, or null. Passing the current chunk makes it faster.
static void GetChunksToLoad(LocationChunk chunk, HashSet<Chunk> dynamicChunks, HashSet<Chunk> staticChunks)Adds a chunk and its neighbours within a load budget to a set, or fills dynamic and static sets from the chunk's load strengths.
static void GetChunksToLoad(LocationChunk chunk, float remainingLoadBudget, HashSet<Chunk> results)Adds a chunk and its neighbours within a load budget to a set, or fills dynamic and static sets from the chunk's load strengths.
static void GetChunksWithinRadius(OverworldChunk overworldChunk, float distance, HashSet<Chunk> result)Overworld chunks within a radius of an overworld chunk, plus forced adjacent chunks.
static HashSet<Chunk> GetChunksWithinRadius(OverworldChunk overworldChunk, float distance)Overworld chunks within a radius of an overworld chunk, plus forced adjacent chunks.
static ValueTuple<Dictionary<LocationChunk, float>, float> GetChunkWeightingsForPosition(Func<LocationChunk, float> weightAssessing = null)A weight for every content location chunk (1 each by default) and their total, for GetRandomChunkForPosition.
static OverworldChunk GetOverworldChunkAtPosition(Vector3 position)The overworld grid chunk at a position, or null.
static bool GetRandomChunkForPosition(out LocationChunk targetChunk, ValueTuple<Dictionary<LocationChunk, float>, float> weights)Picks a random chunk using the given weights. False if the total weight is 0.
static bool IsInOverworldChunk(Vector3 position)True unless the position is inside a non-overworld chunk (a cave or similar).
static void RegisterOtherChunk(LocationChunk chunk)Adds a non-overworld chunk to the lookup.
static void RemoveOtherChunk(LocationChunk otherChunk)Same as DeregisterOtherChunk.
static void ResetOtherChunksBounds()Recomputes the combined bounds of non-overworld chunks now.
static void SetupChunkLookup(IEnumerable<LocationChunk> allChunks)Replaces the lookup with one built from the given chunks.