mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 07:37:19 +02:00
Add Polling rate setting
This commit is contained in:
parent
831fd98d02
commit
5e98c756d4
@ -41,6 +41,7 @@ export enum PrefKey {
|
|||||||
CONTROLLER_DEVICE_VIBRATION = 'controller_device_vibration',
|
CONTROLLER_DEVICE_VIBRATION = 'controller_device_vibration',
|
||||||
CONTROLLER_VIBRATION_INTENSITY = 'controller_vibration_intensity',
|
CONTROLLER_VIBRATION_INTENSITY = 'controller_vibration_intensity',
|
||||||
CONTROLLER_SHOW_CONNECTION_STATUS = 'controller_show_connection_status',
|
CONTROLLER_SHOW_CONNECTION_STATUS = 'controller_show_connection_status',
|
||||||
|
CONTROLLER_POLLING_RATE = 'controller_polling_rate',
|
||||||
|
|
||||||
NATIVE_MKB_ENABLED = 'native_mkb_enabled',
|
NATIVE_MKB_ENABLED = 'native_mkb_enabled',
|
||||||
NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY = 'native_mkb_scroll_x_sensitivity',
|
NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY = 'native_mkb_scroll_x_sensitivity',
|
||||||
|
@ -7,7 +7,7 @@ import { BxExposed } from "@utils/bx-exposed";
|
|||||||
import { t } from "@utils/translation";
|
import { t } from "@utils/translation";
|
||||||
import { interceptHttpRequests } from "@utils/network";
|
import { interceptHttpRequests } from "@utils/network";
|
||||||
import { CE } from "@utils/html";
|
import { CE } from "@utils/html";
|
||||||
import { showGamepadToast } from "@utils/gamepad";
|
import { showGamepadToast, updatePollingRate } from "@utils/gamepad";
|
||||||
import { EmulatedMkbHandler } from "@modules/mkb/mkb-handler";
|
import { EmulatedMkbHandler } from "@modules/mkb/mkb-handler";
|
||||||
import { StreamBadges } from "@modules/stream/stream-badges";
|
import { StreamBadges } from "@modules/stream/stream-badges";
|
||||||
import { StreamStats } from "@modules/stream/stream-stats";
|
import { StreamStats } from "@modules/stream/stream-stats";
|
||||||
@ -360,6 +360,7 @@ function main() {
|
|||||||
StreamStats.setupEvents();
|
StreamStats.setupEvents();
|
||||||
|
|
||||||
if (isFullVersion()) {
|
if (isFullVersion()) {
|
||||||
|
updatePollingRate();
|
||||||
STATES.userAgent.capabilities.touch && TouchController.updateCustomList();
|
STATES.userAgent.capabilities.touch && TouchController.updateCustomList();
|
||||||
overridePreloadState();
|
overridePreloadState();
|
||||||
|
|
||||||
|
@ -202,12 +202,17 @@ const PATCHES = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextIndex = str.indexOf('setTimeout(this.pollGamepads', index);
|
const setTimeoutIndex = str.indexOf('setTimeout(this.pollGamepads', index);
|
||||||
if (nextIndex === -1) {
|
if (setTimeoutIndex < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let codeBlock = str.substring(index, nextIndex);
|
let codeBlock = str.substring(index, setTimeoutIndex);
|
||||||
|
|
||||||
|
// Patch polling rate
|
||||||
|
const tmp = str.substring(setTimeoutIndex, setTimeoutIndex + 150);
|
||||||
|
const tmpPatched = tmp.replaceAll('Math.max(0,4-', 'Math.max(0,window.BX_CONTROLLER_POLLING_RATE-');
|
||||||
|
str = PatcherUtils.replaceWith(str, setTimeoutIndex, tmp, tmpPatched);
|
||||||
|
|
||||||
// Block gamepad stats collecting
|
// Block gamepad stats collecting
|
||||||
if (getPref(PrefKey.BLOCK_TRACKING)) {
|
if (getPref(PrefKey.BLOCK_TRACKING)) {
|
||||||
@ -226,7 +231,8 @@ const PATCHES = {
|
|||||||
codeBlock = codeBlock.replace('this.gamepadTimestamps.set', newCode + 'this.gamepadTimestamps.set');
|
codeBlock = codeBlock.replace('this.gamepadTimestamps.set', newCode + 'this.gamepadTimestamps.set');
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.substring(0, index) + codeBlock + str.substring(nextIndex);
|
str = str.substring(0, index) + codeBlock + str.substring(setTimeoutIndex);
|
||||||
|
return str;
|
||||||
},
|
},
|
||||||
|
|
||||||
enableXcloudLogger(str: string) {
|
enableXcloudLogger(str: string) {
|
||||||
|
@ -28,6 +28,7 @@ import { SettingElement, type BxHtmlSettingElement } from "@/utils/setting-eleme
|
|||||||
import type { RecommendedSettings, SettingDefinition, SuggestedSettingCategory as SuggestedSettingProfile } from "@/types/setting-definition";
|
import type { RecommendedSettings, SettingDefinition, SuggestedSettingCategory as SuggestedSettingProfile } from "@/types/setting-definition";
|
||||||
import { FullscreenText } from "../fullscreen-text";
|
import { FullscreenText } from "../fullscreen-text";
|
||||||
import { BxLogger } from "@/utils/bx-logger";
|
import { BxLogger } from "@/utils/bx-logger";
|
||||||
|
import { updatePollingRate } from "@/utils/gamepad";
|
||||||
|
|
||||||
|
|
||||||
type SettingTabContentItem = Partial<{
|
type SettingTabContentItem = Partial<{
|
||||||
@ -460,6 +461,9 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
pref: PrefKey.CONTROLLER_VIBRATION_INTENSITY,
|
pref: PrefKey.CONTROLLER_VIBRATION_INTENSITY,
|
||||||
unsupported: !VibrationManager.supportDeviceVibration(),
|
unsupported: !VibrationManager.supportDeviceVibration(),
|
||||||
onChange: () => VibrationManager.updateGlobalVars(),
|
onChange: () => VibrationManager.updateGlobalVars(),
|
||||||
|
}, isFullVersion() && {
|
||||||
|
pref: PrefKey.CONTROLLER_POLLING_RATE,
|
||||||
|
onChange: () => updatePollingRate(),
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
1
src/types/index.d.ts
vendored
1
src/types/index.d.ts
vendored
@ -12,6 +12,7 @@ interface Window {
|
|||||||
BX_EXPOSED: any;
|
BX_EXPOSED: any;
|
||||||
|
|
||||||
BX_VIBRATION_INTENSITY: number;
|
BX_VIBRATION_INTENSITY: number;
|
||||||
|
BX_CONTROLLER_POLLING_RATE: number;
|
||||||
BX_ENABLE_CONTROLLER_VIBRATION: boolean;
|
BX_ENABLE_CONTROLLER_VIBRATION: boolean;
|
||||||
BX_ENABLE_DEVICE_VIBRATION: boolean;
|
BX_ENABLE_DEVICE_VIBRATION: boolean;
|
||||||
|
|
||||||
|
1
src/types/setting-definition.d.ts
vendored
1
src/types/setting-definition.d.ts
vendored
@ -59,4 +59,5 @@ export type NumberStepperParams = Partial<{
|
|||||||
exactTicks: number;
|
exactTicks: number;
|
||||||
|
|
||||||
customTextValue: (value: any) => string | null;
|
customTextValue: (value: any) => string | null;
|
||||||
|
reverse: boolean;
|
||||||
}>
|
}>
|
||||||
|
@ -33,3 +33,7 @@ export function showGamepadToast(gamepad: Gamepad) {
|
|||||||
|
|
||||||
Toast.show(text, status, {instant: false});
|
Toast.show(text, status, {instant: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updatePollingRate() {
|
||||||
|
window.BX_CONTROLLER_POLLING_RATE = getPref(PrefKey.CONTROLLER_POLLING_RATE);
|
||||||
|
}
|
||||||
|
@ -160,8 +160,8 @@ export class SettingElement {
|
|||||||
|
|
||||||
let controlValue = value;
|
let controlValue = value;
|
||||||
|
|
||||||
const MIN = setting.min!;
|
const MIN = options.reverse ? -setting.max! : setting.min!;
|
||||||
const MAX = setting.max!;
|
const MAX = options.reverse ? -setting.min! : setting.max!;
|
||||||
const STEPS = Math.max(setting.steps || 1, 1);
|
const STEPS = Math.max(setting.steps || 1, 1);
|
||||||
|
|
||||||
const renderTextValue = (value: any) => {
|
const renderTextValue = (value: any) => {
|
||||||
@ -216,7 +216,7 @@ export class SettingElement {
|
|||||||
type: 'range',
|
type: 'range',
|
||||||
min: MIN,
|
min: MIN,
|
||||||
max: MAX,
|
max: MAX,
|
||||||
value: value,
|
value: options.reverse ? -value : value,
|
||||||
step: STEPS,
|
step: STEPS,
|
||||||
tabindex: 0,
|
tabindex: 0,
|
||||||
});
|
});
|
||||||
@ -225,13 +225,16 @@ export class SettingElement {
|
|||||||
|
|
||||||
$range.addEventListener('input', e => {
|
$range.addEventListener('input', e => {
|
||||||
value = parseInt((e.target as HTMLInputElement).value);
|
value = parseInt((e.target as HTMLInputElement).value);
|
||||||
const valueChanged = controlValue !== value;
|
if (options.reverse) {
|
||||||
|
value *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const valueChanged = controlValue !== value;
|
||||||
if (!valueChanged) {
|
if (!valueChanged) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
controlValue = value;
|
controlValue = options.reverse ? -value : value;
|
||||||
updateButtonsVisibility();
|
updateButtonsVisibility();
|
||||||
$text.textContent = renderTextValue(value);
|
$text.textContent = renderTextValue(value);
|
||||||
|
|
||||||
@ -324,7 +327,7 @@ export class SettingElement {
|
|||||||
// Custom method
|
// Custom method
|
||||||
$wrapper.setValue = (value: any) => {
|
$wrapper.setValue = (value: any) => {
|
||||||
$text.textContent = renderTextValue(value);
|
$text.textContent = renderTextValue(value);
|
||||||
$range.value = value;
|
$range.value = options.reverse ? -value : value;
|
||||||
};
|
};
|
||||||
|
|
||||||
$btnDec.addEventListener('click', onClick);
|
$btnDec.addEventListener('click', onClick);
|
||||||
|
@ -388,6 +388,29 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
[PrefKey.CONTROLLER_POLLING_RATE]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
|
label: t('polling-rate'),
|
||||||
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
|
default: 4,
|
||||||
|
min: 4,
|
||||||
|
max: 40,
|
||||||
|
steps: 4,
|
||||||
|
params: {
|
||||||
|
reverse: true,
|
||||||
|
customTextValue(value: any) {
|
||||||
|
value = parseInt(value);
|
||||||
|
|
||||||
|
let text = +(1000 / value).toFixed(2) + ' Hz';
|
||||||
|
if (value === 4) {
|
||||||
|
text = `${t('default')} (${text})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
[PrefKey.MKB_ENABLED]: {
|
[PrefKey.MKB_ENABLED]: {
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
label: t('enable-mkb'),
|
label: t('enable-mkb'),
|
||||||
|
@ -188,6 +188,7 @@ const Texts = {
|
|||||||
"playing": "Playing",
|
"playing": "Playing",
|
||||||
"playtime": "Playtime",
|
"playtime": "Playtime",
|
||||||
"poland": "Poland",
|
"poland": "Poland",
|
||||||
|
"polling-rate": "Polling rate",
|
||||||
"position": "Position",
|
"position": "Position",
|
||||||
"powered-off": "Powered off",
|
"powered-off": "Powered off",
|
||||||
"powered-on": "Powered on",
|
"powered-on": "Powered on",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user