5 ms·
There's also the problem of getting keyboard input in and out of the web worker in a performant manner. I tried this a few years ago with a Gameboy emulator I
by djhworld 5y ago
There's also the problem of getting keyboard input in and out of the web worker in a performant manner.
I tried this a few years ago with a Gameboy emulator I had ported from Go to webassembly and used web workers to run the emulator in.
Getting the keyboard input in, in a performant way was a real struggle using postMessage, although I'll admit I'm not the best at web programming so someone more skilled might have been able to do it better
- asiachick 5y agoYou could pass it via a SharedArrayBuffer
- plopz 5y agoFrom what I found on MDN "a side effect to the block in one agent will eventually become visible in the other agent", what does the word eventually mean there, what's going on under the hood?
- Dylan16807 5y agoShould just be nanoseconds. I think they're mostly making considerations for unfortunate thread scheduling where one gets stuck for a while.
- deleted 5y ago[deleted]
- sitkack 5y agoWhy 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...
- musicale 5y agoDo you mean that keyboard input into a web worker is too slow, or it uses too much memory or cpu or power or ??? How is keyboard input different from any other sort of data round trip to/from a web worker?