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()) {
GenerationTaskPaper(chunkmaster, world, start, radius, shape)
} 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)
}
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.
*/
@ -126,7 +115,7 @@ abstract class GenerationTask(
/**
* Handles the invocation of the end reached callback and additional logic
*/
protected fun setEndReached() {
private fun setEndReached() {
endReached = true
count = shape.count
endReachedCallback?.invoke(this)
@ -140,6 +129,7 @@ abstract class GenerationTask(
protected fun borderReachedCheck(): Boolean {
val done = borderReached()
if (done) {
unloadLoadedChunks()
setEndReached()
}
return done

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

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

Loading…
Cancel
Save