asynced: allow fps() to ignore the first run and to catch up.

master
Michael Hope 4 years ago
parent f11308e4e8
commit 67ecf3b1bf

@ -7,13 +7,17 @@ def delay(secs: float) -> generator:
yield None
def fps(dt: float):
def fps(dt: float) -> generator:
yield None
until = time.monotonic() + dt
while True:
remain = until - time.monotonic()
until += dt
if remain > 0:
time.sleep(remain)
until += dt
if remain < -dt:
# Catch up a bit
until += -remain / 3
yield None

Loading…
Cancel
Save