I tried to add sound to the game, but got a problem.
If a function that requires a lot of processor resources is working during music playback, then the sound lags. I have no idea how to solve this. Is it possible to add asynchrony here? Or limit the function? This happens not only with sound, the whole game freezes. But with sound, this is most noticeable.
A simple example below.
calc() calculates the sum of primes. Found it on the Internet. The main thing is the demanding function.Simple project.zip (8.9 MB)