mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-19 18:49:19 +01:00
Fix FPS counter "frame" skip
This commit is contained in:
parent
b03078ff27
commit
667a74519a
@ -55,7 +55,7 @@ object OcelotDesktop extends LoggingConfiguration with Logging {
|
||||
def emulationPaused_=(paused: Boolean): Unit = {
|
||||
_emulationPaused = paused
|
||||
// avoid sudden jumps of TPS counter after a pause
|
||||
if (!paused) tpsCounter.skipFrame()
|
||||
if (!paused) tpsCounter.skipSecond()
|
||||
}
|
||||
|
||||
private val TickerIntervalHistorySize = 5
|
||||
|
||||
@ -9,29 +9,31 @@ class FPSCalculator {
|
||||
|
||||
def fps: Float = _fps
|
||||
|
||||
private var _skipFrame = false
|
||||
private var _skipSecond = false
|
||||
|
||||
/**
|
||||
* Next tick will not count towards the overall statistics.
|
||||
* Current second will not count towards the overall statistics.
|
||||
* (In case the measurements were corrupted or distorted somehow.)
|
||||
*/
|
||||
def skipFrame(): Unit = _skipFrame = true
|
||||
def skipSecond(): Unit = _skipSecond = true
|
||||
|
||||
var dt: Float = 0
|
||||
|
||||
def tick(): Unit = {
|
||||
val currentTime = System.currentTimeMillis()
|
||||
|
||||
if (!_skipFrame) {
|
||||
dt = (currentTime - prevFrameTime) / 1000f
|
||||
dt = (currentTime - prevFrameTime) / 1000f
|
||||
numFrames += 1
|
||||
|
||||
numFrames += 1
|
||||
|
||||
if (currentTime - prevTime > 1000) {
|
||||
val delta = currentTime - prevTime
|
||||
prevTime = currentTime
|
||||
_fps = numFrames.asInstanceOf[Float] / delta * 1000f
|
||||
numFrames = 0
|
||||
if (currentTime - prevTime > 1000) {
|
||||
val delta = currentTime - prevTime
|
||||
prevTime = currentTime
|
||||
if (!_skipSecond) {
|
||||
_fps = numFrames.toFloat / delta * 1000.0f
|
||||
} else {
|
||||
_skipSecond = false
|
||||
}
|
||||
numFrames = 0
|
||||
}
|
||||
|
||||
prevFrameTime = currentTime
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user