From 353ab16db64c86122c0fcb9e1852b85c14b354b8 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Fri, 3 Dec 2010 04:20:17 -0500 Subject: Speed optimizations abound! Caching on parameter validation, Binary searching for light locations in pixel mappers, actual thread safety for inputs means we don't drop them randomly, anymore. Caching on PixelStates to reduce multi-renderer costs + a short circuit to speed up processing on pixels that are turned off. --- pixelcore/Pixel.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'pixelcore/Pixel.py') diff --git a/pixelcore/Pixel.py b/pixelcore/Pixel.py index 8c42581..4c8ec89 100644 --- a/pixelcore/Pixel.py +++ b/pixelcore/Pixel.py @@ -12,6 +12,7 @@ class Pixel: def __init__(self, location): self.location = location self.events = {} + self.memState = None def turnOn(self): self.turnOnFor(-1) #Turn the light white for 'time' ms. Really only meant for testing. Use @@ -28,7 +29,13 @@ class Pixel: self.events = {} #Combines all PixelEvents currently active and computes the current color of #the pixel. + def invalidateState(self): + self.memState = None def state(self): + if self.memState != None: + return self.memState + if len(self.events) == 0: + return (0,0,0) deadEvents = [] currentTime = Util.time() resultingColor = (0,0,0) @@ -40,6 +47,7 @@ class Pixel: else: deadEvents.append(eventTime) [self.events.pop(event) for event in deadEvents] + self.memState = tuple(resultingColor) return tuple(resultingColor) def __str__(self): return 'Loc: ' + str(self.location) -- cgit v1.2.3