Fixes and Generation progress

- added generation progress display
- fixed spigot generation task
- fixed generation units
- fixed generation configuration
release/0.12-beta
Trivernis 5 years ago
parent 350e774bb2
commit a8729f2e03

@ -55,30 +55,28 @@ class CmdGenerate(private val chunkmaster: Chunkmaster): Subcommand {
if (args.size > 1) { if (args.size > 1) {
if (args[1].toIntOrNull() != null) { if (args[1].toIntOrNull() != null) {
stopAfter = args[1].toInt() stopAfter = args[1].toInt()
} else if (args[1] in units) { } else if (args[1] in units && args[0].toIntOrNull() != null) {
when (args[1]) { stopAfter = getStopAfter(stopAfter, args[1])
"radius" -> {
stopAfter = ((stopAfter * 2)+1).toDouble().pow(2.0).toInt()
}
"diameter" -> {
stopAfter = stopAfter.toDouble().pow(2.0).toInt()
}
"blockradius" -> {
stopAfter = ((stopAfter*32)+1).toDouble().pow(2.0).toInt()
}
}
} else { } else {
worldName = args[1] worldName = args[1]
} }
} }
if (args.size > 2 && args[2] in units && args[1].toIntOrNull() != null) {
stopAfter = getStopAfter(stopAfter, args[2])
}
} else { } else {
worldName = sender.world.name worldName = sender.world.name
} }
} else { } else {
if (args.isNotEmpty()) { if (args.isNotEmpty()) {
worldName = args[0] worldName = args[0]
if (args.size > 1 && args[1].toIntOrNull() != null) { if (args.size > 1) {
stopAfter = args[1].toInt() if (args[1].toIntOrNull() != null) {
stopAfter = args[1].toInt()
}
}
if (args.size > 2 && args[2] in units) {
stopAfter = getStopAfter(stopAfter, args[2])
} }
} else { } else {
sender.spigot().sendMessage( sender.spigot().sendMessage(
@ -89,6 +87,27 @@ class CmdGenerate(private val chunkmaster: Chunkmaster): Subcommand {
return createTask(sender, worldName, stopAfter) return createTask(sender, worldName, stopAfter)
} }
/**
* Returns stopAfter for a given unit
*/
private fun getStopAfter(number: Int, unit: String): Int {
if (unit in units) {
return when (unit) {
"radius" -> {
((number * 2)+1).toDouble().pow(2.0).toInt()
}
"diameter" -> {
number.toDouble().pow(2.0).toInt()
}
"blockradius" -> {
((number*32)+1).toDouble().pow(2.0).toInt()
}
else -> number
}
}
return number
}
/** /**
* Creates the task with the given arguments. * Creates the task with the given arguments.
*/ */

@ -226,8 +226,9 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
chunkmaster.logger.info( chunkmaster.logger.info(
"""Task #${task.id} running for "${genTask.world.name}". """Task #${task.id} running for "${genTask.world.name}".
|Progress ${task.generationTask.count} chunks |Progress ${task.generationTask.count} chunks
|${if (task.generationTask.stopAfter > 0) "(${(task.generationTask.count.toDouble() / |${if (task.generationTask.stopAfter > 0) "(${"%.2f".format((task.generationTask.count.toDouble() /
task.generationTask.stopAfter.toDouble()) * 100}%)" else ""}. task.generationTask.stopAfter.toDouble()) * 100)}%)" else ""}.
| Speed: ${"%.1f".format(task.generationSpeed)} chunks/sec,
|Last Chunk: ${genTask.lastChunk.x}, ${genTask.lastChunk.z}""".trimMargin("|").replace('\n', ' ') |Last Chunk: ${genTask.lastChunk.x}, ${genTask.lastChunk.z}""".trimMargin("|").replace('\n', ' ')
) )
val updateStatement = chunkmaster.sqliteConnection.prepareStatement( val updateStatement = chunkmaster.sqliteConnection.prepareStatement(

@ -20,7 +20,7 @@ abstract class GenerationTask(plugin: Chunkmaster, centerChunk: ChunkCoordinates
Spiral(Pair(centerChunk.x, centerChunk.z), Pair(startChunk.x, startChunk.z)) Spiral(Pair(centerChunk.x, centerChunk.z), Pair(startChunk.x, startChunk.z))
protected val loadedChunks: HashSet<Chunk> = HashSet() protected val loadedChunks: HashSet<Chunk> = HashSet()
protected var lastChunkCoords = ChunkCoordinates(startChunk.x, startChunk.z) protected var lastChunkCoords = ChunkCoordinates(startChunk.x, startChunk.z)
protected val chunkSkips = plugin.config.getInt("generation.chunks-skips-per-step") protected val chunkSkips = plugin.config.getInt("generation.chunk-skips-per-step")
protected val msptThreshold = plugin.config.getLong("generation.mspt-pause-threshold") protected val msptThreshold = plugin.config.getLong("generation.mspt-pause-threshold")
protected val maxLoadedChunks = plugin.config.getInt("generation.max-loaded-chunks") protected val maxLoadedChunks = plugin.config.getInt("generation.max-loaded-chunks")
protected val chunksPerStep = plugin.config.getInt("generation.chunks-per-step") protected val chunksPerStep = plugin.config.getInt("generation.chunks-per-step")

@ -37,15 +37,18 @@ class GenerationTaskSpigot(
return return
} }
var chunk = lastChunkCoords var chunk = nextChunkCoordinates
if (!world.isChunkGenerated(chunk.x, chunk.z)) { if (!world.isChunkGenerated(chunk.x, chunk.z)) {
for (i in 0 until minOf(chunksPerStep, (stopAfter - count) - 1)) { for (i in 0 until minOf(chunksPerStep, stopAfter - count)) {
chunk = nextChunkCoordinates
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)
chunk = nextChunkCoordinates
} }
val chunkInstance = world.getChunkAt(chunk.x, chunk.z)
chunkInstance.load(true)
loadedChunks.add(chunkInstance)
} }
lastChunkCoords = 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

@ -7,6 +7,29 @@ class RunningTaskEntry(
val task: BukkitTask, val task: BukkitTask,
override val generationTask: GenerationTask override val generationTask: GenerationTask
) : TaskEntry { ) : TaskEntry {
private var lastProgress: Pair<Long, Int>? = null
/**
* Returns the generation Speed
*/
val generationSpeed: Double?
get() {
var generationSpeed: Double? = null
if (lastProgress != null) {
val chunkDiff = generationTask.count - lastProgress!!.second
val timeDiff = (System.currentTimeMillis() - lastProgress!!.first).toDouble()/1000
generationSpeed = chunkDiff.toDouble()/timeDiff
}
lastProgress = Pair(System.currentTimeMillis(), generationTask.count)
return generationSpeed
}
init {
lastProgress = Pair(System.currentTimeMillis(), generationTask.count)
}
override fun cancel() { override fun cancel() {
task.cancel() task.cancel()
generationTask.cancel() generationTask.cancel()

Loading…
Cancel
Save