Skip to main content

MapChunk

A class in Root.Township, Alta.Caves.

One square of a cave generator's map. It holds a MapChunkLayer per plugin, runs its generation on a worker thread, then hands itself to the generator to render through MapChunkDisplay objects.

Constructors​

MemberWhat it is
MapChunk()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

3 private and internal fields
MemberWhat it is
private List<MapChunkDisplay> displaysBacking field for Displays: displays spawned by Render.
private ChunkThread generationThreadBackground thread generating this chunk's layers. Null once it finishes.
private Dictionary<Plugin, MapChunkLayer> layersOne layer of values per plugin, added by AddLayer and read by GetLayer.

Properties​

MemberWhat it is
List<MapChunkDisplay> Displays { get; }Displays spawned to render this chunk.
IGenerator Generator { get; private set; }The generator this chunk belongs to.
int OffX { get; private set; }X offset in cells: X times the chunk size.
int OffZ { get; private set; }Z offset in cells: Z times the chunk size.
GenerationBase RenderGenerator { get; private set; }The generator as a GenerationBase, or null.
int RequestCount { get; set; }Number of outstanding requests for this chunk.
int X { get; private set; }Chunk grid x.
int Z { get; private set; }Chunk grid z.

Methods​

MemberWhat it is
void AddLayer(PluginInstance pluginInstance)Adds a layer for a plugin instance.
void Clear()Disposes all layers.
void CreateAllNonZeroLists()Builds the non-zero cell list on every layer.
MapChunkLayer GetLayer(Plugin plugin)The layer for a plugin. Throws if there is none.
ChunkThread Initialize(IGenerator generator, int x, int z)Sets the generator and grid position, works out the offsets and creates the generation thread.
void Prepare()Clears any old layers and starts a fresh set.
IEnumerator Render(PluginInstance pluginInstance, MapChunkDisplay displayPrefab, int renderIndex)Spawns a display for a plugin's layer and returns its render coroutine, or null without a prefab.
2 private and internal methods
MemberWhat it is
private void OnDestroy()Aborts a running generation thread and releases its layers and displays.
private void Update()Waits for the generation thread to finish, then turns itself off and asks the generator to render the chunk.

Used in​

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