Gjallarhorn: Attempt to clarify the mess that is ChangelogSlice.

This commit is contained in:
Kenneth Endfinger 2022-02-16 00:56:48 -05:00
parent 74fed8c222
commit eb5cb1a229
No known key found for this signature in database
GPG Key ID: C4E68E5647420E10
4 changed files with 17 additions and 17 deletions

View File

@ -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)

View File

@ -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<MutableList<UUID>>()
val allPlayerIds = HashSet<UUID>()

View File

@ -13,11 +13,11 @@ class BlockChangelog(
val changes: List<BlockChange>
) {
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)
}

View File

@ -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<Instant> = from..to
val relativeChangeRange: ClosedRange<Instant> = relativeChangeStart..to
val sliceStartTime: Instant = sliceEndTime.minus(sliceRelativeDuration)
val fullTimeRange: ClosedRange<Instant> = rootStartTime..sliceEndTime
val sliceChangeRange: ClosedRange<Instant> = 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<ChangelogSlice> {
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)
)
}
}