Commit 31cbcda5 authored by David's avatar David

Evidenced a rendering slowdown bug with multiple animate timelines

parent fa5c4a6a
......@@ -18,20 +18,20 @@ import javafx.scene.text.Text
import javafx.util.Duration
import mu.KotlinLogging
import tornadofx.*
import java.time.LocalDateTime
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
data class TickerEntry(
//Generic the shit out of this!
data class TickerEntry<T : Node>(
val title: String,
val content: Node
) {
//TODO: A way to add rendering logic
//TODO: a way to have a notification when it's cleared, for ones that want to be re-executed
}
val content: T,
val reschedule: Boolean = false,
val update: ((content: T) -> Unit)? = null
)
/**
* Display a ticker view of things
......@@ -77,13 +77,26 @@ class TickerView : View() {
//After some kind of delay maybe
//Race condition, the thing hadn't completely sized before adding it, only a problem early on
// making sure to have a delay int here lays it out proper
//Lets create one that does a time
//This causes the lag that causes them to smear together, need to update the rendering logic to not be threaded
// per each item
val time = TickerEntry("CurrentTime", createText("one")) { text ->
//Automatically called by the thing on the right thread...
text.text = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
//TODO: needs a way of cancelling
}
val entries = listOf(
TickerEntry("blorp", createText("Third!")),
TickerEntry("blerp", createText("this is the second")),
TickerEntry("test", createText(sampleText)),
TickerEntry("more", createText("Some more words")),
TickerEntry("another", createText("This is happening")),
TickerEntry("time", createText(ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)))
//TODO: I have to put way too much crap into that to make this work, something isn't right
TickerEntry<Node>("blorp", createText("Third!")),
TickerEntry<Node>("blerp", createText("this is the second")),
time as TickerEntry<Node>,
TickerEntry<Node>("test", createText(sampleText)),
TickerEntry<Node>("more", createText("Some more words")),
TickerEntry<Node>("another", createText("This is happening")),
TickerEntry<Node>("time", createText(ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)))
)
Observable.fromIterable(entries)
.observeOn(Schedulers.computation())
......@@ -107,9 +120,9 @@ class MarqueeView : View() {
private val logger = KotlinLogging.logger {}
private val OFFSET = 5.0 //Amount of space between entries!
val tickEntries = PublishProcessor.create<TickerEntry>()
val tickEntries = PublishProcessor.create<TickerEntry<Node>>()
data class ClearedTick(val entry: TickerEntry)
data class ClearedTick(val entry: TickerEntry<Node>)
private val pane: Pane = pane()
private val singleThread = Executors.newSingleThreadExecutor() //TODO: really need a way to clean this up
......@@ -135,7 +148,7 @@ class MarqueeView : View() {
//TODO: I don't have a good way of cleaning up the executor service. Need to figure that out
//Create a backpressure based flowable that only processes one item at a time.
Flowable.create<TickerEntry>({ emitter ->
Flowable.create<TickerEntry<Node>>({ emitter ->
tickEntries
.observeOn(Schedulers.computation())
.doOnNext {
......@@ -173,7 +186,7 @@ class MarqueeView : View() {
//Will need to fire one of these for each thing, with some space detection, based on when one is ending.
private fun animateText(entry: TickerEntry, publishSubject: PublishProcessor<ClearedTick>) {
private fun animateText(entry: TickerEntry<Node>, publishSubject: PublishProcessor<ClearedTick>) {
val content = entry.content
val emptyStart = root.prefWidth //It's weird, like a race condition
......@@ -184,6 +197,8 @@ class MarqueeView : View() {
val cleared = AtomicBoolean(false)
val timeline = Timeline()
//TODO: need to establish a single timeline, not a timeline per element
//I want any rendering delays to slow the whole thing, not just the individual item. Also then it's less threads
val updateFrame = KeyFrame(Duration.millis(35.0), EventHandler<ActionEvent> {
//I don't intend to bounce this
val textWidth = content.layoutBounds.width
......@@ -206,6 +221,12 @@ class MarqueeView : View() {
} else {
content.layoutX = content.layoutX - 1 //TODO: I should probably do animation in larger chunks perhaps, so that it can use less CPU?
//TODO: this might be where I need to make other animation happen
if (entry.update != null) {
timeline.pause()
entry.update.invoke(entry.content)
timeline.play()
}
}
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment