Created
June 2, 2016 16:07
-
-
Save ousttrue/0192bd14161fef4c816f912092a842a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import asyncio | |
import datetime | |
import logging | |
import time | |
logger = logging.getLogger(__name__) | |
logger.addHandler(logging.StreamHandler()) | |
logger.setLevel(logging.DEBUG) | |
def main_loop(on_update, fps=60): | |
#asyncio.set_event_loop(asyncio.ProactorEventLoop()) | |
loop = asyncio.get_event_loop() | |
async def loop_func(): | |
frame_par_seconds=1.0/fps | |
frame_count=0 | |
last_frame_second=int(loop.time()) | |
while True: | |
start_time=loop.time() | |
end_time = start_time + frame_par_seconds | |
frame_count+=1 | |
frame_second=int(start_time) | |
if frame_second!=last_frame_second: | |
logger.debug("%d frames/sec", frame_count) | |
frame_count=0 | |
last_frame_second=frame_second | |
on_update() | |
await asyncio.sleep(frame_par_seconds - (loop.time()-start_time)) | |
loop.run_until_complete(loop_func()) | |
loop.close() | |
def on_update(): | |
time.sleep(0.014) | |
pass | |
main_loop(on_update, fps=60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment