Add progress report to tasks generating to the worldborder

- Closes #90
pull/95/head
trivernis 4 years ago
parent 3cfc49baa8
commit 6df01dd137

@ -6,6 +6,7 @@ import net.trivernis.chunkmaster.lib.generation.taskentry.TaskEntry
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import kotlin.math.ceil
import kotlin.math.pow
class CmdList(private val chunkmaster: Chunkmaster) : Subcommand {
override val name = "list"
@ -49,14 +50,12 @@ class CmdList(private val chunkmaster: Chunkmaster) : Subcommand {
*/
private fun getGenerationEntry(task: TaskEntry): String {
val genTask = task.generationTask
val percentage = if (genTask.radius > 0)
" (%.1f".format(genTask.shape.progress() * 100) + "%)."
else
""
val progress = genTask.shape.progress(if (genTask.radius < 0) (genTask.world.worldBorder.size / 32).toInt() else null)
val percentage = " (%.1f".format(progress * 100) + "%)."
val count = if (genTask.radius > 0) {
"${genTask.count} / ${ceil(genTask.shape.total()).toInt()}"
} else {
genTask.count.toString()
"${genTask.count} / worldborder ${(genTask.world.worldBorder.size / 16).pow(2).toInt()}"
}
return "\n" + chunkmaster.langManager.getLocalized(
"TASKS_ENTRY",

@ -5,6 +5,8 @@ import java.util.concurrent.CompletableFuture
import kotlin.math.ceil
class PendingChunks(private val sqliteManager: SqliteManager) {
private val insertionCount = 300
/**
* Returns a list of pending chunks for a taskId
*/
@ -33,10 +35,10 @@ class PendingChunks(private val sqliteManager: SqliteManager) {
fun addPendingChunks(taskId: Int, pendingChunks: List<ChunkCoordinates>): CompletableFuture<Void> {
val futures = ArrayList<CompletableFuture<Void>>()
val statementCount = ceil(pendingChunks.size.toDouble() / 100.0).toInt()
val statementCount = ceil(pendingChunks.size.toDouble() / insertionCount).toInt()
for (i in 0 until statementCount) {
futures.add(insertPendingChunks(taskId, pendingChunks.subList(i * 100, ((i * 100) + 100).coerceAtMost(pendingChunks.size))))
futures.add(insertPendingChunks(taskId, pendingChunks.subList(i * insertionCount, ((i * insertionCount) + insertionCount).coerceAtMost(pendingChunks.size))))
}
if (futures.size > 0) {

@ -292,10 +292,12 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
private fun reportGenerationProgress(task: RunningTaskEntry) {
val genTask = task.generationTask
val (speed, chunkSpeed) = task.generationSpeed
val percentage = if (genTask.radius > 0) "(${"%.2f".format(genTask.shape.progress() * 100)}%)" else ""
val progress = genTask.shape.progress(if (genTask.radius < 0) (genTask.world.worldBorder.size / 32).toInt() else null)
val percentage =
"(${"%.2f".format(progress * 100)}%)"
val eta = if (genTask.radius > 0 && speed!! > 0) {
val remaining = 1 - genTask.shape.progress()
val eta = if (speed!! > 0) {
val remaining = 1 - progress
val etaSeconds = remaining / speed
val hours: Int = (etaSeconds / 3600).toInt()
val minutes: Int = ((etaSeconds % 3600) / 60).toInt()

@ -18,8 +18,9 @@ class RunningTaskEntry(
get() {
var generationSpeed: Double? = null
var chunkGenerationSpeed: Double? = null
val progress = generationTask.shape.progress(if (generationTask.radius < 0) (generationTask.world.worldBorder.size / 32).toInt() else null)
if (lastProgress != null) {
val progressDiff = generationTask.shape.progress() - lastProgress!!.second
val progressDiff = progress - lastProgress!!.second
val timeDiff = (System.currentTimeMillis() - lastProgress!!.first).toDouble() / 1000
generationSpeed = progressDiff / timeDiff
}
@ -28,13 +29,13 @@ class RunningTaskEntry(
val timeDiff = (System.currentTimeMillis() - lastChunkCount!!.first).toDouble() / 1000
chunkGenerationSpeed = chunkDiff / timeDiff
}
lastProgress = Pair(System.currentTimeMillis(), generationTask.shape.progress())
lastProgress = Pair(System.currentTimeMillis(), progress)
lastChunkCount = Pair(System.currentTimeMillis(), generationTask.count)
return Pair(generationSpeed, chunkGenerationSpeed)
}
init {
lastProgress = Pair(System.currentTimeMillis(), generationTask.shape.progress())
lastProgress = Pair(System.currentTimeMillis(), generationTask.shape.progress(null))
lastChunkCount = Pair(System.currentTimeMillis(), generationTask.count)
}

@ -20,9 +20,13 @@ class Circle(center: Pair<Int, Int>, start: Pair<Int, Int>, radius: Int) : Shape
return (PI * radius.toFloat().pow(2))
}
override fun progress(): Double {
override fun progress(maxRadius: Int?): Double {
// TODO: Radius inner progress
return (count / (PI * radius.toFloat().pow(2))).coerceAtMost(1.0)
return if (maxRadius != null) {
(count / (PI * maxRadius.toFloat().pow(2))).coerceAtMost(1.0)
} else {
(count / (PI * radius.toFloat().pow(2))).coerceAtMost(1.0)
}
}
override fun currentRadius(): Int {

@ -19,7 +19,7 @@ abstract class Shape(protected val center: Pair<Int, Int>, start: Pair<Int, Int>
/**
* Returns the progress of the shape
*/
abstract fun progress(): Double
abstract fun progress(maxRadius: Int?): Double
/**
* The total number of chunks to generate

@ -18,8 +18,12 @@ class Spiral(center: Pair<Int, Int>, start: Pair<Int, Int>, radius: Int) : Shape
return (radius * 2).toDouble().pow(2)
}
override fun progress(): Double {
return (count / (radius * 2).toDouble().pow(2)).coerceAtMost(1.0)
override fun progress(maxRadius: Int?): Double {
return if (maxRadius != null) {
(count / (maxRadius * 2).toDouble().pow(2)).coerceAtMost(1.0)
} else {
(count / (radius * 2).toDouble().pow(2)).coerceAtMost(1.0)
}
}
override fun currentRadius(): Int {

Loading…
Cancel
Save