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

Make the FPS reported by Engine.get_frames_per_second() smoother #63356

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

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Jul 23, 2022

This uses an averaging algorithm to smooth out the FPS counter. As a bonus, this also makes the reported FPS value an actual float, rather than returning a float constrained to integer steps.

This also improves the documentation a bit.

This PR can be remade for 3.6 if desired. See also #18998, which is an earlier attempt at providing something like this (with a different formula). The same formula is included in the MRP (but commented out) for reference.

Testing project: test_fps_counter.zip
Press Space to toggle between core and script-based FPS reporting. Use core-based reporting to test this PR (or the current behavior, with a vanilla master build).
Press Up/Down arrows to increase/decrease maximum FPS. Note that it's capped by V-Sync for testing purposes, but you can disable V-Sync in the project settings or run with --disable-vsync CLI argument if needed.

TODO

  • Fix the reported value being higher than it should be, especially when a FPS cap below the monitor refresh rate is used. This is likely related to what frame_time actually defines (I've also tried process_ticks to no avail). - For comparison, the script approach in the MRP does not have this issue.
    • Thanks @CaelusV for assistance in fixing this 🙂

@Calinou Calinou added this to the 4.0 milestone Jul 23, 2022
core/math/math_defs.h Outdated Show resolved Hide resolved
@Calinou Calinou force-pushed the smooth-fps-counter branch 3 times, most recently from f0d342e to 8682301 Compare July 27, 2022 17:31
main/main.cpp Outdated Show resolved Hide resolved
@Calinou
Copy link
Member Author

Calinou commented Jul 22, 2024

Rebased and tested again, it works as expected. I update the MRP in OP.

A strange issue occurs now when the engine starts: the reported FPS is negative for a brief period of time. I don't recall this happening previously, despite having made no code changes to the PR itself.

This is a video of the MRP being run at 120 FPS, slowed down to 10% so you can see it more easily:

negative_fps.mp4

This does not occur with the script-based implementation in the MRP.

@CaelusV
Copy link

CaelusV commented Jul 23, 2024

You probably want to make sure the ratio doesn't exceed 1.0 since you're subtracting it from 1.0 on the line below.

@Calinou
Copy link
Member Author

Calinou commented Jul 23, 2024

You probably want to make sure the ratio doesn't exceed 1.0 since you're subtracting it from 1.0 on the line below.

That does the trick, thanks 🙂

This uses an averaging algorithm to smooth out the FPS counter.
@Calinou Calinou force-pushed the smooth-fps-counter branch from ad72599 to 7826d68 Compare July 23, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants