Class ChunkManager


  • public class ChunkManager
    extends java.lang.Object
    The ChunkManager is responsible for the administration of chunks and the maintenance of the underlying ChunkCache. The ChunkManager is thread safe, but the lifecycle methods initialize(), update() and cleanup() should be called from the same thread. It is good practice to let the lifecycle of the ChunkManager be handled by the ChunkManagerState.

    A chunk can be retrieved by using the getChunk(Vec3i) method. When the chunk isn't available it can be requested with the requestChunk(Vec3i) method. The ChunkManager will first try to load the requested chunk using the ChunkRepository. When this is not successful it will try to generate the chunk using the ChunkGenerator. When this also fails, an empty chunk will be created. The requested chunk is placed in the cache and can be retrieved with the getChunk(Vec3i) method.

    Applications can register a ChunkManagerListener to the ChunkManager to get notified when a chunk is available in the cache or when a chunk is updated.

    • Constructor Detail

      • ChunkManager

        public ChunkManager()
      • ChunkManager

        public ChunkManager​(int cacheSize)
    • Method Detail

      • getChunkLocation

        public static com.simsilica.mathd.Vec3i getChunkLocation​(@NonNull
                                                                 @NonNull com.jme3.math.Vector3f location)
        Calculate the location of the chunk that contains the given location.
        Parameters:
        location -
        Returns:
        location of the chunk
      • getBlockLocation

        public static com.simsilica.mathd.Vec3i getBlockLocation​(@NonNull
                                                                 @NonNull com.jme3.math.Vector3f location)
      • getBlockLocation

        public static com.simsilica.mathd.Vec3i getBlockLocation​(@NonNull
                                                                 @NonNull com.jme3.collision.CollisionResult collisionResult)
      • getNeighbourBlockLocation

        public static com.simsilica.mathd.Vec3i getNeighbourBlockLocation​(@NonNull
                                                                          @NonNull com.jme3.math.Vector3f location,
                                                                          Direction direction)
      • getNeighbourBlockLocation

        public static com.simsilica.mathd.Vec3i getNeighbourBlockLocation​(@NonNull
                                                                          @NonNull com.jme3.collision.CollisionResult collisionResult)
      • getChunk

        public java.util.Optional<Chunk> getChunk​(com.simsilica.mathd.Vec3i location)
      • requestChunk

        public void requestChunk​(com.simsilica.mathd.Vec3i location)
      • requestChunkMeshUpdate

        public void requestChunkMeshUpdate​(com.simsilica.mathd.Vec3i location)
      • requestChunkMeshUpdate

        public void requestChunkMeshUpdate​(Chunk chunk)
      • removeChunk

        public void removeChunk​(com.simsilica.mathd.Vec3i location)
        Parameters:
        location - of the chunk
        See Also:
        removeChunk(Chunk)
      • removeChunk

        public void removeChunk​(Chunk chunk)
        Inform the ChunkManager that you no longer need access to the chunk and it can perform cleanup operations on it.
        Parameters:
        chunk -
      • addBlock

        public void addBlock​(com.jme3.math.Vector3f location,
                             Block block)
      • removeBlock

        public void removeBlock​(com.jme3.math.Vector3f location)
      • getBlock

        public java.util.Optional<Block> getBlock​(com.jme3.math.Vector3f location)
      • getBlock

        public java.util.Optional<Block> getBlock​(com.jme3.collision.CollisionResult collisionResult)
      • getNeighbourBlock

        public java.util.Optional<Block> getNeighbourBlock​(com.jme3.math.Vector3f location,
                                                           Direction direction)
      • getNeighbourBlock

        public java.util.Optional<Block> getNeighbourBlock​(com.jme3.collision.CollisionResult collisionResult)
      • initialize

        public void initialize()
      • update

        public void update()
      • cleanup

        public void cleanup()