Package com.rvandoosselaer.blocks
Class ChunkManager
- java.lang.Object
-
- com.rvandoosselaer.blocks.ChunkManager
-
public class ChunkManager extends java.lang.ObjectThe ChunkManager is responsible for the administration of chunks and the maintenance of the underlying ChunkCache. The ChunkManager is thread safe, but the lifecycle methodsinitialize(),update()andcleanup()should be called from the same thread. It is good practice to let the lifecycle of the ChunkManager be handled by theChunkManagerState.A chunk can be retrieved by using the
getChunk(Vec3i)method. When the chunk isn't available it can be requested with therequestChunk(Vec3i)method. The ChunkManager will first try to load the requested chunk using theChunkRepository. When this is not successful it will try to generate the chunk using theChunkGenerator. When this also fails, an empty chunk will be created. The requested chunk is placed in the cache and can be retrieved with thegetChunk(Vec3i)method.Applications can register a
ChunkManagerListenerto the ChunkManager to get notified when a chunk is available in the cache or when a chunk is updated.
-
-
Constructor Summary
Constructors Constructor Description ChunkManager()ChunkManager(int cacheSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBlock(com.jme3.math.Vector3f location, Block block)voidaddListener(@NonNull ChunkManagerListener listener)voidcleanup()java.util.Optional<Block>getBlock(com.jme3.collision.CollisionResult collisionResult)java.util.Optional<Block>getBlock(com.jme3.math.Vector3f location)static com.simsilica.mathd.Vec3igetBlockLocation(@NonNull com.jme3.collision.CollisionResult collisionResult)static com.simsilica.mathd.Vec3igetBlockLocation(@NonNull com.jme3.math.Vector3f location)java.util.Optional<Chunk>getChunk(com.simsilica.mathd.Vec3i location)static com.simsilica.mathd.Vec3igetChunkLocation(@NonNull com.jme3.math.Vector3f location)Calculate the location of the chunk that contains the given location.ChunkResolvergetChunkResolver()java.util.Optional<Block>getNeighbourBlock(com.jme3.collision.CollisionResult collisionResult)java.util.Optional<Block>getNeighbourBlock(com.jme3.math.Vector3f location, Direction direction)static com.simsilica.mathd.Vec3igetNeighbourBlockLocation(@NonNull com.jme3.collision.CollisionResult collisionResult)static com.simsilica.mathd.Vec3igetNeighbourBlockLocation(@NonNull com.jme3.math.Vector3f location, Direction direction)voidinitialize()voidremoveBlock(com.jme3.math.Vector3f location)voidremoveChunk(Chunk chunk)Inform the ChunkManager that you no longer need access to the chunk and it can perform cleanup operations on it.voidremoveChunk(com.simsilica.mathd.Vec3i location)voidremoveListener(@NonNull ChunkManagerListener listener)voidrequestChunk(com.simsilica.mathd.Vec3i location)voidrequestChunkMeshUpdate(Chunk chunk)voidrequestChunkMeshUpdate(com.simsilica.mathd.Vec3i location)voidupdate()
-
-
-
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()
-
addListener
public void addListener(@NonNull @NonNull ChunkManagerListener listener)
-
removeListener
public void removeListener(@NonNull @NonNull ChunkManagerListener listener)
-
getChunkResolver
public ChunkResolver getChunkResolver()
-
-