1
0
Fork 0

WebPanel: be a litte more cpu friendly

- limit precision for animations to four digits
- don't insist on a strict update frequency but schedule a redraw after
  a configured time. This gives the rendering thread of the browser more
  time to draw
This commit is contained in:
Torsten Dreyer 2014-09-24 21:07:19 +02:00
parent 651005b4b0
commit c32d6029ff

View file

@ -184,6 +184,7 @@ FGFS.InputValue = function(arg) {
this.interpolationTable = null; this.interpolationTable = null;
this.min = null; this.min = null;
this.max = null; this.max = null;
this.precision = 4;
this.getValue = function() { this.getValue = function() {
var value = this.value; var value = this.value;
@ -191,14 +192,14 @@ FGFS.InputValue = function(arg) {
value = this.property.getNumValue(); value = this.property.getNumValue();
if (this.interpolationTable != null && this.interpolationTable.length > 0) if (this.interpolationTable != null && this.interpolationTable.length > 0)
return FGFS.interpolate(value, this.interpolationTable); return FGFS.interpolate(value, this.interpolationTable).toPrecision(this.precision);
value = value * this.scale + this.offset; value = value * this.scale + this.offset;
if( this.min != null && value < this.min ) if( this.min != null && value < this.min )
return this.min; return this.min.toPrecision(this.precision);
if( this.max != null && value > this.min ) if( this.max != null && value > this.min )
return this.max; return this.max.toPrecision(this.precision);
return value; return value.toPrecision(this.precision);
} }
if (typeof (arg) == 'number') { if (typeof (arg) == 'number') {
@ -416,13 +417,16 @@ FGFS.FGPanel = function( propUrl )
var mirror = new FGFS.PropertyMirror(this.props.propertyMirror); var mirror = new FGFS.PropertyMirror(this.props.propertyMirror);
var instruments = $(this.props.instrumentSelector).fgLoadInstruments(this.props.instrumentDataKey); this.instruments = $(this.props.instrumentSelector).fgLoadInstruments(this.props.instrumentDataKey);
window.setInterval( function() { this.update = function() {
instruments.forEach(function(instrument) { for( var i = 0; i < this.instruments.length; i++ ) {
instrument.update(); this.instruments[i].update();
}); }
}, this.props.updateInterval ); window.setTimeout( $.proxy(this.update,this), this.props.updateInterval );
}
this.update();
} }
$(document).ready(function() { $(document).ready(function() {