aboutsummaryrefslogtreecommitdiff
path: root/pixelcore
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-01-04 17:23:30 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-01-04 17:23:30 -0500
commit1679719e7ca8ce433c5714474a32c926161dc5b8 (patch)
treedc75dc66ee8695fe786df2b48c0e6911332ed7c5 /pixelcore
parent395e99394ead5d0d656e74fed23dc780652b6090 (diff)
Some performance improvements -- we also synchronize all the frames, giving us a meaning that even
if things slow down, rendering doesn't look weird.
Diffstat (limited to 'pixelcore')
-rw-r--r--pixelcore/Pixel.py25
-rw-r--r--pixelcore/Screen.py5
2 files changed, 16 insertions, 14 deletions
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):
diff --git a/pixelcore/Screen.py b/pixelcore/Screen.py
index b002896..198bd3f 100644
--- a/pixelcore/Screen.py
+++ b/pixelcore/Screen.py
@@ -5,6 +5,7 @@ from operationscore.PixelMapper import *
import util.Search as Search
import util.ComponentRegistry as compReg
import util.Strings as Strings
+import util.TimeOps as timeops
import itertools
import sys
from logger import main_log
@@ -54,7 +55,6 @@ class Screen:
self.responseQueue = []
for response in tempQueue:
self.processResponse(response)
- [p.invalidateState() for p in self]
#public
def respond(self, responseInfo):
@@ -92,6 +92,7 @@ class Screen:
main_log.debug(str(len(pixelWeightList)))
main_log.debug(pixelWeightList)
PixelEvent.addPixelEventIfMissing(responseInfo)
+ currentTime = timeops.time()
for (pixel, weight) in pixelWeightList:
- pixel.processInput(responseInfo['PixelEvent'].scale(weight), 0) #TODO: z-index
+ pixel.processInput(responseInfo['PixelEvent'].scale(weight), 0, currentTime) #TODO: z-index