diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index ecabea63c..2752ea493 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -349,6 +349,7 @@ const _EJS_CORES_MAP = { gbc: ["gambatte", "mgba"], "pc-fx": ["mednafen_pcfx"], ps: ["pcsx_rearmed", "mednafen_psx"], + psp: ["ppsspp"], segacd: ["genesis_plus_gx", "picodrive"], // sega32: ["picodrive"], // Broken: https://github.com/EmulatorJS/EmulatorJS/issues/579 gamegear: ["genesis_plus_gx"], @@ -387,8 +388,23 @@ export type EJSPlatformSlug = keyof typeof _EJS_CORES_MAP; * @param platformSlug The platform slug. * @returns An array of supported cores. */ -export function getSupportedEJSCores(platformSlug: string) { - return _EJS_CORES_MAP[platformSlug.toLowerCase() as EJSPlatformSlug] || []; +export function getSupportedEJSCores(platformSlug: string): string[] { + const cores = + _EJS_CORES_MAP[platformSlug.toLowerCase() as EJSPlatformSlug] || []; + const threadsSupported = isEJSThreadsSupported(); + return cores.filter( + (core) => !areThreadsRequiredForEJSCore(core) || threadsSupported, + ); +} + +/** + * Check if a given EJS core requires threads enabled. + * + * @param core The core name. + * @returns True if threads are required, false otherwise. + */ +export function areThreadsRequiredForEJSCore(core: string): boolean { + return ["ppsspp"].includes(core); } /** @@ -403,11 +419,23 @@ export function isEJSEmulationSupported( heartbeat: Heartbeat, ) { return ( - platformSlug.toLowerCase() in _EJS_CORES_MAP && - !heartbeat.EMULATION.DISABLE_EMULATOR_JS + !heartbeat.EMULATION.DISABLE_EMULATOR_JS && + getSupportedEJSCores(platformSlug).length > 0 ); } +/** + * Check if EJS threads are supported. + * + * EmulatorJS threads are supported if SharedArrayBuffer is available. + * Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer + * + * @returns True if supported, false otherwise. + */ +export function isEJSThreadsSupported(): boolean { + return typeof SharedArrayBuffer !== "undefined"; +} + /** * Check if Ruffle emulation is supported for a given platform. * diff --git a/frontend/src/views/Player/EmulatorJS/Player.vue b/frontend/src/views/Player/EmulatorJS/Player.vue index 20b9af27b..279d7624e 100644 --- a/frontend/src/views/Player/EmulatorJS/Player.vue +++ b/frontend/src/views/Player/EmulatorJS/Player.vue @@ -4,7 +4,7 @@ import saveApi, { saveApi as api } from "@/services/api/save"; import screenshotApi from "@/services/api/screenshot"; import stateApi from "@/services/api/state"; import type { DetailedRom } from "@/stores/roms"; -import { getSupportedEJSCores } from "@/utils"; +import { areThreadsRequiredForEJSCore, getSupportedEJSCores } from "@/utils"; import { onBeforeUnmount, onMounted, ref } from "vue"; const props = defineProps<{ @@ -77,6 +77,7 @@ declare global { EJS_alignStartButton: "top" | "center" | "bottom"; EJS_startOnLoaded: boolean; EJS_fullscreenOnLoaded: boolean; + EJS_threads: boolean; // eslint-disable-next-line @typescript-eslint/no-explicit-any EJS_emulator: any; EJS_onGameStart: () => void; @@ -90,6 +91,7 @@ declare global { const supportedCores = getSupportedEJSCores(romRef.value.platform_slug); window.EJS_core = supportedCores.find((core) => core === props.core) ?? supportedCores[0]; +window.EJS_threads = areThreadsRequiredForEJSCore(window.EJS_core); window.EJS_gameID = romRef.value.id; window.EJS_gameUrl = `/api/roms/${romRef.value.id}/content/${romRef.value.file_name}`; window.EJS_biosUrl = props.bios @@ -438,7 +440,7 @@ window.EJS_onGameStart = async () => { } - +