maximum_fps
Also periodically update current_fps
Is automatically called at the end of full_frame
.
# Check and sleep to maintain a frame-rate bellow `maximum_fps`
#
# Also periodically update `current_fps`
# Is automatically called at the end of `full_frame`.
fun limit_fps
do
var t = clock.total
if t >= frame_count_deadline then
var cfps = frame_count.to_f / 5.0
self.current_fps = cfps
frame_count = 0
frame_count_deadline = t + 5.0
end
frame_count += 1
var mfps = maximum_fps
if mfps <= 0.0 then return
var lapse = clock.lapse
var dt = lapse.to_f
var target_dt = 1.0 / mfps
if dt < target_dt then
var sleep_t = target_dt - dt
sleep_t.sleep
clock.lapse
end
end
lib/gamnit/limit_fps.nit:52,2--77,4