Commit 43ec8eda authored by Nico Mack's avatar Nico Mack
Browse files

Bug Fixes and minor improvements

parent dcc14610
......@@ -487,7 +487,7 @@ public class NumericalVariable extends Variable<Double> {
public double getConstrainedValue() {
this.normalizedValue = this.normalizeValue(this.value);
return this.minValue + (this.normalizedValue * this.valueRange);
return roundToPrecision(this.minValue + (this.normalizedValue * this.valueRange));
}
// ---------------------------------------------------------------------------
......
......@@ -34,6 +34,7 @@ import java.util.concurrent.TimeUnit;
public class ThrottlingExecutor {
private long last;
private long projected;
private ScheduledFuture<?> scheduled;
private long coalescePeriod;
......@@ -54,6 +55,7 @@ public class ThrottlingExecutor {
public ThrottlingExecutor() {
this.coalescePeriod = 0;
this.last = 0;
this.projected = 0;
}
// ---------------------------------------------------------------------------
......@@ -91,12 +93,15 @@ public class ThrottlingExecutor {
public void submit(TimerTask task) {
long now = System.currentTimeMillis();
if ((this.coalescePeriod > 0) && (last > 0)) {
if (this.coalescePeriod > 0) {
long elapsed = now - last;
long delay = 0;
if (elapsed < this.coalescePeriod) {
delay = this.coalescePeriod - elapsed;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Task submitted within {} ms coalesce period! Deferred execution in {} ms!", this.coalescePeriod, (this.coalescePeriod - elapsed)); //$NON-NLS-1$
LOGGER.debug("Task submitted within {} ms coalesce period! Deferred execution in {} ms!", this.coalescePeriod, delay); //$NON-NLS-1$
}
if (scheduled != null) {
......@@ -106,13 +111,18 @@ public class ThrottlingExecutor {
}
}
scheduled = executor.schedule(task, (this.coalescePeriod - elapsed), TimeUnit.MILLISECONDS);
projected = last + coalescePeriod;
scheduled = executor.schedule(task, delay, TimeUnit.MILLISECONDS);
return;
}
elapsed = now - projected;
delay = (elapsed < this.coalescePeriod) ? this.coalescePeriod - elapsed : 0;
scheduled = executor.schedule(task, delay, TimeUnit.MILLISECONDS);
last = now + delay;
} else {
scheduled = executor.schedule(task, 0, TimeUnit.MILLISECONDS);
}
executor.schedule(task, 0, TimeUnit.MILLISECONDS);
last = now;
scheduled = null;
}
// ---------------------------------------------------------------------------
......
......@@ -219,21 +219,21 @@ public class ValueWidget extends TetherableWidget implements InformationProvider
*/
// ---------------------------------------------------------------------------
private void updateDisplays() {
private void updateDisplays(double newValue) {
for (ValueCorona display : dispatcher) {
display.setInformation(this.variable.getConstrainedValue());
display.setInformation(newValue);
}
}
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
protected void updateTethers(Double value) {
@SuppressWarnings({"unchecked", "rawtypes"})
protected void updateTethers(Double newValue) {
if (this.isTethered()) {
List<InformationFeed> dataFeeds = this.getTethers(InformationFeed.class);
for (InformationFeed<Double> tether : dataFeeds) {
tether.setInformation(value);
tether.setInformation(newValue);
}
}
}
......@@ -272,8 +272,10 @@ public class ValueWidget extends TetherableWidget implements InformationProvider
value = Math.min(value, this.upperBound);
variable.setValue(value);
value = variable.getConstrainedValue();
this.updateTethers(value);
this.updateDisplays();
this.updateDisplays(value);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} = {}", variable.getName(), value); //$NON-NLS-1$
......@@ -290,7 +292,8 @@ public class ValueWidget extends TetherableWidget implements InformationProvider
public void actionDrop(TangibleObject tuioObject) {
if (Double.isNaN(dropAngle)) {
dropAngle = (isPersistent) ? 0 : AngleUtils.moduloTwoPi(tuioObject.getAngle());
// dropAngle = (isPersistent) ? 0 : AngleUtils.moduloTwoPi(tuioObject.getAngle());
dropAngle = AngleUtils.moduloTwoPi(tuioObject.getAngle());
}
if (!isPersistent) {
......@@ -316,6 +319,8 @@ public class ValueWidget extends TetherableWidget implements InformationProvider
if (!this.isPersistent(tuioObject.getObjectId())) {
getVariable().setValue(initialValue);
}
dropAngle = Double.NaN;
}
// ---------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment