LayerProcGen v0.1.0
Layer-based infinite procedural generation
Loading...
Searching...
No Matches
AbstractLayerChunkabstract

Internal. Non-generic class that LayerChunk inherits from. More...

Inherits ILC, and IPoolable.

Inherited by LayerChunk< L, C >.

Public Member Functions

virtual void Create (int level, bool destroy)
 Create or destroy the specified level of this chunk.
 
virtual void Reset ()
 Called by the pool when this IPoolable object is returned to the pool.
 
override string ToString ()
 Example output: "[TerrainChunk (3,-4) level 0]".
 

Properties

AbstractChunkBasedDataLayer abstractLayer [get]
 The layer for this chunk type. In derived classes the layer property can be used instead.
 
GridBounds bounds [get]
 The bounds in world space units of this chunk.
 
Point index [get, set]
 The coordinate index this chunk is for.
 
int level = -1 [get, set]
 The level the chunk is currently generated up to (zero-based).
 
Point worldOffset [get]
 The position in world space units of the lower left corner of this chunk.
 

Detailed Description

Internal. Non-generic class that LayerChunk inherits from.

Member Function Documentation

◆ Create()

virtual void Create ( int level,
bool destroy )
virtual

Create or destroy the specified level of this chunk.

Parameters
levelThe level of the chunk to create or destroy.
destroyTrue if destroying, false if creating.

The central method for procedural generation of the chunk.

If the chunk has only one level, the following is a useful pattern for the method. Placing the destruction code before the creation code will tend to place lines of code related to resource use closer to each other.

public override void Create(int level, bool destroy) {
if (destroy) {
// Destroy data for this chunk (or return to pools where applicable).
}
else {
// Generate data for this chunk.
}
}
virtual void Create(int level, bool destroy)
Create or destroy the specified level of this chunk.
Definition LayerChunk.cs:212
int level
The level the chunk is currently generated up to (zero-based).
Definition LayerChunk.cs:74

If the chunk has multiple levels, the following is a useful pattern for the method:

public override void Create(int level, bool destroy) {
if (level == 0) {
if (destroy) {
// Destroy data for level 0 of this chunk (or return to pools where applicable).
}
else {
// Generate data for level 0 of this chunk.
}
}
if (level == 1) {
if (destroy) {
// Destroy data for level 1 of this chunk (or return to pools where applicable).
}
else {
// Generate data for level 1 of this chunk.
}
}
}

◆ Reset()

virtual void Reset ( )
virtual

Called by the pool when this IPoolable object is returned to the pool.

AbstractLayerChunk resets internal chunk state in this method. Derived classes generally don't need to override this method as cleanup should happen in the Create method when the destroy parameter is true. If overriding this method anyway, ensure the the base method is called.

Implements IPoolable.

◆ ToString()

override string ToString ( )

Example output: "[TerrainChunk (3,-4) level 0]".

Returns

Property Documentation

◆ abstractLayer

AbstractChunkBasedDataLayer abstractLayer
getabstract

The layer for this chunk type. In derived classes the layer property can be used instead.

Implements ILC.

◆ bounds

GridBounds bounds
get

The bounds in world space units of this chunk.

Based on worldOffset and layer.chunkSize.

Implements ILC.

◆ index

Point index
getset

The coordinate index this chunk is for.

A 2D index where consecutive chunks have consecutive indexes. The chunk with its lower left corner at the world origin will have index (0, 0). Its neighbor to the left will have index (-1, 0) and to the right (1, 0) etc.

◆ level

int level = -1
getset

The level the chunk is currently generated up to (zero-based).

This property is not updated to a higher level until the call to Create has finished, so do not check it inside the Create method. Use the level parameter of the Create method instead.

◆ worldOffset

Point worldOffset
get

The position in world space units of the lower left corner of this chunk.

Based on index * layer.chunkSize.