Improve spigot chunk generation

Add skipping of already generated chunks.
An issue remaining is that some chunks are still
not generated and the shape doesn't always match.
pull/55/head
trivernis 5 years ago
parent 2b121b67fd
commit be130adc6f

@ -351,7 +351,7 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
return if (PaperLib.isPaper()) { return if (PaperLib.isPaper()) {
GenerationTaskPaper(chunkmaster, world, start, radius, shape) GenerationTaskPaper(chunkmaster, world, start, radius, shape)
} else { } else {
GenerationTaskSpigot(chunkmaster, world, center, start, radius, shape) GenerationTaskSpigot(chunkmaster, world, start, radius, shape)
} }
} }
} }

@ -55,17 +55,6 @@ abstract class GenerationTask(
return ChunkCoordinates(nextChunkCoords.first, nextChunkCoords.second) return ChunkCoordinates(nextChunkCoords.first, nextChunkCoords.second)
} }
val lastChunk: Chunk
get() {
return world.getChunkAt(lastChunkCoords.x, lastChunkCoords.z)
}
val nextChunk: Chunk
get() {
val next = nextChunkCoordinates
return world.getChunkAt(next.x, next.z)
}
/** /**
* Checks if the World border or the maximum chunk setting for the task is reached. * Checks if the World border or the maximum chunk setting for the task is reached.
*/ */
@ -126,7 +115,7 @@ abstract class GenerationTask(
/** /**
* Handles the invocation of the end reached callback and additional logic * Handles the invocation of the end reached callback and additional logic
*/ */
protected fun setEndReached() { private fun setEndReached() {
endReached = true endReached = true
count = shape.count count = shape.count
endReachedCallback?.invoke(this) endReachedCallback?.invoke(this)
@ -140,6 +129,7 @@ abstract class GenerationTask(
protected fun borderReachedCheck(): Boolean { protected fun borderReachedCheck(): Boolean {
val done = borderReached() val done = borderReached()
if (done) { if (done) {
unloadLoadedChunks()
setEndReached() setEndReached()
} }
return done return done

@ -26,19 +26,19 @@ class GenerationTaskPaper(
} }
/** /**
* Runs the generation task. Every Iteration the next chunk will be generated if * Runs the generation task. Every Iteration the next chunks will be generated if
* it hasn't been generated already. * they haven't been generated already
* After 10 chunks have been generated, they will all be unloaded and saved. * After a configured number of chunks chunks have been generated, they will all be unloaded and saved.
*/ */
override fun run() { override fun run() {
if (plugin.mspt < msptThreshold) { // pause when tps < 2 if (plugin.mspt < msptThreshold) {
if (loadedChunks.size > maxLoadedChunks) { if (loadedChunks.size > maxLoadedChunks) {
unloadLoadedChunks() unloadLoadedChunks()
} else if (pendingChunks.size < maxPendingChunks) { // if more than 10 chunks are pending, wait. } else if (pendingChunks.size < maxPendingChunks) {
if (borderReachedCheck()) return if (borderReachedCheck()) return
var chunk = nextChunkCoordinates var chunk = nextChunkCoordinates
for (i in 1 until chunkSkips) { for (i in 0 until chunkSkips) {
if (world.isChunkGenerated(chunk.x, chunk.z)) { if (world.isChunkGenerated(chunk.x, chunk.z)) {
chunk = nextChunkCoordinates chunk = nextChunkCoordinates
} else { } else {

@ -6,8 +6,9 @@ import org.bukkit.World
import java.lang.Exception import java.lang.Exception
class GenerationTaskSpigot( class GenerationTaskSpigot(
private val plugin: Chunkmaster, override val world: World, private val plugin: Chunkmaster,
centerChunk: ChunkCoordinates, private val startChunk: ChunkCoordinates, override val world: World,
startChunk: ChunkCoordinates,
override val radius: Int = -1, override val radius: Int = -1,
shape: Shape shape: Shape
) : GenerationTask(plugin, startChunk, shape) { ) : GenerationTask(plugin, startChunk, shape) {
@ -21,21 +22,28 @@ class GenerationTaskSpigot(
} }
/** /**
* Runs the generation task. Every Iteration the next chunk will be generated if * Runs the generation task. Every Iteration the next chunks will be generated if
* it hasn't been generated already. * they haven't been generated already
* After 10 chunks have been generated, they will all be unloaded and saved. * After a configured number of chunks chunks have been generated, they will all be unloaded and saved.
*/ */
override fun run() { override fun run() {
if (plugin.mspt < msptThreshold) { // pause when tps < 2 if (plugin.mspt < msptThreshold) {
if (loadedChunks.size > maxLoadedChunks) { if (loadedChunks.size > maxLoadedChunks) {
unloadLoadedChunks() unloadLoadedChunks()
} else { } else {
if (borderReachedCheck()) return if (borderReachedCheck()) return
var chunk = nextChunkCoordinates var chunk = nextChunkCoordinates
for (i in 0 until chunkSkips) {
if (world.isChunkGenerated(chunk.x, chunk.z)) {
chunk = nextChunkCoordinates
} else {
break
}
}
if (!world.isChunkGenerated(chunk.x, chunk.z)) { if (!world.isChunkGenerated(chunk.x, chunk.z)) {
for (i in 0 until minOf(chunksPerStep, radius - shape.currentRadius())) { for (i in 0 until chunksPerStep) {
if (borderReached()) break if (borderReached()) break
val chunkInstance = world.getChunkAt(chunk.x, chunk.z) val chunkInstance = world.getChunkAt(chunk.x, chunk.z)
chunkInstance.load(true) chunkInstance.load(true)
@ -45,10 +53,9 @@ class GenerationTaskSpigot(
val chunkInstance = world.getChunkAt(chunk.x, chunk.z) val chunkInstance = world.getChunkAt(chunk.x, chunk.z)
chunkInstance.load(true) chunkInstance.load(true)
loadedChunks.add(chunkInstance) loadedChunks.add(chunkInstance)
} }
lastChunkCoords = chunk lastChunkCoords = chunk
count = shape.count // set the count to the more accurate spiral count count = shape.count
} }
} }
} }

Loading…
Cancel
Save