mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59: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 = {
|
def emulationPaused_=(paused: Boolean): Unit = {
|
||||||
_emulationPaused = paused
|
_emulationPaused = paused
|
||||||
// avoid sudden jumps of TPS counter after a pause
|
// avoid sudden jumps of TPS counter after a pause
|
||||||
if (!paused) tpsCounter.skipFrame()
|
if (!paused) tpsCounter.skipSecond()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val TickerIntervalHistorySize = 5
|
private val TickerIntervalHistorySize = 5
|
||||||
|
|||||||
@ -9,29 +9,31 @@ class FPSCalculator {
|
|||||||
|
|
||||||
def fps: Float = _fps
|
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
|
var dt: Float = 0
|
||||||
|
|
||||||
def tick(): Unit = {
|
def tick(): Unit = {
|
||||||
val currentTime = System.currentTimeMillis()
|
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
|
||||||
if (currentTime - prevTime > 1000) {
|
prevTime = currentTime
|
||||||
val delta = currentTime - prevTime
|
if (!_skipSecond) {
|
||||||
prevTime = currentTime
|
_fps = numFrames.toFloat / delta * 1000.0f
|
||||||
_fps = numFrames.asInstanceOf[Float] / delta * 1000f
|
} else {
|
||||||
numFrames = 0
|
_skipSecond = false
|
||||||
}
|
}
|
||||||
|
numFrames = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
prevFrameTime = currentTime
|
prevFrameTime = currentTime
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user