|
@@ -47581,7 +47581,7 @@ var BABYLON;
|
|
var BABYLON;
|
|
var BABYLON;
|
|
(function (BABYLON) {
|
|
(function (BABYLON) {
|
|
var Gamepads = (function () {
|
|
var Gamepads = (function () {
|
|
- function Gamepads(ongamedpadconnected) {
|
|
|
|
|
|
+ function Gamepads(ongamedpadconnected, ongamedpaddisconnected) {
|
|
var _this = this;
|
|
var _this = this;
|
|
this.babylonGamepads = [];
|
|
this.babylonGamepads = [];
|
|
this.oneGamepadConnected = false;
|
|
this.oneGamepadConnected = false;
|
|
@@ -47590,6 +47590,7 @@ var BABYLON;
|
|
this.gamepadSupport = (navigator.getGamepads ||
|
|
this.gamepadSupport = (navigator.getGamepads ||
|
|
navigator.webkitGetGamepads || navigator.msGetGamepads || navigator.webkitGamepads);
|
|
navigator.webkitGetGamepads || navigator.msGetGamepads || navigator.webkitGamepads);
|
|
this._callbackGamepadConnected = ongamedpadconnected;
|
|
this._callbackGamepadConnected = ongamedpadconnected;
|
|
|
|
+ this._callbackGamepadDisconnected = ongamedpaddisconnected;
|
|
if (this.gamepadSupport) {
|
|
if (this.gamepadSupport) {
|
|
//first add already-connected gamepads
|
|
//first add already-connected gamepads
|
|
this._updateGamepadObjects();
|
|
this._updateGamepadObjects();
|
|
@@ -47602,7 +47603,7 @@ var BABYLON;
|
|
_this._onGamepadConnected(evt.gamepad);
|
|
_this._onGamepadConnected(evt.gamepad);
|
|
};
|
|
};
|
|
this._onGamepadDisonnectedEvent = function (evt) {
|
|
this._onGamepadDisonnectedEvent = function (evt) {
|
|
- _this._onGamepadDisconnected(evt);
|
|
|
|
|
|
+ _this._onGamepadDisconnected(evt.gamepad);
|
|
};
|
|
};
|
|
window.addEventListener('gamepadconnected', this._onGamepadConnectedEvent, false);
|
|
window.addEventListener('gamepadconnected', this._onGamepadConnectedEvent, false);
|
|
window.addEventListener('gamepaddisconnected', this._onGamepadDisonnectedEvent, false);
|
|
window.addEventListener('gamepaddisconnected', this._onGamepadDisonnectedEvent, false);
|
|
@@ -47619,8 +47620,16 @@ var BABYLON;
|
|
this._onGamepadConnectedEvent = null;
|
|
this._onGamepadConnectedEvent = null;
|
|
this._onGamepadDisonnectedEvent = null;
|
|
this._onGamepadDisonnectedEvent = null;
|
|
}
|
|
}
|
|
|
|
+ this.oneGamepadConnected = false;
|
|
|
|
+ this._stopMonitoringGamepads();
|
|
|
|
+ this.babylonGamepads = [];
|
|
};
|
|
};
|
|
Gamepads.prototype._onGamepadConnected = function (gamepad) {
|
|
Gamepads.prototype._onGamepadConnected = function (gamepad) {
|
|
|
|
+ // Protection code for Chrome which has a very buggy gamepad implementation...
|
|
|
|
+ // And raises a connected event on disconnection for instance
|
|
|
|
+ if (gamepad.index in this.babylonGamepads) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
var newGamepad = this._addNewGamepad(gamepad);
|
|
var newGamepad = this._addNewGamepad(gamepad);
|
|
if (this._callbackGamepadConnected)
|
|
if (this._callbackGamepadConnected)
|
|
this._callbackGamepadConnected(newGamepad);
|
|
this._callbackGamepadConnected(newGamepad);
|
|
@@ -47644,10 +47653,10 @@ var BABYLON;
|
|
this.babylonGamepads.push(newGamepad);
|
|
this.babylonGamepads.push(newGamepad);
|
|
return newGamepad;
|
|
return newGamepad;
|
|
};
|
|
};
|
|
- Gamepads.prototype._onGamepadDisconnected = function (evt) {
|
|
|
|
|
|
+ Gamepads.prototype._onGamepadDisconnected = function (gamepad) {
|
|
// Remove the gamepad from the list of gamepads to monitor.
|
|
// Remove the gamepad from the list of gamepads to monitor.
|
|
for (var i in this.babylonGamepads) {
|
|
for (var i in this.babylonGamepads) {
|
|
- if (this.babylonGamepads[i].index == evt.gamepad.index) {
|
|
|
|
|
|
+ if (this.babylonGamepads[i].index == gamepad.index) {
|
|
this.babylonGamepads.splice(+i, 1);
|
|
this.babylonGamepads.splice(+i, 1);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -47655,7 +47664,10 @@ var BABYLON;
|
|
// If no gamepads are left, stop the polling loop.
|
|
// If no gamepads are left, stop the polling loop.
|
|
if (this.babylonGamepads.length == 0) {
|
|
if (this.babylonGamepads.length == 0) {
|
|
this._stopMonitoringGamepads();
|
|
this._stopMonitoringGamepads();
|
|
|
|
+ this.oneGamepadConnected = false;
|
|
}
|
|
}
|
|
|
|
+ if (this._callbackGamepadDisconnected)
|
|
|
|
+ this._callbackGamepadDisconnected(gamepad);
|
|
};
|
|
};
|
|
Gamepads.prototype._startMonitoringGamepads = function () {
|
|
Gamepads.prototype._startMonitoringGamepads = function () {
|
|
if (!this.isMonitoring) {
|
|
if (!this.isMonitoring) {
|
|
@@ -47668,7 +47680,7 @@ var BABYLON;
|
|
};
|
|
};
|
|
Gamepads.prototype._checkGamepadsStatus = function () {
|
|
Gamepads.prototype._checkGamepadsStatus = function () {
|
|
var _this = this;
|
|
var _this = this;
|
|
- // updating gamepad objects
|
|
|
|
|
|
+ // Hack to be compatible Chrome
|
|
this._updateGamepadObjects();
|
|
this._updateGamepadObjects();
|
|
for (var i in this.babylonGamepads) {
|
|
for (var i in this.babylonGamepads) {
|
|
this.babylonGamepads[i].update();
|
|
this.babylonGamepads[i].update();
|
|
@@ -47685,9 +47697,8 @@ var BABYLON;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- // This function is called only on Chrome, which does not yet support
|
|
|
|
- // connection/disconnection events, but requires you to monitor
|
|
|
|
- // an array for changes.
|
|
|
|
|
|
+ // This function is called only on Chrome, which does not properly support
|
|
|
|
+ // connection/disconnection events and forces you to recopy again the gamepad object
|
|
Gamepads.prototype._updateGamepadObjects = function () {
|
|
Gamepads.prototype._updateGamepadObjects = function () {
|
|
var gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
|
|
var gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
|
|
for (var i = 0; i < gamepads.length; i++) {
|
|
for (var i = 0; i < gamepads.length; i++) {
|
|
@@ -47699,6 +47710,7 @@ var BABYLON;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
|
|
+ // Forced to copy again this object for Chrome for unknown reason
|
|
this.babylonGamepads[i].browserGamepad = gamepads[i];
|
|
this.babylonGamepads[i].browserGamepad = gamepads[i];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -47785,13 +47797,10 @@ var BABYLON;
|
|
BABYLON.Gamepad = Gamepad;
|
|
BABYLON.Gamepad = Gamepad;
|
|
var GenericPad = (function (_super) {
|
|
var GenericPad = (function (_super) {
|
|
__extends(GenericPad, _super);
|
|
__extends(GenericPad, _super);
|
|
- function GenericPad(id, index, gamepad) {
|
|
|
|
- var _this = _super.call(this, id, index, gamepad) || this;
|
|
|
|
- _this.id = id;
|
|
|
|
- _this.index = index;
|
|
|
|
- _this.gamepad = gamepad;
|
|
|
|
|
|
+ function GenericPad(id, index, browserGamepad) {
|
|
|
|
+ var _this = _super.call(this, id, index, browserGamepad) || this;
|
|
_this.type = Gamepad.GENERIC;
|
|
_this.type = Gamepad.GENERIC;
|
|
- _this._buttons = new Array(gamepad.buttons.length);
|
|
|
|
|
|
+ _this._buttons = new Array(browserGamepad.buttons.length);
|
|
return _this;
|
|
return _this;
|
|
}
|
|
}
|
|
GenericPad.prototype.onbuttondown = function (callback) {
|
|
GenericPad.prototype.onbuttondown = function (callback) {
|
|
@@ -47814,7 +47823,7 @@ var BABYLON;
|
|
GenericPad.prototype.update = function () {
|
|
GenericPad.prototype.update = function () {
|
|
_super.prototype.update.call(this);
|
|
_super.prototype.update.call(this);
|
|
for (var index = 0; index < this._buttons.length; index++) {
|
|
for (var index = 0; index < this._buttons.length; index++) {
|
|
- this._buttons[index] = this._setButtonValue(this.gamepad.buttons[index].value, this._buttons[index], index);
|
|
|
|
|
|
+ this._buttons[index] = this._setButtonValue(this.browserGamepad.buttons[index].value, this._buttons[index], index);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
return GenericPad;
|
|
return GenericPad;
|