4 ms·
Why this arch over having the UI run in the main thread and sending events into the wasm worker?
by sitkack 5y ago
Why this arch over having the UI run in the main thread and sending events into the wasm worker?
- devwastaken 5y agoThe web worker where wasm is running in would be the one that handles the whole game, and the game has to be told the inputs. Inputs are only grab able on the main thread, and rendering is only done on the main thread. If you run the game in the main thread too you can end up with your browser tab becoming unresponsive, or have delays in the input and rendering that affect the games performance. It's the same as when you make a python UI all in one thread, you can't receive user input and also do some long task at the same time.
- djhworld 5y agoI'd ported the emulator to WASM from one I'd half written a few years previously, and engineered myself into a corner (+ like I said, not a web programmer) The emulator ran in the worker, and the inputs were handled on the main thread. The output (i.e. display) was pushed from the worker -> main thread I think if I was to do it from scratch I'd do something similar to the DooM approach here and use renderAnimationFrame etc If you're interested I wrote about it a few years ago but haven't touch it since https://djharper.dev/post/2018/09/21/i-ported-my-gameboy-color-emulator-to-webassembly/ https://djharper.dev/post/2018/09/21/i-ported-my-gameboy-col...