mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
fixed a "bug" that assumed the framerates are normally distributed
This commit is contained in:
@@ -1078,6 +1078,10 @@ public class App implements ApplicationListener {
|
|||||||
screenshotRequested = true;
|
screenshotRequested = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isScreenshotRequested() {
|
||||||
|
return screenshotRequested;
|
||||||
|
}
|
||||||
|
|
||||||
// DEFAULT DIRECTORIES //
|
// DEFAULT DIRECTORIES //
|
||||||
|
|
||||||
public static String OSName = System.getProperty("os.name");
|
public static String OSName = System.getProperty("os.name");
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ object DefaultConfig {
|
|||||||
|
|
||||||
"fx_newlight" to false,
|
"fx_newlight" to false,
|
||||||
|
|
||||||
"debug_key_deltat_benchmark" to Input.Keys.SLASH
|
"debug_key_deltat_benchmark" to Input.Keys.SLASH,
|
||||||
|
"debug_deltat_benchmark_sample_sizes" to 2048,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ 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)
|
val deltaTeeBenchmarks = CircularArray<Float>(App.getConfigInt("debug_deltat_benchmark_sample_sizes"), true)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
consoleHandler.setPosition(0, 0)
|
consoleHandler.setPosition(0, 0)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
|||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||||
import com.badlogic.gdx.math.Matrix4
|
import com.badlogic.gdx.math.Matrix4
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||||
import net.torvald.terrarum.ui.BasicDebugInfoWindow
|
import net.torvald.terrarum.ui.BasicDebugInfoWindow
|
||||||
@@ -162,12 +163,20 @@ object TerrarumPostProcessor : Disposable {
|
|||||||
"ΔF: Gathering data (${INGAME.deltaTeeBenchmarks.elemCount}/${INGAME.deltaTeeBenchmarks.size})"
|
"ΔF: Gathering data (${INGAME.deltaTeeBenchmarks.elemCount}/${INGAME.deltaTeeBenchmarks.size})"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val tallies = INGAME.deltaTeeBenchmarks.toList()
|
val tallies = INGAME.deltaTeeBenchmarks.toList().sorted()
|
||||||
val average = tallies.average()
|
val average = tallies.average()
|
||||||
val stdev = (tallies.sumOf { (it - average).sqr() } / tallies.size).sqrt()
|
|
||||||
val low5 = average + stdev * -1.64
|
val halfPos = 0.5f * INGAME.deltaTeeBenchmarks.size
|
||||||
val low1 = average + stdev * -2.33
|
val halfInd = halfPos.floorInt()
|
||||||
"ΔF: Avr ${average.format(1)}; 95% ${low5.format(1)}; 99% ${low1.format(1)}; σ ${stdev.format(1)}"
|
val low5pos = 0.05f * INGAME.deltaTeeBenchmarks.size
|
||||||
|
val low5ind = low5pos.floorInt()
|
||||||
|
val low1pos = 0.01f * INGAME.deltaTeeBenchmarks.size
|
||||||
|
val low1ind = low1pos.floorInt()
|
||||||
|
|
||||||
|
val median = FastMath.interpolateLinear(halfPos - halfInd, tallies[halfInd], tallies[halfInd + 1])
|
||||||
|
val low5 = FastMath.interpolateLinear(low5pos - low5ind, tallies[low5ind], tallies[low5ind + 1])
|
||||||
|
val low1 = FastMath.interpolateLinear(low1pos - low1ind, tallies[low1ind], tallies[low1ind + 1])
|
||||||
|
"ΔF: Avr ${average.format(1)}; Med ${median.format(1)}; 5% ${low5.format(1)}; 1% ${low1.format(1)}"
|
||||||
}
|
}
|
||||||
val tw = App.fontGame.getWidth(benchstr)
|
val tw = App.fontGame.getWidth(benchstr)
|
||||||
App.fontGame.draw(it, benchstr, Toolkit.drawWidth - tw - 5f, App.scr.height - 24f)
|
App.fontGame.draw(it, benchstr, Toolkit.drawWidth - tw - 5f, App.scr.height - 24f)
|
||||||
@@ -181,6 +190,7 @@ object TerrarumPostProcessor : Disposable {
|
|||||||
private val rng = HQRNG()
|
private val rng = HQRNG()
|
||||||
|
|
||||||
private fun Double.format(digits: Int) = "%.${digits}f".format(this)
|
private fun Double.format(digits: Int) = "%.${digits}f".format(this)
|
||||||
|
private fun Float.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,
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ import com.badlogic.gdx.utils.Disposable
|
|||||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.App.*
|
import net.torvald.terrarum.App.measureDebugTime
|
||||||
import net.torvald.terrarum.Terrarum.ingame
|
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
@@ -222,7 +221,7 @@ object IngameRenderer : Disposable {
|
|||||||
this.player = player
|
this.player = player
|
||||||
|
|
||||||
|
|
||||||
if (!gamePaused || newWorldLoadedLatch) {
|
if ((!gamePaused && !App.isScreenshotRequested()) || newWorldLoadedLatch) {
|
||||||
measureDebugTime("Renderer.LightRun*") {
|
measureDebugTime("Renderer.LightRun*") {
|
||||||
// recalculate for even frames, or if the sign of the cam-x changed
|
// recalculate for even frames, or if the sign of the cam-x changed
|
||||||
if (App.GLOBAL_RENDER_TIMER % 3 == 0 || Math.abs(WorldCamera.x - oldCamX) >= world.width * 0.85f * TILE_SIZEF || newWorldLoadedLatch) {
|
if (App.GLOBAL_RENDER_TIMER % 3 == 0 || Math.abs(WorldCamera.x - oldCamX) >= world.width * 0.85f * TILE_SIZEF || newWorldLoadedLatch) {
|
||||||
|
|||||||
@@ -742,6 +742,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
private var oldCamX = 0
|
private var oldCamX = 0
|
||||||
private var oldPlayerX = 0.0
|
private var oldPlayerX = 0.0
|
||||||
|
|
||||||
|
private var deltaTeeCleared = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ingame (world) related updates; UI update must go to renderGame()
|
* Ingame (world) related updates; UI update must go to renderGame()
|
||||||
*/
|
*/
|
||||||
@@ -756,7 +758,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
// will also queue up the block/wall/wire placed events
|
// will also queue up the block/wall/wire placed events
|
||||||
ingameController.update()
|
ingameController.update()
|
||||||
|
|
||||||
if (!paused || newWorldLoadedLatch) {
|
if ((!paused && !App.isScreenshotRequested()) || newWorldLoadedLatch) {
|
||||||
|
|
||||||
//hypothetical_input_capturing_function_if_you_finally_decided_to_forgo_gdx_input_processor_and_implement_your_own_to_synchronise_everything()
|
//hypothetical_input_capturing_function_if_you_finally_decided_to_forgo_gdx_input_processor_and_implement_your_own_to_synchronise_everything()
|
||||||
|
|
||||||
@@ -822,11 +824,17 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
if (KeyToggler.isOn(App.getConfigInt("debug_key_deltat_benchmark"))) {
|
if (KeyToggler.isOn(App.getConfigInt("debug_key_deltat_benchmark"))) {
|
||||||
deltaTeeBenchmarks.appendHead(1f / Gdx.graphics.deltaTime)
|
deltaTeeBenchmarks.appendHead(1f / Gdx.graphics.deltaTime)
|
||||||
|
|
||||||
|
if (deltaTeeCleared) deltaTeeCleared = false
|
||||||
|
}
|
||||||
|
else if (!deltaTeeCleared) {
|
||||||
|
deltaTeeCleared = true
|
||||||
|
deltaTeeBenchmarks.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!paused || newWorldLoadedLatch) {
|
if ((!paused && !App.isScreenshotRequested()) || newWorldLoadedLatch) {
|
||||||
// completely consume block change queues because why not
|
// completely consume block change queues because why not
|
||||||
terrainChangeQueue.clear()
|
terrainChangeQueue.clear()
|
||||||
wallChangeQueue.clear()
|
wallChangeQueue.clear()
|
||||||
@@ -858,7 +866,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
//println("paused = $paused")
|
//println("paused = $paused")
|
||||||
|
|
||||||
if (!paused && newWorldLoadedLatch) newWorldLoadedLatch = false
|
if ((!paused && !App.isScreenshotRequested()) && newWorldLoadedLatch) newWorldLoadedLatch = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user