Commit 5441fb3c authored by David's avatar David

A bit of optimization on calculating when something has cleared

parent 58c42686
......@@ -173,7 +173,8 @@ class MarqueeView : View() {
private val logger = KotlinLogging.logger {}
private val OFFSET = 5.0 //Amount of space between entries!
private val activeTicks = ConcurrentLinkedQueue<TickerEntry<Node>>() //This might not need to be threadsafe, only one thing is adding/removing it
data class ActiveTick(val entry: TickerEntry<Node>, var cleared: Boolean = false)
private val activeTicks = ConcurrentLinkedQueue<ActiveTick>() //This might not need to be threadsafe, only one thing is adding/removing it
private val queuedTicks = ConcurrentLinkedQueue<TickerEntry<Node>>() //This one does, multiple threads!
private val pane: Pane = pane()
......@@ -215,7 +216,14 @@ class MarqueeView : View() {
fun lastOneCleared(): Boolean {
//Determine if the last entry in the activeQueue has cleared
val last = activeTicks.last()
return last.content.layoutBounds.width + last.content.layoutX + OFFSET <= root.width
if(!last.cleared){
//Only do the math one time, well up to many times, but it might be cleared, and then clean it out
val entry = last.entry
if(entry.content.layoutBounds.width + entry.content.layoutX + OFFSET <= root.width) {
last.cleared = true
}
}
return last.cleared
}
val subscriptions = HashMap<TickerEntry<Node>, Disposable>()
......@@ -230,13 +238,14 @@ class MarqueeView : View() {
if (newTickerEntry != null) {
//Then just put it into the active queue, so it will start processing like normal
newTickerEntry.content.layoutX = root.prefWidth //Where to start
activeTicks.add(newTickerEntry)
activeTicks.add(ActiveTick(newTickerEntry))
root.add(newTickerEntry.content) //this is where it gets added
//But I never remove them!?!? UH OH They get removed later
}
}
//Something isn't working out right here.
activeTicks.forEach { entry ->
activeTicks.forEach { active ->
val entry = active.entry
val content = entry.content
//I don't intend to bounce this
......@@ -251,7 +260,7 @@ class MarqueeView : View() {
logger.debug("ANIMATED ${entry.title} COMPLETELY OUT THE PANEL!")
//Now I ned to figure out how to remove it
entry.content.removeFromParent() //Is this legit?
activeTicks.remove(entry) //no longer here, shouldn't ruin the loop
activeTicks.remove(active) //no longer here, shouldn't ruin the loop
if (subscriptions.containsKey(entry)) {
subscriptions.remove(entry)!!.dispose() //This should cancel it
logger.debug("disposing observable for ${entry.title}")
......
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