Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

realtime_interval and key_repeat_interval are browser-dependent #949

Open
pancelor opened this issue Dec 20, 2022 · 1 comment
Open

realtime_interval and key_repeat_interval are browser-dependent #949

pancelor opened this issue Dec 20, 2022 · 1 comment

Comments

@pancelor
Copy link
Contributor

A comment from a puzzlescript dev that I just stumbled across on discord:

It's weird that in firefox it's like 3x times slower, hard to nail the gamefeel for all browsers alike. Sorry to those who played on Chrome!

Apparently key_repeat_interval acts differently across browsers? So I made a test file: key_repeat_interval.txt. I set up a situation with key_repeat_interval that should have taken 10 seconds, and manually timed it (with my phone's stopwatch) in each browser. In firefox it took 10.03 seconds, but in chrome it took 13.21 seconds. that's much much slower than it should be!

(I observed similar results for realtime_interval.txt -- 10.00 seconds in firefox versus 14.17 seconds in chrome. I did not test again_interval but I would guess it has similar issues)


I suspect this happens because puzzlescript uses setTimeout(loop,17) to draw frames; as far as I know requestAnimationFrame is the "correct" way to run a HTML canvas game's mainloop. I don't know where I first heard that but I did a bit of searching and found some web resources that seem to agree:

  • this tutorial talks a little bit about why you would want requestAnimationFrame instead of setInterval
  • MainLoop.js, a game loop library that looks well-thought-out, and uses requestAnimationFrame
@pancelor
Copy link
Contributor Author

this timing discrepancy seems like strong enough motivation to revive #924 / #925, so I did that: #948 is the new PR. I tested #948 locally and the discrepancy was fixed:

## results from key_repeat_interval.pz, after #948
firefox: 10.16 seconds
chrome:  10.13 seconds (yay)

## results from realtime_interval.pz, after #948
firefox: 10.13 seconds
chrome:  10.08 seconds (yay)

sorry to spread this conversation across 4 different places! I'll leave this thread here, focused on the bug, and I'll talk about requestAnimationFrame more as a reply to #925

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant