mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-03 21:21:34 +00:00
19 lines
386 B
Swift
19 lines
386 B
Swift
|
import Foundation
|
||
|
|
||
|
public struct FPSCalculator {
|
||
|
private var _accumulator = 0.0
|
||
|
private var _framesCount = 0
|
||
|
|
||
|
public mutating func frame(deltaTime: Double, result: (_ fps: Int) -> Void) {
|
||
|
_framesCount += 1
|
||
|
_accumulator += deltaTime
|
||
|
|
||
|
if (_accumulator >= 1.0) {
|
||
|
result(_framesCount)
|
||
|
|
||
|
_framesCount = 0
|
||
|
_accumulator = fmod(_accumulator, 1.0)
|
||
|
}
|
||
|
}
|
||
|
}
|