aboutsummaryrefslogtreecommitdiff
path: root/pixelcore
diff options
context:
space:
mode:
Diffstat (limited to 'pixelcore')
-rw-r--r--pixelcore/Pixel.py33
-rw-r--r--pixelcore/Screen.py25
2 files changed, 40 insertions, 18 deletions
diff --git a/pixelcore/Pixel.py b/pixelcore/Pixel.py
index 7260e56..2f21fd8 100644
--- a/pixelcore/Pixel.py
+++ b/pixelcore/Pixel.py
@@ -13,7 +13,7 @@ class Pixel:
def __init__(self, location):
self.location = location
- self.events = {}
+ self.events = []
self.lastRenderTime = timeops.time()
self.lastRender = (0,0,0)
@@ -30,34 +30,45 @@ class Pixel:
#Add a pixelEvent to the list of active events
def processInput(self,pixelEvent,zindex, scale=1,currentTime=None): #consider migrating arg to dict
+ #TODO: fix for multiple pixel events
if currentTime == None:
currentTime = timeops.time()
- self.events[currentTime] = (zindex,scale, pixelEvent)
-
+ #if not currentTime in self.events:
+ # self.events[currentTime] = []
+ #self.events[currentTime].append((zindex,scale, pixelEvent))
+ self.events.append((currentTime, zindex, scale, pixelEvent)) #TODO: this is kindof
+ #gross
def clearAllEvents(self):
- self.events = {}
+ self.events = []
#Combines all PixelEvents currently active and computes the current color of
#the pixel.
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 == {}:
+ if self.events == []:
self.lastRenderTime = currentTime
return (0,0,0)
deadEvents = []
resultingColor = (0,0,0)
colors = []
- for eventTime in self.events: #TODO: right color weighting code
- (zindex,scale,event) = self.events[eventTime]
- eventResult = event.state(currentTime-eventTime)
+ for eventObj in self.events: #TODO: right color weighting code
+ if len(self.events) > 50:
+ pdb.set_trace()
+ #TODO: this sucks. fix it
+ eventTime, zindex, scale, pixelEvent = eventObj
+ eventResult = pixelEvent.state(currentTime-eventTime)
if eventResult != None:
- colors.append(color.multiplyColor(eventResult,scale))
+ scaledEvent = color.multiplyColor(eventResult,scale)
+ if (scaledEvent[0] + scaledEvent[1] + scaledEvent[2]) < 5:
+ deadEvents.append(eventObj)
+ else:
+ colors.append(scaledEvent)
else:
- deadEvents.append(eventTime)
+ deadEvents.append(eventObj)
resultingColor = color.combineColors(colors)
- [self.events.pop(event) for event in deadEvents]
+ [self.events.remove(event) for event in deadEvents]
resultingColor = [int(round(c)) for c in resultingColor]
self.lastRender = tuple(resultingColor)
self.lastRenderTime = currentTime
diff --git a/pixelcore/Screen.py b/pixelcore/Screen.py
index cfadee8..b595847 100644
--- a/pixelcore/Screen.py
+++ b/pixelcore/Screen.py
@@ -19,25 +19,28 @@ class Screen:
self.xSortedPixels = []
self.xPixelLocs = []
sizeValid = False
-
+ self.pixelsSorted = False
def addStrip(self, lS):
self.pixelStrips.append(lS)
self.sizeValid = False #keep track of whether or not our screen size has
+ self.pixelsSorted = False
#been invalidated by adding more pixels
- self.computeXSortedPixels()
#Returns (pixelIndex, pixel). Does a binary search.
def pixelsInRange(self, minX, maxX):
+ if not self.pixelsSorted:
+ self.computeXSortedPixels()
minIndex = Search.find_ge(self.xPixelLocs, minX)
maxIndex = Search.find_le(self.xPixelLocs, maxX)+1
return self.xSortedPixels[minIndex:maxIndex]
def computeXSortedPixels(self):
+ self.xSortedPixels = []
for pixel in self:
self.xSortedPixels.append((pixel.location[0], pixel))
self.xSortedPixels.sort()
self.xPixelLocs = [p[0] for p in self.xSortedPixels]
-
+ self.pixelsSorted = True
#For debug only
def allOn(self):
[lS.allOn(-1) for lS in self.pixelStrips]
@@ -49,11 +52,15 @@ class Screen:
#increment time -- This processes all queued responses. Responses generated
#during this period are added to the queue that will be processed on the next
#time step.
- def timeStep(self):
+ #SUBVERTING DESIGN FOR EFFICIENCY 1/24/11, RCOH -- It would be cleaner to store the time on the responses
+ #themselves, however, it is faster to just pass it in.
+ def timeStep(self, currentTime=None):
+ if currentTime == None:
+ currentTime = timeops.time()
tempQueue = list(self.responseQueue)
self.responseQueue = []
for response in tempQueue:
- self.processResponse(response)
+ self.processResponse(response, currentTime)
#public
def respond(self, responseInfo):
@@ -77,9 +84,12 @@ class Screen:
return (0, 0, maxX+100, maxY+100) #TODO: cleaner
#private
- def processResponse(self, responseInfo): #we need to make a new dict for
+ def processResponse(self, responseInfo, currentTime=None): #we need to make a new dict for
#each to prevent interference
#[strip.respond(dict(responseInfo)) for strip in self.pixelStrips]
+ if currentTime == None:
+ currentTime = timeops.time()
+ print 'cachetime fail'
if type(responseInfo) != type(dict()):
pass
if 'Mapper' in responseInfo:
@@ -89,7 +99,8 @@ class Screen:
#if type(mapper) != type(PixelMapper):
# raise Exception('No default mapper specified.')
pixelWeightList = mapper.mapEvent(responseInfo['Location'], self)
+ main_log.debug('Screen processing response. ' + str(len(pixelWeightList)) + ' events\
+generated')
PixelEvent.addPixelEventIfMissing(responseInfo)
- currentTime = timeops.time()
for (pixel, weight) in pixelWeightList:
pixel.processInput(responseInfo['PixelEvent'], 0,weight, currentTime) #TODO: z-index