From 83d1c4b46c252642ca6f5abb6330d484e1d91b47 Mon Sep 17 00:00:00 2001 From: Jan Klopper Date: Thu, 31 Mar 2016 14:00:47 +0200 Subject: [PATCH] Make some loops only run when needed, defer pygame updates if nothing changed since last update Draw all packets in queue at once if we get the chance. --- vloed.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/vloed.py b/vloed.py index 96f2c17..811c641 100755 --- a/vloed.py +++ b/vloed.py @@ -65,20 +65,21 @@ class Canvas(object): def CanvasUpdate(self): """Updates the screen according to self.fps""" lasttime = time.time() + changed = False while True: currenttime = time.time() - self.Draw() + changed = self.Draw() or changed if currenttime - lasttime >= 1 / self.fps: pygame.display.flip() + changed = False lasttime = time.time() def Draw(self): """Draws pixels specified in the received packages in the queue""" - try: + if self.queue.empty(): + return False + while not self.queue.empty(): data = self.queue.get() - except: - raise - else: preamble = struct.unpack_from("