rework loops to return at least once per fps
This commit is contained in:
parent
da2f29c38a
commit
c9c45df928
1 changed files with 5 additions and 5 deletions
10
vloed.py
10
vloed.py
|
|
@ -67,18 +67,18 @@ class Canvas(object):
|
||||||
lasttime = time.time()
|
lasttime = time.time()
|
||||||
changed = False
|
changed = False
|
||||||
while True:
|
while True:
|
||||||
currenttime = time.time()
|
nextdraw = time.time() + (1 / self.fps)
|
||||||
changed = self.Draw() or changed
|
changed = self.Draw(nextdraw) or changed
|
||||||
if currenttime - lasttime >= 1 / self.fps:
|
if time.time() - lasttime >= 1 / self.fps:
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
changed = False
|
changed = False
|
||||||
lasttime = time.time()
|
lasttime = time.time()
|
||||||
|
|
||||||
def Draw(self):
|
def Draw(self, returntime):
|
||||||
"""Draws pixels specified in the received packages in the queue"""
|
"""Draws pixels specified in the received packages in the queue"""
|
||||||
if self.queue.empty():
|
if self.queue.empty():
|
||||||
return False
|
return False
|
||||||
while not self.queue.empty():
|
while not self.queue.empty() and time.time() < returntime:
|
||||||
data = self.queue.get()
|
data = self.queue.get()
|
||||||
preamble = struct.unpack_from("<?", data)[0]
|
preamble = struct.unpack_from("<?", data)[0]
|
||||||
protocol = struct.unpack_from("<B", data, 1)[0]
|
protocol = struct.unpack_from("<B", data, 1)[0]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue