clydeshaffer / GameTankEmulator

An emulator for the GameTank, a real physical hardware game console I've built
MIT License
15 stars 9 forks source link

Pause emulation on tab blur #41

Closed nickgirardo closed 3 weeks ago

nickgirardo commented 3 weeks ago

Browsers heavily throttle non-active flags. This is especially bad with the gametank emulator's web build as this often leads to deeply cursed audio as the audio processor is not given enough time to run.

This pr adds some simple, idempotent functions to gte.cpp to pause and resume emulation. These functions are exported for use through emscripten. The browser uses a visibilitychange event on the page to call PauseEmulation or ResumeEmulation respectively.

Lmk what your thoughts on this pr are. I didn't see any other functions specifically for controlling the emulator's paused state, so I'm not sure I'm pausing everything I need to.

Note on <iframe>s: According to mdn, iframes inherit the visibility status of their containing page. This means that if you tab away from an itch page with an emulator running the embedded emulator iframe also receives the visibilitychange event. I haven't updated the embedded shell in this pr to also feature pausing functionality, but I could if you want.


Update: pause/ resume functionality has been added to the embedded shell

clydeshaffer commented 3 weeks ago

Looks good! I think adding it to the embed shell as well would be reasonable

nickgirardo commented 3 weeks ago

Looks good! I think adding it to the embed shell as well would be reasonable

It's been added!