From 1679719e7ca8ce433c5714474a32c926161dc5b8 Mon Sep 17 00:00:00 2001 From: rcoh Date: Tue, 4 Jan 2011 17:23:30 -0500 Subject: Some performance improvements -- we also synchronize all the frames, giving us a meaning that even if things slow down, rendering doesn't look weird. --- pixelcore/Pixel.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'pixelcore/Pixel.py') diff --git a/pixelcore/Pixel.py b/pixelcore/Pixel.py index 9f5cc85..b9fc07f 100644 --- a/pixelcore/Pixel.py +++ b/pixelcore/Pixel.py @@ -14,7 +14,8 @@ class Pixel: def __init__(self, location): self.location = location self.events = {} - self.memState = None + self.lastRenderTime = timeops.time() + self.lastRender = (0,0,0) def turnOn(self): self.turnOnFor(-1) @@ -28,24 +29,23 @@ class Pixel: #arg #Add a pixelEvent to the list of active events - def processInput(self,pixelEvent,zindex): #consider migrating arg to dict - self.events[timeops.time()] = (zindex, pixelEvent) + def processInput(self,pixelEvent,zindex, currentTime=None): #consider migrating arg to dict + if currentTime == None: + currentTime = timeops.time() + self.events[currentTime] = (zindex, pixelEvent) def clearAllEvents(self): 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 self.events == []: + def state(self, currentTime=timeops.time()): #TODO: this only evaluates at import time, I think + if currentTime-self.lastRenderTime < 5: + return self.lastRender + if self.events == {}: + self.lastRenderTime = currentTime return (0,0,0) deadEvents = [] - currentTime = timeops.time() resultingColor = (0,0,0) colors = [] for eventTime in self.events: #TODO: right color weighting code @@ -59,7 +59,8 @@ class Pixel: resultingColor = color.combineColors(colors) [self.events.pop(event) for event in deadEvents] resultingColor = [int(round(c)) for c in resultingColor] - self.memState = tuple(resultingColor) + self.lastRender = tuple(resultingColor) + self.lastRenderTime = currentTime return tuple(resultingColor) def __str__(self): -- cgit v1.2.3