Send attached gamepads at launch to fix L4D2

This commit is contained in:
Cameron Gutman 2018-01-20 15:08:36 -08:00
parent 17f006db03
commit fdcd3d4747
3 changed files with 49 additions and 7 deletions

View File

@ -24,7 +24,10 @@ static short GetActiveGamepadMask(PP_GamepadsSampleData& gamepadData) {
for (unsigned int p = 0; p < gamepadData.length; p++) { for (unsigned int p = 0; p < gamepadData.length; p++) {
PP_GamepadSampleData& padData = gamepadData.items[p]; PP_GamepadSampleData& padData = gamepadData.items[p];
// See logic in getConnectedGamepadMask() (utils.js)
// These must stay in sync!
if (!padData.connected) { if (!padData.connected) {
// Not connected // Not connected
continue; continue;

View File

@ -598,12 +598,15 @@ function startGame(host, appID) {
var rikey = generateRemoteInputKey(); var rikey = generateRemoteInputKey();
var rikeyid = generateRemoteInputKeyId(); var rikeyid = generateRemoteInputKeyId();
var gamepadMask = getConnectedGamepadMask();
$('#loadingMessage').text('Starting ' + appToStart.title + '...'); $('#loadingMessage').text('Starting ' + appToStart.title + '...');
playGameMode(); playGameMode();
if(host.currentGame == appID) { // if user wants to launch the already-running app, then we resume it. if(host.currentGame == appID) { // if user wants to launch the already-running app, then we resume it.
return host.resumeApp(rikey, rikeyid).then(function (ret) { return host.resumeApp(
rikey, rikeyid, 0x030002 // Surround channel mask << 16 | Surround channel count
).then(function (ret) {
sendMessage('startRequest', [host.address, streamWidth, streamHeight, frameRate, sendMessage('startRequest', [host.address, streamWidth, streamHeight, frameRate,
bitrate.toString(), rikey, rikeyid.toString(), host.appVersion]); bitrate.toString(), rikey, rikeyid.toString(), host.appVersion]);
}, function (failedResumeApp) { }, function (failedResumeApp) {
@ -619,7 +622,8 @@ function startGame(host, appID) {
optimize, // DON'T Allow GFE (0) to optimize game settings, or ALLOW (1) to optimize game settings optimize, // DON'T Allow GFE (0) to optimize game settings, or ALLOW (1) to optimize game settings
rikey, rikeyid, rikey, rikeyid,
remote_audio_enabled, // Play audio locally too? remote_audio_enabled, // Play audio locally too?
0x030002 // Surround channel mask << 16 | Surround channel count 0x030002, // Surround channel mask << 16 | Surround channel count
gamepadMask
).then(function (ret) { ).then(function (ret) {
sendMessage('startRequest', [host.address, streamWidth, streamHeight, frameRate, sendMessage('startRequest', [host.address, streamWidth, streamHeight, frameRate,
bitrate.toString(), rikey, rikeyid.toString(), host.appVersion]); bitrate.toString(), rikey, rikeyid.toString(), host.appVersion]);

View File

@ -23,6 +23,38 @@ function generateRemoteInputKeyId() {
return ((Math.random()-0.5) * 0x7FFFFFFF)|0; return ((Math.random()-0.5) * 0x7FFFFFFF)|0;
} }
function getConnectedGamepadMask() {
var count = 0;
var mask = 0;
var gamepads = navigator.getGamepads ? navigator.getGamepads() : [];
for (var i = 0; i < gamepads.length; i++) {
var gamepad = gamepads[i];
if (gamepad) {
// See logic in gamepad.cpp
// These must stay in sync!
if (!gamepad.connected) {
// Not connected
continue;
}
if (gamepad.timestamp == 0) {
// On some platforms, Chrome returns "connected" pads that
// really aren't, so timestamp stays at zero. To work around this,
// we'll only count gamepads that have a non-zero timestamp in our
// controller index.
continue;
}
mask |= 1 << count++;
}
}
console.log('%c[utils.js, getConnectedGamepadMask]', 'color:gray;', 'Detected '+count+' gamepads');
return mask;
}
String.prototype.toHex = function() { String.prototype.toHex = function() {
var hex = ''; var hex = '';
for(var i = 0; i < this.length; i++) { for(var i = 0; i < this.length; i++) {
@ -440,7 +472,7 @@ NvHTTP.prototype = {
} }
}, },
launchApp: function (appId, mode, sops, rikey, rikeyid, localAudio, surroundAudioInfo) { launchApp: function (appId, mode, sops, rikey, rikeyid, localAudio, surroundAudioInfo, gamepadMask) {
return sendMessage('openUrl', [ return sendMessage('openUrl', [
this._baseUrlHttps + this._baseUrlHttps +
'/launch?' + this._buildUidStr() + '/launch?' + this._buildUidStr() +
@ -450,19 +482,22 @@ NvHTTP.prototype = {
'&rikey=' + rikey + '&rikey=' + rikey +
'&rikeyid=' + rikeyid + '&rikeyid=' + rikeyid +
'&localAudioPlayMode=' + localAudio + '&localAudioPlayMode=' + localAudio +
'&surroundAudioInfo=' + surroundAudioInfo, '&surroundAudioInfo=' + surroundAudioInfo +
'&remoteControllersBitmap=' + gamepadMask +
'&gcmap=' + gamepadMask,
false false
]).then(function (ret) { ]).then(function (ret) {
return true; return true;
}); });
}, },
resumeApp: function (rikey, rikeyid) { resumeApp: function (rikey, rikeyid, surroundAudioInfo) {
return sendMessage('openUrl', [ return sendMessage('openUrl', [
this._baseUrlHttps + this._baseUrlHttps +
'/resume?' + this._buildUidStr() + '/resume?' + this._buildUidStr() +
'&rikey=' + rikey + '&rikey=' + rikey +
'&rikeyid=' + rikeyid, '&rikeyid=' + rikeyid +
'&surroundAudioInfo=' + surroundAudioInfo,
false false
]).then(function (ret) { ]).then(function (ret) {
return true; return true;