Proper tps calculation

This commit is contained in:
loucass003 committed 2026-04-08 07:34:24 +02:00
1 parent 4e69262240
commit bf3168af2b
1 file changed
+6 -1
@@ -1,5 +1,6 @@
package dev.slimevr.tracker
import kotlin.time.TimeSource
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.distinctUntilChangedBy
import kotlinx.coroutines.flow.launchIn
@@ -24,9 +25,13 @@ object TrackerTPSBehaviour : TrackerBehaviour {
}.launchIn(receiver.scope)
receiver.scope.launch {
var mark = TimeSource.Monotonic.markNow()
while (isActive) {
delay(1000)
receiver.dispatch(TrackerActions.Update { copy(tps = count.exchange(0).toUShort()) })
val elapsed = mark.elapsedNow()
val tps = count.exchange(0) * 1000L / elapsed.inWholeMilliseconds
receiver.dispatch(TrackerActions.Update { copy(tps = tps.toUShort()) })
mark = TimeSource.Monotonic.markNow()
}
}
}