mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 03:54:06 +09:00
rudimentary framerate benchmarking (turning it on will make the game run significantly slower)
This commit is contained in:
@@ -112,6 +112,8 @@ object DefaultConfig {
|
|||||||
|
|
||||||
"fx_newlight" to false,
|
"fx_newlight" to false,
|
||||||
|
|
||||||
|
"debug_key_deltat_benchmark" to Input.Keys.SLASH
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// settings regarding debugger
|
// settings regarding debugger
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import net.torvald.terrarum.modulebasegame.ui.UITooltip
|
|||||||
import net.torvald.terrarum.realestate.LandUtil
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
import net.torvald.terrarum.savegame.VirtualDisk
|
import net.torvald.terrarum.savegame.VirtualDisk
|
||||||
import net.torvald.terrarum.ui.ConsoleWindow
|
import net.torvald.terrarum.ui.ConsoleWindow
|
||||||
|
import net.torvald.util.CircularArray
|
||||||
import net.torvald.util.SortedArrayList
|
import net.torvald.util.SortedArrayList
|
||||||
import org.khelekore.prtree.*
|
import org.khelekore.prtree.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -78,6 +79,8 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
|
|||||||
open var uiTooltip: UITooltip = UITooltip()
|
open var uiTooltip: UITooltip = UITooltip()
|
||||||
open var notifier: Notification = Notification()
|
open var notifier: Notification = Notification()
|
||||||
|
|
||||||
|
val deltaTeeBenchmarks = CircularArray<Float>(1024, true)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
consoleHandler.setPosition(0, 0)
|
consoleHandler.setPosition(0, 0)
|
||||||
notifier.setPosition(
|
notifier.setPosition(
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
|||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import com.badlogic.gdx.utils.JsonReader
|
import com.badlogic.gdx.utils.JsonReader
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.unsafe.UnsafeHelper
|
|
||||||
import net.torvald.gdx.graphics.Cvec
|
import net.torvald.gdx.graphics.Cvec
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.App.*
|
import net.torvald.terrarum.App.*
|
||||||
@@ -33,6 +32,7 @@ import net.torvald.terrarum.serialise.Common
|
|||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TerrarumSansBitmap
|
import net.torvald.terrarumsansbitmap.gdx.TerrarumSansBitmap
|
||||||
|
import net.torvald.unsafe.UnsafeHelper
|
||||||
import net.torvald.util.CircularArray
|
import net.torvald.util.CircularArray
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
@@ -114,7 +114,7 @@ object Terrarum : Disposable {
|
|||||||
|
|
||||||
private val javaHeapCircularArray = CircularArray<Int>(64, true)
|
private val javaHeapCircularArray = CircularArray<Int>(64, true)
|
||||||
private val nativeHeapCircularArray = CircularArray<Int>(64, true)
|
private val nativeHeapCircularArray = CircularArray<Int>(64, true)
|
||||||
private val updateRateCircularArray = CircularArray<Double>(16, true)
|
private val updateRateCircularArray = CircularArray<Double>(64, true)
|
||||||
|
|
||||||
val memJavaHeap: Int
|
val memJavaHeap: Int
|
||||||
get() {
|
get() {
|
||||||
@@ -133,7 +133,7 @@ object Terrarum : Disposable {
|
|||||||
val updateRateStr: String
|
val updateRateStr: String
|
||||||
get() {
|
get() {
|
||||||
updateRateCircularArray.appendHead(updateRate)
|
updateRateCircularArray.appendHead(updateRate)
|
||||||
return String.format("%.2f", updateRateCircularArray.maxOrNull() ?: 0.0)
|
return String.format("%.2f", updateRateCircularArray.average())
|
||||||
}
|
}
|
||||||
|
|
||||||
lateinit var testTexture: Texture
|
lateinit var testTexture: Texture
|
||||||
|
|||||||
@@ -153,6 +153,26 @@ object TerrarumPostProcessor : Disposable {
|
|||||||
App.fontGame.draw(it, thisIsDebugStr, 5f, App.scr.height - 24f)
|
App.fontGame.draw(it, thisIsDebugStr, 5f, App.scr.height - 24f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (KeyToggler.isOn(App.getConfigInt("debug_key_deltat_benchmark"))) {
|
||||||
|
batch.color = Toolkit.Theme.COL_ACTIVE
|
||||||
|
batch.inUse {
|
||||||
|
// we're going to assume the data are normally distributed
|
||||||
|
val benchstr = if (INGAME.deltaTeeBenchmarks.elemCount < INGAME.deltaTeeBenchmarks.size) {
|
||||||
|
"ΔF: Gathering data (${INGAME.deltaTeeBenchmarks.elemCount}/${INGAME.deltaTeeBenchmarks.size})"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val tallies = INGAME.deltaTeeBenchmarks.toList()
|
||||||
|
val average = tallies.average()
|
||||||
|
val stdev = (tallies.sumOf { (it - average).sqr() } / tallies.size).sqrt()
|
||||||
|
val low5 = average + stdev * -1.64
|
||||||
|
val low1 = average + stdev * -2.33
|
||||||
|
"ΔF: Avr ${average.format(1)}; 95% ${low5.format(1)}; 99% ${low1.format(1)}; σ ${stdev.format(1)}"
|
||||||
|
}
|
||||||
|
val tw = App.fontGame.getWidth(benchstr)
|
||||||
|
App.fontGame.draw(it, benchstr, Toolkit.drawWidth - tw - 5f, App.scr.height - 24f)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,6 +180,8 @@ object TerrarumPostProcessor : Disposable {
|
|||||||
}
|
}
|
||||||
private val rng = HQRNG()
|
private val rng = HQRNG()
|
||||||
|
|
||||||
|
private fun Double.format(digits: Int) = "%.${digits}f".format(this)
|
||||||
|
|
||||||
private val swizzler = intArrayOf(
|
private val swizzler = intArrayOf(
|
||||||
1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1,
|
1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1,
|
||||||
1,0,0,0, 0,1,0,0, 0,0,0,1, 0,0,1,0,
|
1,0,0,0, 0,1,0,0, 0,0,0,1, 0,0,1,0,
|
||||||
|
|||||||
@@ -581,7 +581,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
// some sketchy test code here
|
// some sketchy test code here
|
||||||
|
|
||||||
|
KeyToggler.forceSet(App.getConfigInt("debug_key_deltat_benchmark"), false)
|
||||||
|
|
||||||
}// END enter
|
}// END enter
|
||||||
|
|
||||||
@@ -819,6 +819,10 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
|
|
||||||
WORLD_UPDATE_TIMER += 1
|
WORLD_UPDATE_TIMER += 1
|
||||||
|
|
||||||
|
if (KeyToggler.isOn(App.getConfigInt("debug_key_deltat_benchmark"))) {
|
||||||
|
deltaTeeBenchmarks.appendHead(1f / Gdx.graphics.deltaTime)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ class CircularArray<T>(val size: Int, val overwriteOnOverflow: Boolean): Iterabl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To just casually add items to the list, use [appendHead], **please!**
|
||||||
|
*/
|
||||||
fun appendTail(item: T) {
|
fun appendTail(item: T) {
|
||||||
// even if overflowing is enabled, appending at tail causes head element to be altered, therefore such action
|
// even if overflowing is enabled, appending at tail causes head element to be altered, therefore such action
|
||||||
// must be blocked by throwing overflow error
|
// must be blocked by throwing overflow error
|
||||||
@@ -183,6 +186,12 @@ class CircularArray<T>(val size: Int, val overwriteOnOverflow: Boolean): Iterabl
|
|||||||
return accumulator
|
return accumulator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun toList(): List<T> {
|
||||||
|
val list = ArrayList<T>()
|
||||||
|
iterator().forEach { list.add(it) }
|
||||||
|
return list.toList()
|
||||||
|
}
|
||||||
|
|
||||||
private inline fun Int.wrap() = this fmod size
|
private inline fun Int.wrap() = this fmod size
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
|||||||
Reference in New Issue
Block a user