LayerProcGen v0.1.0
Layer-based infinite procedural generation
Loading...
Searching...
No Matches
ChunkBasedDataLayer< L, C >abstract

In a layer-and-chunk pair of classes, the layer inherits from this class. More...

Inherits AbstractChunkBasedDataLayer, and IChunkBasedDataLayer.

Public Member Functions

virtual int GetLevelCount ()
 Override to specify the number of generation levels in the layer. Default is 1.
 
int GetLevelCount ()
 
void HandleAllAbstractChunks (int minChunkLevel, Action< AbstractLayerChunk > func)
 Handle all loaded chunks.
 
void HandleDependenciesForLevel (int level, Action< LayerDependency > func)
 Handle all layer dependencies.
 
bool IsLoadedAtPosition (DPoint position)
 Returns true if the layer is loaded at the highest level at the specified position in world units.
 
bool IsLoadedAtPosition (DPoint position, int level)
 Returns true if the layer is loaded at least up to level at the specified position in world units.
 

Static Public Member Functions

static bool HasLayer< T > ()
 Check if a layer of the specified type exists without creating it as a side effect.
 

Protected Member Functions

void AddLayerDependency (int ownLevel, LayerDependency dependency)
 Call from constructor to add a dependency on another layer. The dependency is added to the specified ownLevel of the current layer.
 
void AddLayerDependency (LayerDependency dependency)
 Call from constructor to add a dependency on another layer. The dependency is added to the lowest level of the current layer.
 
 ChunkBasedDataLayer (int rollingGridWidth=32, int rollingGridHeight=0, int rollingGridMaxOverlap=3)
 The layer constructor in inherited classes can be used to setup dependencies on other layers.
 
bool GetChunkOfGridPoint (ILC q, int x, int y, int chunkGridW, int chunkGridH, out C chunk, out Point localPointInChunk)
 Assuming an infinite grid with a resolution per chunk of chunkGridW by chunkGridH , output the chunk and localPointInChunk of the given global point. If iterating over many grid points, consider instead using HandleGridPoints.
 
bool GetChunkOfGridPoint (ILC q, Point gridPoint, Point chunkGridSize, out C chunk, out Point localPointInChunk)
 Assuming an infinite grid with a resolution per chunk of chunkGridSize , output the chunk and localPointInChunk of the given global gridPoint . If iterating over many grid points, consider instead using HandleGridPoints.
 
void HandleAllChunks (int minChunkLevel, Action< C > func)
 Handle all loaded chunks.
 
void HandleChunksInBounds (ILC q, GridBounds worldBounds, int minChunkLevel, Action< C > func)
 Handle chunks that overlap the given worldBounds specified in world units.
 
delegate void HandleGridPointInChunk (C chunk, Point localPointInChunk, Point globalPoint)
 
void HandleGridPoints (ILC q, GridBounds gridBounds, Point chunkGridSize, HandleGridPointInChunk handler, bool callForNullChunks=false)
 Assuming an infinite grid with a resolution per chunk of chunkGridSize , call the handler function once for each of the grid points within the gridBounds . This is more efficient than calling GetChunkOfGridPoint for each grid point.
 
bool TryGetChunk (Point index, out C chunk, int level=0)
 Try to get the chunk at the specified index.
 
void WarnAboutMissingDependencies (ILC q, GridBounds requested)
 Call this method if a chunk q has called methods that rely on other chunks that are not currently generated. Based on the bounds of q and the requested world bounds of the current layer, the method will calculate which layer dependency has to be added to ensure the required chunks are generated in time.
 

Protected Attributes

readonly RollingGrid< C > chunks
 
readonly List< LayerDependency >[] dependencies
 

Properties

int chunkH [get]
 
int chunkH [get]
 
Point chunkSize [get]
 
Point chunkSize [get]
 
int chunkW [get]
 
int chunkW [get]
 
static L instance [get]
 
static IEnumerable< AbstractDataLayerlayers [get]
 An enumeration of all current layers.
 

Detailed Description

In a layer-and-chunk pair of classes, the layer inherits from this class.

Template Parameters
LThe layer class itself.
CThe corresponding chunk class.
Type Constraints
L :ChunkBasedDataLayer 
L :L 
L :C 
L :new() 
C :LayerChunk 
C :L 
C :C 
C :new() 

Constructor & Destructor Documentation

◆ ChunkBasedDataLayer()

ChunkBasedDataLayer ( int rollingGridWidth = 32,
int rollingGridHeight = 0,
int rollingGridMaxOverlap = 3 )
protected

The layer constructor in inherited classes can be used to setup dependencies on other layers.

Parameters
rollingGridWidthThe width of the rolling grid the chunks are stored in. The default is 32.
rollingGridHeightThe height of the rolling grid the chunks are stored in. If set to 0, the value of rollingGridWidth is used. The default is 0.
rollingGridMaxOverlapThe max overlap of the rolling grid the chunks are stored in. The default is 3.

Member Function Documentation

◆ HandleAllAbstractChunks()

void HandleAllAbstractChunks ( int minChunkLevel,
Action< AbstractLayerChunk > func )

Handle all loaded chunks.

Implements IChunkBasedDataLayer.

◆ HandleDependenciesForLevel()

void HandleDependenciesForLevel ( int level,
Action< LayerDependency > func )

Handle all layer dependencies.

Implements IChunkBasedDataLayer.

◆ HasLayer< T >()

static bool HasLayer< T > ( )
staticinherited

Check if a layer of the specified type exists without creating it as a side effect.

Type Constraints
T :AbstractDataLayer 

◆ IsLoadedAtPosition() [1/2]

bool IsLoadedAtPosition ( DPoint position)

Returns true if the layer is loaded at the highest level at the specified position in world units.

Implements IChunkBasedDataLayer.

◆ IsLoadedAtPosition() [2/2]

bool IsLoadedAtPosition ( DPoint position,
int level )

Returns true if the layer is loaded at least up to level at the specified position in world units.

Implements IChunkBasedDataLayer.

◆ TryGetChunk()

bool TryGetChunk ( Point index,
out C chunk,
int level = 0 )
protected

Try to get the chunk at the specified index.

Parameters
indexAn integer coordinate that indexes into the grid of chunks.
chunkThe requested chunk, or null.
Returns
True if the chunk exists and has been generated to at least level 0.