zztgo
zztgo copied to clipboard
implement SoundHasTimeElapsed
SoundUninstall could be implemented to send a "quit" signal to the ticking routine, but I'm not sure if it has to be.
Also removes some code with DOS-specific workarounds that is not necessary here.
Sound does not work, but ticking speeds should now accurately match the original ZZT (though there's an odd issue with it occasionally doing a few ticks in one go for me, and I wonder why that is).
Hey @asiekierka, thanks for this! I like how you've simulated the sound timer "interrupt handler" with a Ticker running on a background goroutine. However, the problem with this is that there's no CPU sleep, so when you run the game with your PR it uses 100% CPU as it's now a busy loop -- presumably the DOS one had the same issue, but that didn't really matter in the DOS days. :-)
You can see this by going to Activity Monitor (I'm on macOS) when you're on the TOWN.ZZT title screen. In the previous code it uses ~3% CPU, with this PR it uses ~100%.
So I think it'll have to be some kind of "sleep till the next tick wake-up time" approach. Whether that's a literal time.Sleep()
or a wait on a ticker channel or something, I'm not sure.
That did not... occur to me, somehow! Sorry, sorry.
You could just wait for the next Ticker tick if SoundHasTimeElapsed is false, yes; as it's not going to return true unless that's the case.