Davidobot / love.js

LÖVE ported to the web using Emscripten, updated to the latest Emscripten and LÖVE (v11.5)
MIT License
605 stars 27 forks source link

Detect if the browser supports pthreads to pick the most suitable execution mode #5

Open thomasgoldstein opened 4 years ago

thomasgoldstein commented 4 years ago

Hi. A feature request. Add the ability to create a lovejs bundle which would contain both the pthread version and the compatibility version, and at the beginning of the execution, it'd detect if your browser supports pthreads in order to pick the best version.

Davidobot commented 4 years ago

I've looked into this a bit. Looks like there is no direct check for pthreads support. The way to implement this would probably be to catch all exceptions from the main loop and switch versions if they are encountered.

thomasgoldstein commented 4 years ago

I've looked around. I don't know if it's relevant here, but I've found this: https://github.com/whatwg/html/issues/4732 Some people suggest ways to detect SharedArrayBuffer support, but I'm not even sure that it's the same as pthread support.

If that is not useful, here's another idea: maybe it'd be simpler to just call some dummy pthread init code on startup to know right away if it's supported or not by the browser, so you don't have to bother trying to catch exceptions that might arise later while playing the game.

jiaaro commented 4 years ago

window.SharedArrayBuffer === undefined does seem to coincide with browsers where the compat version is required in my limited testing. Seems like a good enough heuristic. I'd want to fall back to compat aggressively to ensure things run.