Skip to main content

GenerationBase

A class in Root.Township, Alta.Caves.

Generates one procedural cave layer from a seed: splits it into map chunks and runs each generation plugin on them, spread over frames. The server picks the seed and sends it so clients build the same cave.

Constructors​

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

Fields​

17 private and internal fields
MemberWhat it is
private MapChunk[,] chunksGrid of generated map chunks.
private int chunksGeneratingNumber of map chunks still generating.
private int chunksHighMap chunks along Z.
private int chunkSizeSize of one map chunk in local units.
private Transform chunksParentParent object for the map chunks.
private int chunksWideMap chunks along X.
private MethodSyncStruct<CaveSeedArguments> clientSpawnMethod sync that sends the seed to clients.
private IEnumerator<bool> currentRenderingThe chunk render step in progress.
private Transform deletingEntitiesDeclared but not used.
private Plugin floorPluginThe plugin for the cave floor.
private bool isGenerationStartedSet once generation starts; late joiners then get the seed on connect.
private bool isSeedRandomOnRegenerateDeclared but not used.
private static Logger loggerNLog logger for generation progress and errors.
private PluginList pluginListPlugins that generate and render each chunk, in order.
private List<MapChunk> renderingChunks waiting to be rendered, sorted by request count.
private int seedGeneration seed; a negative value picks a random one at start.
private int stepIndexDeclared but not used.

Properties​

MemberWhat it is
MapChunk[,] Chunks { get; }The grid of map chunks, null before generation.
int ChunkSize { get; }Size of one map chunk in generator units.
static GenerationBase CurrentlyRendering { get; set; }The generator allowed to render this frame, so only one renders at a time.
Vector2 Entrance { get; private set; }Where the layer's entrance is.
Vector2 EntranceDirection { get; private set; }Direction of the layer's entrance.
Plugin FloorPlugin { get; }The plugin that makes the floor.
HashFunction HashFunction { get; private set; }Seeded hash function for the plugins, made at generation start.
bool IsGeneratingDynamic { get; }Whether the layer streamer is generating dynamic content.
int Layer { get; private set; }The cave layer number.
CaveLayerStreamer LayerStreamer { get; private set; }The streamer that owns this cave layer.
List<PluginInstance> PluginInstances { get; private set; }One plugin instance per plugin in PluginList, made at generation start.
PluginList PluginList { get; }The plugins that make up this cave.
int Seed { get; set; }The generation seed. A negative value is replaced with a random one at start.
SimplexNoise SimplexNoise { get; private set; }Seeded noise for the plugins, made at generation start.
Vector2 Snap { get; set; }A settable offset; not used inside this class.
SpawnData SpawnData { get; private set; }Spawn data built from the layer's biome.

Events​

MemberWhat it is
event Action RenderingCompleteRaised once when all chunks are generated and rendered.

Methods​

MemberWhat it is
void DecrementGenerating()Called by a map chunk when it finishes generating.
int GetChunkCoord(float position)Map chunk index for a position along one axis.
override void Initialize()Sets up the synced seed message clients use to start generating.
override void OnConnected(Player player)Server: sends the seed and entrance to a player who joins after generation started.
void ReleaseChunk(int x, int y)Drops one request for a map chunk and destroys it when none are left.
void RequestChunk(int x, int y)Creates and starts generating a map chunk, or adds a request to an existing one.
async Task SetupLayer(CaveLayerStreamer streamer, int layer, int seed, Vector2 entrance, Vector2 entranceDirection)Sets the layer, seed, streamer and entrance, then generates.
async Task StartGenerating()Generates every chunk and waits until rendering is complete. The server also sends the seed to clients.
void StartRendering(MapChunk chunk)Queues a generated map chunk for rendering.
8 private and internal methods
MemberWhat it is
private void Clear()Destroys every generated map chunk.
private async void ClientSpawn(IPlayer player, Stream stream, CaveSeedArguments args)Syncs the cave seed, layer and entrance; clients then generate the same layer locally.
private void DecrementSceneLoading()Lowers the scene loading count when rendering completes.
private void OnDestroy()Drops the chunks and plugin instances and clears the layer streamer's static renderers.
private async Task PrepareAndStart()Loads the layer's biome, sets up the environment and chunk parent, then starts generating.
private IEnumerator<bool> Render(MapChunk chunk) (iterator)Runs every plugin's chunk render step by step, then on the server builds pathfinding if needed.
private void Update()Lets one generator at a time run its rendering queue.
private void UpdateRendering()Renders queued chunks within a per-frame time budget and raises RenderingComplete when all are done.

Used in​

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