diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-16 23:32:56 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-16 23:32:56 +0200 |
commit | 2025ec49e8ae78501ee0bd20d8e974c9d2edae8a (patch) | |
tree | c4368860ddb64aa0b6c1ce10083bfa9e78bcf795 /chuck/OSCGraphicsLayer.ck | |
parent | 232938d984f9ea11c66d200921ab1584b6443bd5 (diff) | |
download | osc-graphics-2025ec49e8ae78501ee0bd20d8e974c9d2edae8a.tar.gz |
optimize port polling
Diffstat (limited to 'chuck/OSCGraphicsLayer.ck')
-rw-r--r-- | chuck/OSCGraphicsLayer.ck | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/chuck/OSCGraphicsLayer.ck b/chuck/OSCGraphicsLayer.ck index ffd7fe7..9aed84e 100644 --- a/chuck/OSCGraphicsLayer.ck +++ b/chuck/OSCGraphicsLayer.ck @@ -26,10 +26,13 @@ public class OSCGraphicsLayer { int index; fun void - tick(float in) + tick(float in, float prev) { in $ int => geo[index]; - geo => layer.geo; + + /* optimize: avoid sending unnecessary messages */ + if (geo[index] != (prev $ int)) + geo => layer.geo; } } fun OSCGraphicsPort @ @@ -64,9 +67,11 @@ public class OSCGraphicsLayer { OSCGraphicsLayer @layer; fun void - tick(float in) + tick(float in, float prev) { - in => layer.alpha; + /* optimize: alpha set as float, but there are only 255 alpha levels */ + if ((in*255) $ int != (prev*255) $ int) + in => layer.alpha; } } fun OSCGraphicsPort @ |