commit 96
This commit is contained in:
parent
456e46cabf
commit
1647bd1b88
2 changed files with 25 additions and 8 deletions
|
@ -16,6 +16,7 @@ import kotlin.time.TimeSource
|
|||
|
||||
interface DynamicValue<T> {
|
||||
fun reset()
|
||||
fun skipTransition()
|
||||
fun getCurrentValue(): T
|
||||
}
|
||||
|
||||
|
@ -71,6 +72,14 @@ abstract class DoubleDV<T>(private val initialStaticValue: Double) : DynamicValu
|
|||
state = State.Static(initialStaticValue)
|
||||
}
|
||||
|
||||
override fun skipTransition() {
|
||||
state = when (val s = state) {
|
||||
is State.Fade -> State.Static(s.end)
|
||||
is State.PulseOnce -> State.Static(s.end)
|
||||
else -> s
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCurrentValue(): T {
|
||||
val elapsedTime = stateChangeMark.elapsedNow()
|
||||
|
||||
|
@ -215,6 +224,8 @@ class ConcreteDV<T>(private val initialStaticValue: T) : DynamicValue<T> {
|
|||
state = State.Static(initialStaticValue)
|
||||
}
|
||||
|
||||
override fun skipTransition() {}
|
||||
|
||||
override fun getCurrentValue(): T = when (val s = state) {
|
||||
is State.Static -> s.value
|
||||
}
|
||||
|
@ -252,6 +263,13 @@ class ColorDV(private val initialStaticValue: Color = Color.WHITE) : DynamicValu
|
|||
state = State.Static(initialStaticValue)
|
||||
}
|
||||
|
||||
override fun skipTransition() {
|
||||
state = when(val s = state) {
|
||||
is State.Fade -> State.Static(s.end)
|
||||
else -> s
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCurrentValue(): Color {
|
||||
val elapsedTime = stateChangeMark.elapsedNow()
|
||||
|
||||
|
|
|
@ -81,10 +81,6 @@ class ShowContext(
|
|||
else -> it.copy(position = position, isLightBehindCurtainOn = isLightBehindCurtainOn)
|
||||
}
|
||||
}
|
||||
|
||||
if (step.cue is StepCue.MusicStart) {
|
||||
logger.info { "Music started: ${step.cue.title} (${step.cue.duration.inWholeSeconds}s)" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,6 +153,8 @@ fun CoroutineScope.startStepRunning(context: ShowContext) = launch {
|
|||
context.stateFlow.map { it.position }.distinctUntilChanged().collect { position ->
|
||||
context.outputDataFreeze.incrementAndGet()
|
||||
|
||||
val isJump = context.show.getNextValidPosition(lastPosition) != position
|
||||
|
||||
if (position < lastPosition) {
|
||||
context.devices.forEach { it.dvs.forEach(DynamicValue<*>::reset) }
|
||||
lastPosition = ShowPosition.START
|
||||
|
@ -164,12 +162,13 @@ fun CoroutineScope.startStepRunning(context: ShowContext) = launch {
|
|||
|
||||
while (lastPosition != position) {
|
||||
lastPosition = context.show.getNextValidPosition(lastPosition) ?: break
|
||||
|
||||
val step = context.show.acts[lastPosition]
|
||||
|
||||
lastStepJob?.cancelAndJoin()
|
||||
if (isJump) context.devices.forEach { it.dvs.forEach(DynamicValue<*>::skipTransition) }
|
||||
|
||||
lastStepJob = launch(SupervisorJob(currentCoroutineContext().job), CoroutineStart.UNDISPATCHED) {
|
||||
val runContext = object : StepRunContext, CoroutineScope by this {}
|
||||
|
||||
step.runner?.let { runContext.it() }
|
||||
}
|
||||
}
|
||||
|
@ -200,8 +199,8 @@ private fun CoroutineScope.startWebsocketServer(context: ShowContext) = launch {
|
|||
|
||||
embeddedServer(CIO, port = 80) {
|
||||
install(WebSockets) {
|
||||
pingPeriod = 10.seconds
|
||||
timeout = 15.seconds
|
||||
pingPeriod = 2.seconds
|
||||
timeout = 5.seconds
|
||||
maxFrameSize = Long.MAX_VALUE
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue