mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-02 13:00:53 +00:00
21 lines
526 B
Swift
21 lines
526 B
Swift
import Foundation
|
|
|
|
public struct FPSCalculator {
|
|
private var _accumulator = Duration.zero
|
|
private var _framesCount = 0
|
|
|
|
public mutating func frame(deltaTime: Duration, result: (_ fps: Int) -> Void) {
|
|
self._framesCount += 1
|
|
self._accumulator += deltaTime
|
|
|
|
if self._accumulator >= Duration.seconds(1) {
|
|
result(self._framesCount)
|
|
|
|
self._framesCount = 0
|
|
self._accumulator = .init(
|
|
secondsComponent: 0,
|
|
attosecondsComponent: self._accumulator.components.attoseconds)
|
|
}
|
|
}
|
|
}
|