From eb5cb1a229b5867a2c23cca4b1b4382a1e8975c3 Mon Sep 17 00:00:00 2001 From: Kenneth Endfinger Date: Wed, 16 Feb 2022 00:56:48 -0500 Subject: [PATCH] Gjallarhorn: Attempt to clarify the mess that is ChangelogSlice. --- .../commands/BlockChangeTimelapseCommand.kt | 4 ++-- .../render/PlayerLocationShareRenderer.kt | 4 ++-- .../gjallarhorn/state/BlockChangelog.kt | 6 +++--- .../gjallarhorn/state/ChangelogSlice.kt | 20 +++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/commands/BlockChangeTimelapseCommand.kt b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/commands/BlockChangeTimelapseCommand.kt index 0c31ae8..cb01b6b 100644 --- a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/commands/BlockChangeTimelapseCommand.kt +++ b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/commands/BlockChangeTimelapseCommand.kt @@ -107,13 +107,13 @@ class BlockChangeTimelapseCommand : CliktCommand("Block Change Timelapse", name createRendererFunction = { expanse -> render.create(expanse, db) }, threadPoolExecutor = threadPoolExecutor ) { slice, result -> - val speed = slice.relative.toSeconds().toDouble() / timelapseMode.interval.toSeconds().toDouble() + val speed = slice.sliceRelativeDuration.toSeconds().toDouble() / timelapseMode.interval.toSeconds().toDouble() val graphics = result.createGraphics() val font = Font.decode("Arial Black").deriveFont(24.0f) graphics.color = Color.black graphics.font = font val context = graphics.fontRenderContext - val text = String.format("%s @ %.4f speed (1 frame = %s sec)", slice.to, speed, slice.relative.toSeconds()) + val text = String.format("%s @ %.4f speed (1 frame = %s sec)", slice.sliceEndTime, speed, slice.sliceRelativeDuration.toSeconds()) val layout = TextLayout(text, font, context) layout.draw(graphics, 60f, 60f) diff --git a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/render/PlayerLocationShareRenderer.kt b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/render/PlayerLocationShareRenderer.kt index 8c28e36..61644fe 100644 --- a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/render/PlayerLocationShareRenderer.kt +++ b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/render/PlayerLocationShareRenderer.kt @@ -19,8 +19,8 @@ class PlayerLocationShareRenderer( private val colorKey = BlockColorKey(mapOf()) override fun render(slice: ChangelogSlice, map: BlockStateMap): BufferedImage { - val start = slice.relativeChangeRange.start - val end = slice.relativeChangeRange.endInclusive + val start = slice.sliceChangeRange.start + val end = slice.sliceChangeRange.endInclusive val playerSparseMap = BlockCoordinateSparseMap>() val allPlayerIds = HashSet() diff --git a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/BlockChangelog.kt b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/BlockChangelog.kt index 05b1712..1be42d7 100644 --- a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/BlockChangelog.kt +++ b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/BlockChangelog.kt @@ -13,11 +13,11 @@ class BlockChangelog( val changes: List ) { fun slice(slice: ChangelogSlice): BlockChangelog = BlockChangelog(changes.filter { - slice.isTimeWithin(it.time) + slice.isTimeWithinFullRange(it.time) }) fun countRelativeChangesInSlice(slice: ChangelogSlice): Int = changes.count { - slice.isRelativeWithin(it.time) + slice.isTimeWithinSliceRange(it.time) } val changeTimeRange: ChangelogSlice @@ -46,7 +46,7 @@ class BlockChangelog( return slices.parallelStream().flatMap { slice -> val count = countRelativeChangesInSlice(slice) if (count < targetChangeThreshold || - slice.relative < minimumTimeInterval + slice.sliceRelativeDuration < minimumTimeInterval ) { return@flatMap Stream.of(slice) } diff --git a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/ChangelogSlice.kt b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/ChangelogSlice.kt index 2b859ce..fe80dc0 100644 --- a/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/ChangelogSlice.kt +++ b/tool-gjallarhorn/src/main/kotlin/cloud/kubelet/foundation/gjallarhorn/state/ChangelogSlice.kt @@ -3,23 +3,23 @@ package cloud.kubelet.foundation.gjallarhorn.state import java.time.Duration import java.time.Instant -data class ChangelogSlice(val from: Instant, val to: Instant, val relative: Duration) { +data class ChangelogSlice(val rootStartTime: Instant, val sliceEndTime: Instant, val sliceRelativeDuration: Duration) { constructor(from: Instant, to: Instant) : this(from, to, Duration.ofMillis(to.toEpochMilli() - from.toEpochMilli())) - val relativeChangeStart: Instant = to.minus(relative) - val range: ClosedRange = from..to - val relativeChangeRange: ClosedRange = relativeChangeStart..to + val sliceStartTime: Instant = sliceEndTime.minus(sliceRelativeDuration) + val fullTimeRange: ClosedRange = rootStartTime..sliceEndTime + val sliceChangeRange: ClosedRange = sliceStartTime..sliceEndTime - fun isTimeWithin(time: Instant) = time in range - fun isRelativeWithin(time: Instant) = time in relativeChangeRange + fun isTimeWithinFullRange(time: Instant) = time in fullTimeRange + fun isTimeWithinSliceRange(time: Instant) = time in sliceChangeRange fun split(): List { - val half = relative.dividedBy(2) - val initial = to.minus(relative) + val half = sliceRelativeDuration.dividedBy(2) + val initial = sliceEndTime.minus(sliceRelativeDuration) val first = initial.plus(half) return listOf( - ChangelogSlice(from, first, half), - ChangelogSlice(from, to, half) + ChangelogSlice(rootStartTime, first, half), + ChangelogSlice(rootStartTime, sliceEndTime, half) ) } }