Performance improvements

- improved performance on paper servers by using chunk coordinates instead of chunk instances to check if the chunk was generated
- moved generation stuff to lib/generation
pull/1/head
Trivernis 5 years ago
parent 08bec14df9
commit c49036e35b

@ -2,7 +2,7 @@ package net.trivernis.chunkmaster
import io.papermc.lib.PaperLib import io.papermc.lib.PaperLib
import net.trivernis.chunkmaster.commands.* import net.trivernis.chunkmaster.commands.*
import net.trivernis.chunkmaster.lib.GenerationManager import net.trivernis.chunkmaster.lib.generation.GenerationManager
import net.trivernis.chunkmaster.lib.SqlUpdateManager import net.trivernis.chunkmaster.lib.SqlUpdateManager
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.scheduler.BukkitTask import org.bukkit.scheduler.BukkitTask

@ -0,0 +1,4 @@
package net.trivernis.chunkmaster.lib.generation
data class ChunkCoordinates(val x: Int, val z: Int) {
}

@ -1,4 +1,4 @@
package net.trivernis.chunkmaster.lib package net.trivernis.chunkmaster.lib.generation
import io.papermc.lib.PaperLib import io.papermc.lib.PaperLib
import net.trivernis.chunkmaster.Chunkmaster import net.trivernis.chunkmaster.Chunkmaster

@ -1,6 +1,7 @@
package net.trivernis.chunkmaster.lib package net.trivernis.chunkmaster.lib.generation
import net.trivernis.chunkmaster.Chunkmaster import net.trivernis.chunkmaster.Chunkmaster
import net.trivernis.chunkmaster.lib.Spiral
import org.bukkit.Chunk import org.bukkit.Chunk
import org.bukkit.World import org.bukkit.World
@ -15,7 +16,8 @@ abstract class GenerationTask(plugin: Chunkmaster, centerChunk: Chunk, startChun
abstract val lastChunk: Chunk abstract val lastChunk: Chunk
abstract val endReached: Boolean abstract val endReached: Boolean
protected val spiral: Spiral = Spiral(Pair(centerChunk.x, centerChunk.z), Pair(startChunk.x, startChunk.z)) protected val spiral: Spiral =
Spiral(Pair(centerChunk.x, centerChunk.z), Pair(startChunk.x, startChunk.z))
protected val loadedChunks: HashSet<Chunk> = HashSet() protected val loadedChunks: HashSet<Chunk> = HashSet()
protected val chunkSkips = plugin.config.getInt("generation.chunks-skips-per-step") protected val chunkSkips = plugin.config.getInt("generation.chunks-skips-per-step")
protected val msptThreshold = plugin.config.getLong("generation.mspt-pause-threshold") protected val msptThreshold = plugin.config.getLong("generation.mspt-pause-threshold")
@ -23,10 +25,15 @@ abstract class GenerationTask(plugin: Chunkmaster, centerChunk: Chunk, startChun
abstract override fun run() abstract override fun run()
abstract fun cancel() abstract fun cancel()
val nextChunk: Chunk val nextChunkCoordinates: ChunkCoordinates
get() { get() {
val nextChunkCoords = spiral.next() val nextChunkCoords = spiral.next()
return world.getChunkAt(nextChunkCoords.first, nextChunkCoords.second) return ChunkCoordinates(nextChunkCoords.first, nextChunkCoords.second)
}
val nextChunk: Chunk
get() {
val next = nextChunkCoordinates
return world.getChunkAt(next.x, next.z)
} }
protected fun borderReached(): Boolean { protected fun borderReached(): Boolean {

@ -1,4 +1,4 @@
package net.trivernis.chunkmaster.lib package net.trivernis.chunkmaster.lib.generation
import net.trivernis.chunkmaster.Chunkmaster import net.trivernis.chunkmaster.Chunkmaster
import org.bukkit.Chunk import org.bukkit.Chunk
@ -17,10 +17,15 @@ class GenerationTaskPaper(
override var count = 0 override var count = 0
private set private set
override var lastChunk: Chunk = startChunk override var lastChunk: Chunk = startChunk
get() {
return world.getChunkAt(lastChunkCoords.x, lastChunkCoords.z)
}
private set private set
override var endReached: Boolean = false override var endReached: Boolean = false
private set private set
private var lastChunkCoords = ChunkCoordinates(startChunk.x, startChunk.z)
/** /**
* Runs the generation task. Every Iteration the next chunk will be generated if * Runs the generation task. Every Iteration the next chunk will be generated if
* it hasn't been generated already. * it hasn't been generated already.
@ -40,10 +45,10 @@ class GenerationTaskPaper(
return return
} }
var chunk = nextChunk var chunk = nextChunkCoordinates
for (i in 1 until chunkSkips) { for (i in 1 until chunkSkips) {
if (PaperLib.isChunkGenerated(world, chunk.x, chunk.z)) { if (PaperLib.isChunkGenerated(world, chunk.x, chunk.z)) {
chunk = nextChunk chunk = nextChunkCoordinates
} else { } else {
break break
} }
@ -52,7 +57,7 @@ class GenerationTaskPaper(
if (!PaperLib.isChunkGenerated(world, chunk.x, chunk.z)) { if (!PaperLib.isChunkGenerated(world, chunk.x, chunk.z)) {
pendingChunks.add(PaperLib.getChunkAtAsync(world, chunk.x, chunk.z, true)) pendingChunks.add(PaperLib.getChunkAtAsync(world, chunk.x, chunk.z, true))
} }
lastChunk = chunk lastChunkCoords = chunk
count = spiral.count // set the count to the more accurate spiral count count = spiral.count // set the count to the more accurate spiral count
} }
} }

@ -1,11 +1,8 @@
package net.trivernis.chunkmaster.lib package net.trivernis.chunkmaster.lib.generation
import net.trivernis.chunkmaster.Chunkmaster import net.trivernis.chunkmaster.Chunkmaster
import org.bukkit.Chunk import org.bukkit.Chunk
import org.bukkit.World import org.bukkit.World
import org.bukkit.scheduler.BukkitRunnable
import org.bukkit.scheduler.BukkitTask
import java.util.concurrent.CompletableFuture
class GenerationTaskSpigot( class GenerationTaskSpigot(
private val plugin: Chunkmaster, override val world: World, private val plugin: Chunkmaster, override val world: World,

@ -1,4 +1,4 @@
package net.trivernis.chunkmaster.lib package net.trivernis.chunkmaster.lib.generation
import org.bukkit.scheduler.BukkitTask import org.bukkit.scheduler.BukkitTask
Loading…
Cancel
Save