From 80e5401c94022f1b537fb5fa715403f06be3c924 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Tue, 3 Oct 2017 16:47:16 +0200 Subject: [PATCH] throttle updateControllerList while keeping getGamepads call --- src/systems/tracked-controls.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/systems/tracked-controls.js b/src/systems/tracked-controls.js index 983a7756b06..6dae79764fc 100644 --- a/src/systems/tracked-controls.js +++ b/src/systems/tracked-controls.js @@ -1,4 +1,5 @@ var registerSystem = require('../core/system').registerSystem; +var utils = require('../utils'); /** * Tracked controls system. @@ -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; } @@ -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;