mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-03 05:30:55 +00:00
Gjallarhorn: Attempt to clarify the mess that is ChangelogSlice.
This commit is contained in:
@ -107,13 +107,13 @@ class BlockChangeTimelapseCommand : CliktCommand("Block Change Timelapse", name
|
|||||||
createRendererFunction = { expanse -> render.create(expanse, db) },
|
createRendererFunction = { expanse -> render.create(expanse, db) },
|
||||||
threadPoolExecutor = threadPoolExecutor
|
threadPoolExecutor = threadPoolExecutor
|
||||||
) { slice, result ->
|
) { 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 graphics = result.createGraphics()
|
||||||
val font = Font.decode("Arial Black").deriveFont(24.0f)
|
val font = Font.decode("Arial Black").deriveFont(24.0f)
|
||||||
graphics.color = Color.black
|
graphics.color = Color.black
|
||||||
graphics.font = font
|
graphics.font = font
|
||||||
val context = graphics.fontRenderContext
|
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 =
|
val layout =
|
||||||
TextLayout(text, font, context)
|
TextLayout(text, font, context)
|
||||||
layout.draw(graphics, 60f, 60f)
|
layout.draw(graphics, 60f, 60f)
|
||||||
|
@ -19,8 +19,8 @@ class PlayerLocationShareRenderer(
|
|||||||
private val colorKey = BlockColorKey(mapOf())
|
private val colorKey = BlockColorKey(mapOf())
|
||||||
|
|
||||||
override fun render(slice: ChangelogSlice, map: BlockStateMap): BufferedImage {
|
override fun render(slice: ChangelogSlice, map: BlockStateMap): BufferedImage {
|
||||||
val start = slice.relativeChangeRange.start
|
val start = slice.sliceChangeRange.start
|
||||||
val end = slice.relativeChangeRange.endInclusive
|
val end = slice.sliceChangeRange.endInclusive
|
||||||
|
|
||||||
val playerSparseMap = BlockCoordinateSparseMap<MutableList<UUID>>()
|
val playerSparseMap = BlockCoordinateSparseMap<MutableList<UUID>>()
|
||||||
val allPlayerIds = HashSet<UUID>()
|
val allPlayerIds = HashSet<UUID>()
|
||||||
|
@ -13,11 +13,11 @@ class BlockChangelog(
|
|||||||
val changes: List<BlockChange>
|
val changes: List<BlockChange>
|
||||||
) {
|
) {
|
||||||
fun slice(slice: ChangelogSlice): BlockChangelog = BlockChangelog(changes.filter {
|
fun slice(slice: ChangelogSlice): BlockChangelog = BlockChangelog(changes.filter {
|
||||||
slice.isTimeWithin(it.time)
|
slice.isTimeWithinFullRange(it.time)
|
||||||
})
|
})
|
||||||
|
|
||||||
fun countRelativeChangesInSlice(slice: ChangelogSlice): Int = changes.count {
|
fun countRelativeChangesInSlice(slice: ChangelogSlice): Int = changes.count {
|
||||||
slice.isRelativeWithin(it.time)
|
slice.isTimeWithinSliceRange(it.time)
|
||||||
}
|
}
|
||||||
|
|
||||||
val changeTimeRange: ChangelogSlice
|
val changeTimeRange: ChangelogSlice
|
||||||
@ -46,7 +46,7 @@ class BlockChangelog(
|
|||||||
return slices.parallelStream().flatMap { slice ->
|
return slices.parallelStream().flatMap { slice ->
|
||||||
val count = countRelativeChangesInSlice(slice)
|
val count = countRelativeChangesInSlice(slice)
|
||||||
if (count < targetChangeThreshold ||
|
if (count < targetChangeThreshold ||
|
||||||
slice.relative < minimumTimeInterval
|
slice.sliceRelativeDuration < minimumTimeInterval
|
||||||
) {
|
) {
|
||||||
return@flatMap Stream.of(slice)
|
return@flatMap Stream.of(slice)
|
||||||
}
|
}
|
||||||
|
@ -3,23 +3,23 @@ package cloud.kubelet.foundation.gjallarhorn.state
|
|||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.Instant
|
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()))
|
constructor(from: Instant, to: Instant) : this(from, to, Duration.ofMillis(to.toEpochMilli() - from.toEpochMilli()))
|
||||||
|
|
||||||
val relativeChangeStart: Instant = to.minus(relative)
|
val sliceStartTime: Instant = sliceEndTime.minus(sliceRelativeDuration)
|
||||||
val range: ClosedRange<Instant> = from..to
|
val fullTimeRange: ClosedRange<Instant> = rootStartTime..sliceEndTime
|
||||||
val relativeChangeRange: ClosedRange<Instant> = relativeChangeStart..to
|
val sliceChangeRange: ClosedRange<Instant> = sliceStartTime..sliceEndTime
|
||||||
|
|
||||||
fun isTimeWithin(time: Instant) = time in range
|
fun isTimeWithinFullRange(time: Instant) = time in fullTimeRange
|
||||||
fun isRelativeWithin(time: Instant) = time in relativeChangeRange
|
fun isTimeWithinSliceRange(time: Instant) = time in sliceChangeRange
|
||||||
|
|
||||||
fun split(): List<ChangelogSlice> {
|
fun split(): List<ChangelogSlice> {
|
||||||
val half = relative.dividedBy(2)
|
val half = sliceRelativeDuration.dividedBy(2)
|
||||||
val initial = to.minus(relative)
|
val initial = sliceEndTime.minus(sliceRelativeDuration)
|
||||||
val first = initial.plus(half)
|
val first = initial.plus(half)
|
||||||
return listOf(
|
return listOf(
|
||||||
ChangelogSlice(from, first, half),
|
ChangelogSlice(rootStartTime, first, half),
|
||||||
ChangelogSlice(from, to, half)
|
ChangelogSlice(rootStartTime, sliceEndTime, half)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user