public class StreamingTerrain

  1. Object
  2. StreamingTerrain

ImplementsTerrain

An unbounded Terrain that pages TerrainChunks in and out through a ChunkProvider, keeping at most #getCacheSize() chunks resident (LRU). World cell coordinates may be negative; each maps to a chunk and a local cell. Call #streamAround(int,int,int) as the player moves to pre-load nearby chunks and evict (saving dirty) far ones.

Nested types

class StreamingTerrain.MemoryChunkProviderA trivial in-memory provider: remembers chunks it has seen, generates empty flat-grass chunks otherwise.

Constructors

public StreamingTerrain()
public StreamingTerrain(ChunkProvider provider, int cacheSize)

Methods

public int getCacheSize()
public StreamingTerrain setCacheSize(int cacheSize)
public ChunkProvider getProvider()
public TerrainChunk chunk(int cx, int cz)Returns the resident chunk for the given chunk coords, loading it on demand.
public float getHeight(int x, int z)
public void setHeight(int x, int z, float height)
public boolean hasGround(int x, int z)
public String getMaterial(int x, int z)Material id at the cell (resolve via MaterialRegistry).
public void setMaterial(int x, int z, String materialId)
public List<TerrainFeature> features()Features whose anchor cell is currently loaded.
public void addFeature(TerrainFeature feature)Adds a feature, routing it to the chunk that owns its position.
public boolean isBounded()True for a fixed-size terrain (#getCols()/#getRows() valid), false if unbounded.
public int getCols()Column count for a bounded terrain, or -1 if unbounded.
public int getRows()Row count for a bounded terrain, or -1 if unbounded.
public void streamAround(int cellX, int cellZ, int radius)Pre-loads the (2*radius+1)^2 chunks around the given cell so movement is seamless; the LRU cache evicts (and saves) chunks that fall out of range.
public void flush()Persists every dirty resident chunk through the provider.
public int loadedChunkCount()
public List<TerrainChunk> residentChunks()The currently-resident chunks (snapshot) – used to persist a small region inline.

Inherited fields

Inherited methods

Constructor details

StreamingTerrain

public StreamingTerrain()

StreamingTerrain

public StreamingTerrain(ChunkProvider provider, int cacheSize)

Method details

getCacheSize

public int getCacheSize()

setCacheSize

public StreamingTerrain setCacheSize(int cacheSize)

getProvider

public ChunkProvider getProvider()

chunk

public TerrainChunk chunk(int cx, int cz)
Returns the resident chunk for the given chunk coords, loading it on demand.

getHeight

public float getHeight(int x, int z)

setHeight

public void setHeight(int x, int z, float height)

hasGround

public boolean hasGround(int x, int z)

getMaterial

public String getMaterial(int x, int z)
Material id at the cell (resolve via MaterialRegistry).

setMaterial

public void setMaterial(int x, int z, String materialId)

features

public List<TerrainFeature> features()
Features whose anchor cell is currently loaded.

addFeature

public void addFeature(TerrainFeature feature)
Adds a feature, routing it to the chunk that owns its position.

isBounded

public boolean isBounded()
True for a fixed-size terrain (#getCols()/#getRows() valid), false if unbounded.

getCols

public int getCols()
Column count for a bounded terrain, or -1 if unbounded.

getRows

public int getRows()
Row count for a bounded terrain, or -1 if unbounded.

streamAround

public void streamAround(int cellX, int cellZ, int radius)
Pre-loads the (2*radius+1)^2 chunks around the given cell so movement is seamless; the LRU cache evicts (and saves) chunks that fall out of range.

flush

public void flush()
Persists every dirty resident chunk through the provider.

loadedChunkCount

public int loadedChunkCount()

residentChunks

public List<TerrainChunk> residentChunks()
The currently-resident chunks (snapshot) – used to persist a small region inline.