Use PriorityQueue over AVLTreeSet with hacks
This commit is contained in:
parent
dc47b3a13e
commit
884caba048
@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
|
|||||||
import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet
|
import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet
|
||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.mc.otm.core.addSorted
|
import ru.dbotthepony.mc.otm.core.addSorted
|
||||||
|
import java.util.PriorityQueue
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
class TickList : ITickable {
|
class TickList : ITickable {
|
||||||
@ -17,8 +18,7 @@ class TickList : ITickable {
|
|||||||
private val alwaysQueued = ArrayList<ITickable>()
|
private val alwaysQueued = ArrayList<ITickable>()
|
||||||
private val toRemoveFromAlways = ArrayList<ITickable>()
|
private val toRemoveFromAlways = ArrayList<ITickable>()
|
||||||
|
|
||||||
private val timers = ObjectAVLTreeSet<Timer>()
|
private val timers = PriorityQueue<Timer>()
|
||||||
private val nextTimerID = AtomicInteger()
|
|
||||||
private val namedTimers = Object2ObjectOpenHashMap<Any, Timer>(0)
|
private val namedTimers = Object2ObjectOpenHashMap<Any, Timer>(0)
|
||||||
|
|
||||||
private var shouldTick = false
|
private var shouldTick = false
|
||||||
@ -32,7 +32,6 @@ class TickList : ITickable {
|
|||||||
|
|
||||||
inner class Timer(val timerTicks: Int, val runnable: Runnable) : Comparable<Timer> {
|
inner class Timer(val timerTicks: Int, val runnable: Runnable) : Comparable<Timer> {
|
||||||
val ringAt = ticks + timerTicks
|
val ringAt = ticks + timerTicks
|
||||||
val timerID = nextTimerID.incrementAndGet()
|
|
||||||
|
|
||||||
var finished = false
|
var finished = false
|
||||||
private set
|
private set
|
||||||
@ -43,10 +42,7 @@ class TickList : ITickable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun compareTo(other: Timer): Int {
|
override fun compareTo(other: Timer): Int {
|
||||||
var c = ringAt.compareTo(other.ringAt)
|
return ringAt.compareTo(other.ringAt)
|
||||||
if (c != 0) return c
|
|
||||||
c = timerID.compareTo(other.timerID)
|
|
||||||
return c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun execute() {
|
fun execute() {
|
||||||
@ -230,7 +226,7 @@ class TickList : ITickable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (timers.isNotEmpty()) {
|
while (timers.isNotEmpty()) {
|
||||||
val head = timers.first()
|
val head = timers.peek()
|
||||||
|
|
||||||
if (head.ringAt <= ticks) {
|
if (head.ringAt <= ticks) {
|
||||||
head.execute()
|
head.execute()
|
||||||
|
Loading…
Reference in New Issue
Block a user