Open pancelor opened 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
A comment from a puzzlescript dev that I just stumbled across on discord:
Apparently
key_repeat_interval
acts differently across browsers? So I made a test file: key_repeat_interval.txt. I set up a situation withkey_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 knowrequestAnimationFrame
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:requestAnimationFrame
instead ofsetInterval
requestAnimationFrame