increpare / PuzzleScript

Open Source HTML5 Puzzle Game Engine
MIT License
903 stars 159 forks source link

realtime_interval and key_repeat_interval are browser-dependent #949

Open pancelor opened 1 year ago

pancelor commented 1 year ago

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:

pancelor commented 1 year ago

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