Class StreamingTerrain
java.lang.Object
com.codename1.gaming.level.StreamingTerrain
- All Implemented Interfaces:
Terrain
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 Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA trivial in-memory provider: remembers chunks it has seen, generates empty flat-grass chunks otherwise. -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFeature(TerrainFeature feature) Adds a feature, routing it to the chunk that owns its position.chunk(int cx, int cz) Returns the resident chunk for the given chunk coords, loading it on demand.features()Features whose anchor cell is currently loaded.voidflush()Persists every dirty resident chunk through the provider.intintgetCols()Column count for a bounded terrain, or -1 if unbounded.floatgetHeight(int x, int z) getMaterial(int x, int z) Material id at the cell (resolve viaMaterialRegistry).intgetRows()Row count for a bounded terrain, or -1 if unbounded.booleanhasGround(int x, int z) booleanTrue for a fixed-size terrain (#getCols()/#getRows()valid), false if unbounded.intThe currently-resident chunks (snapshot) -- used to persist a small region inline.setCacheSize(int cacheSize) voidsetHeight(int x, int z, float height) voidsetMaterial(int x, int z, String materialId) voidstreamAround(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.
-
Constructor Details
-
StreamingTerrain
public StreamingTerrain() -
StreamingTerrain
-
-
Method Details
-
getCacheSize
public int getCacheSize() -
setCacheSize
-
getProvider
-
chunk
Returns the resident chunk for the given chunk coords, loading it on demand. -
getHeight
-
setHeight
-
hasGround
-
getMaterial
Description copied from interface:TerrainMaterial id at the cell (resolve viaMaterialRegistry).- Specified by:
getMaterialin interfaceTerrain
-
setMaterial
- Specified by:
setMaterialin interfaceTerrain
-
features
Description copied from interface:TerrainFeatures whose anchor cell is currently loaded. -
addFeature
Description copied from interface:TerrainAdds a feature, routing it to the chunk that owns its position.- Specified by:
addFeaturein interfaceTerrain
-
isBounded
-
getCols
-
getRows
-
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
The currently-resident chunks (snapshot) -- used to persist a small region inline.
-