Package com.rvandoosselaer.blocks
Class ChunkManager
java.lang.Object
com.rvandoosselaer.blocks.ChunkManager
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
addListener
(@NonNull ChunkManagerListener listener) void
cleanup()
getBlock
(com.jme3.collision.CollisionResult collisionResult) getBlock
(com.jme3.math.Vector3f location) static com.jme3.math.Vector3f
getBlockCenterLocation
(@NonNull com.simsilica.mathd.Vec3i location) Calculate the center location of a block.static com.simsilica.mathd.Vec3i
getBlockLocation
(@NonNull com.jme3.collision.CollisionResult collisionResult) static com.simsilica.mathd.Vec3i
getBlockLocation
(@NonNull com.jme3.math.Vector3f location) getChunk
(com.simsilica.mathd.Vec3i location) static com.simsilica.mathd.Vec3i
getChunkLocation
(@NonNull com.jme3.math.Vector3f location) Calculate the location of the chunk that contains the given location.getNeighbourBlock
(com.jme3.collision.CollisionResult collisionResult) getNeighbourBlock
(com.jme3.math.Vector3f location, Direction direction) static com.simsilica.mathd.Vec3i
getNeighbourBlockLocation
(@NonNull com.jme3.collision.CollisionResult collisionResult) static com.simsilica.mathd.Vec3i
getNeighbourBlockLocation
(@NonNull com.jme3.math.Vector3f location, Direction direction) void
void
removeBlock
(com.jme3.math.Vector3f location) void
removeChunk
(Chunk chunk) Inform the ChunkManager that you no longer need access to the chunk and it can perform cleanup operations on it.void
removeChunk
(com.simsilica.mathd.Vec3i location) void
removeListener
(@NonNull ChunkManagerListener listener) void
requestChunk
(com.simsilica.mathd.Vec3i location) void
requestChunkMeshUpdate
(Chunk chunk) void
requestChunkMeshUpdate
(com.simsilica.mathd.Vec3i location) void
void
update()
-
Constructor Details
-
ChunkManager
public ChunkManager() -
ChunkManager
public ChunkManager(int cacheSize)
-
-
Method Details
-
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) -
getBlockCenterLocation
public static com.jme3.math.Vector3f getBlockCenterLocation(@NonNull @NonNull com.simsilica.mathd.Vec3i location) Calculate the center location of a block.- Parameters:
location
-- Returns:
- center of the block
-
getChunk
-
setChunk
-
requestChunk
public void requestChunk(com.simsilica.mathd.Vec3i location) -
requestChunkMeshUpdate
public void requestChunkMeshUpdate(com.simsilica.mathd.Vec3i location) -
requestChunkMeshUpdate
-
removeChunk
public void removeChunk(com.simsilica.mathd.Vec3i location) - Parameters:
location
- of the chunk- See Also:
-
removeChunk
Inform the ChunkManager that you no longer need access to the chunk and it can perform cleanup operations on it.- Parameters:
chunk
-
-
addBlock
-
removeBlock
public void removeBlock(com.jme3.math.Vector3f location) -
getBlock
-
getBlock
-
getNeighbourBlock
-
getNeighbourBlock
-
initialize
public void initialize() -
update
public void update() -
cleanup
public void cleanup() -
addListener
-
removeListener
-
getChunkResolver
-