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.
- Listed in World generation
- Inherits or implements
NetworkEntityBehaviour,IGenerator
Constructors
| Member | What it is |
|---|---|
GenerationBase() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
17 private and internal fields
| Member | What it is |
|---|---|
private MapChunk[,] chunks | Grid of generated map chunks. |
private int chunksGenerating | Number of map chunks still generating. |
private int chunksHigh | Map chunks along Z. |
private int chunkSize | Size of one map chunk in local units. |
private Transform chunksParent | Parent object for the map chunks. |
private int chunksWide | Map chunks along X. |
private MethodSyncStruct<CaveSeedArguments> clientSpawn | Method sync that sends the seed to clients. |
private IEnumerator<bool> currentRendering | The chunk render step in progress. |
private Transform deletingEntities | Declared but not used. |
private Plugin floorPlugin | The plugin for the cave floor. |
private bool isGenerationStarted | Set once generation starts; late joiners then get the seed on connect. |
private bool isSeedRandomOnRegenerate | Declared but not used. |
private static Logger logger | NLog logger for generation progress and errors. |
private PluginList pluginList | Plugins that generate and render each chunk, in order. |
private List<MapChunk> rendering | Chunks waiting to be rendered, sorted by request count. |
private int seed | Generation seed; a negative value picks a random one at start. |
private int stepIndex | Declared but not used. |
Properties
| Member | What 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
| Member | What it is |
|---|---|
event Action RenderingComplete | Raised once when all chunks are generated and rendered. |
Methods
| Member | What 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
| Member | What 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: