Skip to content

Commit 69c1bd6

Browse files
committed
Throttle fly controls sync
Default to 1 sec sync rate.
1 parent c161017 commit 69c1bd6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

js/scripts/three-class-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ module.exports = {
243243
rotationVector: new Types.Vector3(0, 0, 0),
244244
movementSpeed: new Types.Float(1.0),
245245
rollSpeed: new Types.Float(0.05),
246+
syncRate: new Types.Float(1.0),
246247
},
247248
},
248249
Picker: {

js/src/controls/FlyControls.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var FlyControlsModel = FlyControlsAutogen.FlyControlsModel.extend({
1111
this.clock = new THREE.Clock();
1212
var controlling = this.get('controlling');
1313
this.renderer = null;
14+
this.syncAtWill = true;
1415

1516
obj = new FlyControls(controlling.obj);
1617
obj.dispose(); // Disconnect events, we need to (dis-)connect on freeze/thaw
@@ -21,7 +22,12 @@ var FlyControlsModel = FlyControlsAutogen.FlyControlsModel.extend({
2122
FlyControlsAutogen.FlyControlsModel.prototype.setupListeners.call(this);
2223
var that = this;
2324
this.obj.addEventListener('change', function() {
24-
that.update_controlled();
25+
// Throttle syncs:
26+
if (that.syncAtWill) {
27+
that.syncAtWill = false;
28+
that.update_controlled();
29+
setTimeout(that.allowSync.bind(that), 1000 * that.get('syncRate'));
30+
}
2531
});
2632
this.on('enableControl', this.onEnable, this);
2733
this.on('disableControl', this.onDisable, this);
@@ -38,9 +44,13 @@ var FlyControlsModel = FlyControlsAutogen.FlyControlsModel.extend({
3844
this.renderer = null;
3945
},
4046

47+
allowSync: function() {
48+
this.syncAtWill = true;
49+
},
50+
4151
_update: function() {
42-
this.obj.update(this.clock.getDelta());
4352
if (this.renderer !== null) {
53+
this.obj.update(this.clock.getDelta());
4454
requestAnimationFrame(this._update.bind(this));
4555
}
4656
},

0 commit comments

Comments
 (0)