illegalinstruction / spe321_mhis

This was an interactive piece about mental health, made for Oregon Tech's SPE 321 course. Leaving it here as a monument to us having beaten Twine into submission.
1 stars 0 forks source link

drawNextFrame() possibly being called too often #35

Closed illegalinstruction closed 2 years ago

illegalinstruction commented 2 years ago

Steps to reproduce:

  1. On an older/slower/lowend laptop, play the game.

Notice that the fans go berzerk, even though we're really only painting at most six images, an operation that'll be accelerated in most browsers.

illegalinstruction commented 2 years ago

...and now I see why:

setInterval(render_next_frame, (FRAME_RATE/1000.0));

should be

setInterval(render_next_frame, (1000.0/FRAME_RATE));

...embarrassingly, it's been like that for weeks.

illegalinstruction commented 2 years ago

Change this to setTimeout() - Chrome and Edge blithely ignore setInterval() 🙄

illegalinstruction commented 2 years ago

This is still a problem, thanks to another odd quirk of Twine: drawNextFrame() gets registered as a a callback once for every passage load. (You can see it if you carefully watch the anxiety bar - it starts scrolling like mad, even when your anxiety is in the green).

The fix is probably to just have a bool somewhere that tracks the first time we called setInterval(), and if it's already been done, don't do it a second time.