aboutsummaryrefslogtreecommitdiff
path: root/LightInstallation.py
diff options
context:
space:
mode:
authorGravatar Russell Cohen <rcoh@mit.edu>2010-12-03 04:20:17 -0500
committerGravatar Russell Cohen <rcoh@mit.edu>2010-12-03 04:20:17 -0500
commit353ab16db64c86122c0fcb9e1852b85c14b354b8 (patch)
tree8904f1cd312974a849ad5bcf0c8520fd20175cda /LightInstallation.py
parent0366f46d3d7e946e254f933888aea4beb4e70658 (diff)
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.
Diffstat (limited to 'LightInstallation.py')
-rw-r--r--LightInstallation.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/LightInstallation.py b/LightInstallation.py
index 849e41f..8f71cf0 100644
--- a/LightInstallation.py
+++ b/LightInstallation.py
@@ -1,14 +1,17 @@
from xml.etree.ElementTree import ElementTree
from pixelcore.Screen import *
from pixelcore.PixelStrip import *
-import pdb, sys, time, Util
+import pdb, sys, time, Util, thread
from pygame.locals import *
#Python class to instantiate and drive a Screen through different patterns,
#and effects.
class LightInstallation:
def __init__(self, configFileName):
+ self.timer = Util.Stopwatch()
+ self.timer.start()
self.inputs = {} #dict of inputs and their bound behaviors, keyed by InputId
self.behaviors = {}
+ self.lock = thread.allocate_lock()
self.behaviorOutputs = {} #key: [list of output destinations]
self.behaviorInputs = {}
self.componentDict = {}
@@ -39,6 +42,8 @@ class LightInstallation:
self.registerComponents(self.inputs)
self.registerComponents(self.behaviors)
#Done initializing. Lets start this thing!
+ self.timer.stop()
+ print 'Initialization done. Time: ', self.timer.elapsed(), 'ms'
self.mainLoop()
def initializeMapper(self, mapperConfig):
self.mapper = self.initializeComponent(mapperConfig)[0] #TODO: support
@@ -82,16 +87,21 @@ class LightInstallation:
#self.screen.allOn()
lastLoopTime = Util.time()
refreshInterval = 30
- while 1:
+ runCount = 1000
+ while runCount > 0:
+ runCount -= 1
loopStart = Util.time()
responses = self.evaluateBehaviors() #inputs are all queued when they
#happen, so we only need to run the behaviors
+ self.timer.start()
[self.screen.respond(response) for response in responses if
response != []]
self.screen.timeStep()
[r.render(self.screen) for r in self.renderers]
loopElapsed = Util.time()-loopStart
sleepTime = max(0,refreshInterval-loopElapsed)
+ self.timer.stop()
+ #print self.timer.elapsed()
if sleepTime > 0:
time.sleep(sleepTime/1000)
#evaluates all the behaviors (including inter-dependencies) and returns a