sigh
This commit is contained in:
parent
666d746936
commit
4ff09bea2b
@ -681,7 +681,7 @@ class StarboundClient private constructor(val clientID: Int) : Closeable {
|
|||||||
blendFunc = BlendFunc.MULTIPLY_WITH_ALPHA
|
blendFunc = BlendFunc.MULTIPLY_WITH_ALPHA
|
||||||
}
|
}
|
||||||
|
|
||||||
val spinner = ExecutionSpinner(mailbox, ::renderFrame, Starbound.TICK_TIME_ADVANCE_NANOS, true)
|
val spinner = ExecutionSpinner(mailbox, ::renderFrame, Starbound.TICK_TIME_ADVANCE_NANOS)
|
||||||
val settings = ClientSettings()
|
val settings = ClientSettings()
|
||||||
|
|
||||||
val viewportCells: ICellAccess = object : ICellAccess {
|
val viewportCells: ICellAccess = object : ICellAccess {
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
package ru.dbotthepony.kstarbound.util
|
package ru.dbotthepony.kstarbound.util
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.kommons.util.MailboxExecutorService
|
import ru.dbotthepony.kommons.util.MailboxExecutorService
|
||||||
import ru.dbotthepony.kstarbound.Starbound
|
import ru.dbotthepony.kstarbound.Starbound
|
||||||
import java.util.concurrent.locks.LockSupport
|
import java.util.concurrent.locks.LockSupport
|
||||||
import java.util.function.BooleanSupplier
|
import java.util.function.BooleanSupplier
|
||||||
|
|
||||||
class ExecutionSpinner(private val executor: MailboxExecutorService, private val spinner: BooleanSupplier, private val timeBetweenFrames: Long, val precise: Boolean = false) : Runnable {
|
class ExecutionSpinner(private val executor: MailboxExecutorService, private val spinner: BooleanSupplier, private val timeBetweenFrames: Long) : Runnable {
|
||||||
|
init {
|
||||||
|
Companion
|
||||||
|
}
|
||||||
|
|
||||||
private var lastRender = System.nanoTime()
|
private var lastRender = System.nanoTime()
|
||||||
private var frameRenderTime = 0L
|
private var frameRenderTime = 0L
|
||||||
private val frameRenderTimes = LongArray(60) { 1L }
|
private val frameRenderTimes = LongArray(60) { 1L }
|
||||||
@ -46,23 +51,10 @@ class ExecutionSpinner(private val executor: MailboxExecutorService, private val
|
|||||||
fun spin(): Boolean {
|
fun spin(): Boolean {
|
||||||
var diff = timeUntilNextFrame()
|
var diff = timeUntilNextFrame()
|
||||||
|
|
||||||
if (precise) {
|
while (diff > 0L) {
|
||||||
while (diff > 1_500_000L) {
|
executor.executeQueuedTasks()
|
||||||
executor.executeQueuedTasks()
|
diff = timeUntilNextFrame()
|
||||||
diff = timeUntilNextFrame()
|
if (diff > 400_000L) LockSupport.parkNanos(100_000L)
|
||||||
if (diff > 1_500_000L) LockSupport.parkNanos(diff - 400_000L)
|
|
||||||
}
|
|
||||||
|
|
||||||
while (diff > 0L) {
|
|
||||||
executor.executeQueuedTasks()
|
|
||||||
diff = timeUntilNextFrame()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (diff > 0L) {
|
|
||||||
executor.executeQueuedTasks()
|
|
||||||
diff = timeUntilNextFrame()
|
|
||||||
if (diff > 400_000L) LockSupport.parkNanos(diff)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val mark = System.nanoTime()
|
val mark = System.nanoTime()
|
||||||
@ -78,4 +70,25 @@ class ExecutionSpinner(private val executor: MailboxExecutorService, private val
|
|||||||
override fun run() {
|
override fun run() {
|
||||||
while (spin()) {}
|
while (spin()) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val LOGGER = LogManager.getLogger()
|
||||||
|
|
||||||
|
init {
|
||||||
|
val thread = object : Thread("Fix God Damn Windows Process Scheduler For Once Please") {
|
||||||
|
override fun run() {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
sleep(Int.MAX_VALUE.toLong())
|
||||||
|
} catch (err: InterruptedException) {
|
||||||
|
LOGGER.error("Timer hack thread was interrupted, ignoring.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thread.isDaemon = true
|
||||||
|
thread.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user