Skip to content

Commit

Permalink
throttle updateControllerList while keeping getGamepads call (#3112)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngokevin authored and dmarcos committed Nov 7, 2017
1 parent 3a933b4 commit 7cc2cef
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/systems/tracked-controls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var registerSystem = require('../core/system').registerSystem;
var utils = require('../utils');

/**
* Tracked controls system.
Expand All @@ -10,7 +11,8 @@ module.exports.System = registerSystem('tracked-controls', {

this.controllers = [];

this.updateControllerList();
this.updateControllerList(navigator.getGamepads && navigator.getGamepads());
this.throttledUpdateControllerList = utils.throttle(this.updateControllerList, 500, this);

if (!navigator.getVRDisplays) { return; }

Expand All @@ -22,20 +24,21 @@ module.exports.System = registerSystem('tracked-controls', {
},

tick: function () {
this.updateControllerList();
var gamepads;
// Call getGamepads for Chrome.
gamepads = navigator.getGamepads && navigator.getGamepads();
this.throttledUpdateControllerList(gamepads);
},

/**
* Update controller list.
*/
updateControllerList: function () {
updateControllerList: function (gamepads) {
var controllers = this.controllers;
var gamepad;
var gamepads;
var i;
var prevCount;

gamepads = navigator.getGamepads && navigator.getGamepads();
if (!gamepads) { return; }

prevCount = controllers.length;
Expand Down

0 comments on commit 7cc2cef

Please sign in to comment.