Merge pull request #3 from CodePanter/master
Optimized pygame, and moved 'packetformat' out of the for loop.
This commit is contained in:
commit
31b02f426b
1 changed files with 6 additions and 2 deletions
8
vloed.py
8
vloed.py
|
|
@ -9,6 +9,7 @@ __version__ = 0.2
|
||||||
__author__ = "Jan Klopper <jan@underdark.nl>"
|
__author__ = "Jan Klopper <jan@underdark.nl>"
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
from pygame.locals import *
|
||||||
import struct
|
import struct
|
||||||
import time
|
import time
|
||||||
from gevent import spawn, socket, monkey
|
from gevent import spawn, socket, monkey
|
||||||
|
|
@ -49,7 +50,9 @@ class Canvas(object):
|
||||||
def canvas(self, width=1366, height=768):
|
def canvas(self, width=1366, height=768):
|
||||||
"""Init the pygame canvas"""
|
"""Init the pygame canvas"""
|
||||||
pygame.init()
|
pygame.init()
|
||||||
self.screen = pygame.display.set_mode((width, height))
|
pygame.mixer.quit()
|
||||||
|
flags = DOUBLEBUF
|
||||||
|
self.screen = pygame.display.set_mode((width, height), flags)
|
||||||
|
|
||||||
def clear(self, r=0, g=0, b=0): # pylint: disable=C0103
|
def clear(self, r=0, g=0, b=0): # pylint: disable=C0103
|
||||||
""" Fill the entire screen with a solid colour (default: black)"""
|
""" Fill the entire screen with a solid colour (default: black)"""
|
||||||
|
|
@ -78,6 +81,7 @@ class Canvas(object):
|
||||||
else:
|
else:
|
||||||
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]
|
||||||
|
packetformat = ("<2H4B" if preamble else "<2H3B")
|
||||||
pixellength = 7 #xx,yy,r,g,b
|
pixellength = 7 #xx,yy,r,g,b
|
||||||
if preamble:
|
if preamble:
|
||||||
pixellength = 8 #xx,yy,r,g,b,a
|
pixellength = 8 #xx,yy,r,g,b,a
|
||||||
|
|
@ -86,7 +90,7 @@ class Canvas(object):
|
||||||
print '%d pixels received, protocol V %d ' % (pixelcount, protocol)
|
print '%d pixels received, protocol V %d ' % (pixelcount, protocol)
|
||||||
for i in xrange(0, pixelcount):
|
for i in xrange(0, pixelcount):
|
||||||
pixel = struct.unpack_from(
|
pixel = struct.unpack_from(
|
||||||
("<2H4B" if preamble else "<2H3B"),
|
packetformat,
|
||||||
data,
|
data,
|
||||||
self.pixeloffset + (i*pixellength))
|
self.pixeloffset + (i*pixellength))
|
||||||
if self.debug:
|
if self.debug:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue