Eliminate unintentional entity tick time increase
This commit is contained in:
parent
b5c9b1f35a
commit
23dab02cc5
@ -254,17 +254,30 @@ abstract class AbstractEntity : Comparable<AbstractEntity> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for fast check on completed tasks
|
|
||||||
// This is necessary to cancel tasks when we are removed, so we don't reference ourselves
|
// This is necessary to cancel tasks when we are removed, so we don't reference ourselves
|
||||||
// in event loop after we have been removed
|
// in event loop after we have been removed
|
||||||
private val scheduledTasks = PriorityQueue<ScheduledFuture<*>>()
|
private val scheduledTasks = ObjectArrayList<ScheduledFuture<*>>()
|
||||||
|
|
||||||
protected fun scheduleInTicks(ticks: Int, action: Runnable) {
|
protected fun scheduleInTicks(ticks: Int, action: Runnable) {
|
||||||
scheduledTasks.add(world.eventLoop.schedule(action, ticks * Starbound.TIMESTEP_NANOS, TimeUnit.NANOSECONDS))
|
var task: ScheduledFuture<*>? = null
|
||||||
|
|
||||||
|
task = world.eventLoop.schedule(Runnable {
|
||||||
|
scheduledTasks.remove(task!!)
|
||||||
|
action.run()
|
||||||
|
}, ticks * Starbound.TIMESTEP_NANOS, TimeUnit.NANOSECONDS)
|
||||||
|
|
||||||
|
scheduledTasks.add(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun schedule(time: Long, unit: TimeUnit, action: Runnable) {
|
protected fun schedule(time: Long, unit: TimeUnit, action: Runnable) {
|
||||||
scheduledTasks.add(world.eventLoop.schedule(action, time, unit))
|
var task: ScheduledFuture<*>? = null
|
||||||
|
|
||||||
|
task = world.eventLoop.schedule(Runnable {
|
||||||
|
scheduledTasks.remove(task!!)
|
||||||
|
action.run()
|
||||||
|
}, time, unit)
|
||||||
|
|
||||||
|
scheduledTasks.add(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
var isRemote: Boolean = false
|
var isRemote: Boolean = false
|
||||||
@ -382,10 +395,6 @@ abstract class AbstractEntity : Comparable<AbstractEntity> {
|
|||||||
open fun damagedOther(notification: DamageNotificationPacket) {}
|
open fun damagedOther(notification: DamageNotificationPacket) {}
|
||||||
|
|
||||||
open fun tick(delta: Double) {
|
open fun tick(delta: Double) {
|
||||||
while (scheduledTasks.isNotEmpty() && scheduledTasks.peek().isDone) {
|
|
||||||
scheduledTasks.poll()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (networkGroup.upstream.isInterpolating) {
|
if (networkGroup.upstream.isInterpolating) {
|
||||||
networkGroup.upstream.tickInterpolation(delta)
|
networkGroup.upstream.tickInterpolation(delta)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user