Class StreamingTerrain

java.lang.Object
com.codename1.gaming.level.StreamingTerrain
All Implemented Interfaces:
Terrain

public class StreamingTerrain extends Object implements 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.
  • 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)
      Specified by:
      getHeight in interface Terrain
    • setHeight

      public void setHeight(int x, int z, float height)
      Specified by:
      setHeight in interface Terrain
    • hasGround

      public boolean hasGround(int x, int z)
      Specified by:
      hasGround in interface Terrain
    • getMaterial

      public String getMaterial(int x, int z)
      Description copied from interface: Terrain
      Material id at the cell (resolve via MaterialRegistry).
      Specified by:
      getMaterial in interface Terrain
    • setMaterial

      public void setMaterial(int x, int z, String materialId)
      Specified by:
      setMaterial in interface Terrain
    • features

      public List<TerrainFeature> features()
      Description copied from interface: Terrain
      Features whose anchor cell is currently loaded.
      Specified by:
      features in interface Terrain
    • addFeature

      public void addFeature(TerrainFeature feature)
      Description copied from interface: Terrain
      Adds a feature, routing it to the chunk that owns its position.
      Specified by:
      addFeature in interface Terrain
    • isBounded

      public boolean isBounded()
      Description copied from interface: Terrain
      True for a fixed-size terrain (#getCols()/#getRows() valid), false if unbounded.
      Specified by:
      isBounded in interface Terrain
    • getCols

      public int getCols()
      Description copied from interface: Terrain
      Column count for a bounded terrain, or -1 if unbounded.
      Specified by:
      getCols in interface Terrain
    • getRows

      public int getRows()
      Description copied from interface: Terrain
      Row count for a bounded terrain, or -1 if unbounded.
      Specified by:
      getRows in interface Terrain
    • 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.