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

Adds FPS limit option to preserve browser performance #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

userexec
Copy link

@userexec userexec commented Oct 15, 2020

Adds fps to options and associated documentation. Works by calling a setTimeout at the end of each draw instead of immediately calling the next draw. setTimeout is controlled by fps option, or can be set to 0 for no throttling. Defaults to 60FPS, which should keep Firefox tabs from crashing when they encounter this library.

Draw loop tracks elapsed time since last draw and multiplies particle speed by time so that the distance particles cover stays the same regardless of the chosen FPS. Speed is also divided by an arbitrary number to keep the distance covered by certain clock speeds roughly equal in the frame-limited animation loop to what they would have been in the unlimited loop. This is just so a clock of "25" still looks the same speed as it did without frame limiting.

fixes #23

@davwheat
Copy link

Personally, I'd be more in favour with calling requestAnimationFrame on every screen refresh, like normal, but then using logic within the animation frame handler to control skipping a new render.

https://stackoverflow.com/a/19772220/11091039

@userexec
Copy link
Author

That does seem like the more technically correct way to do it. I'd be curious to see if Firefox handles it well or just chokes from handing over too many resources to unlimited repeating calls. The settimeout solution was definitely an axe vs. scalpel situation where we just wanted Firefox to chill out and take a break.

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

Successfully merging this pull request may close these issues.

Performance issues on Firefox
2 participants