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