GDQuest / learn-gdscript

Learn Godot's GDScript programming language from zero, right in your browser, for free.
https://gdquest.github.io/learn-gdscript/
Other
2.11k stars 160 forks source link

Locked on 50 FPS on Windows #771

Closed Adiveler closed 1 year ago

Adiveler commented 1 year ago

Describe the bug App is locked on 50 FPS, no matter what option I choose (30 FPS works as intended though)

To Reproduce Steps to reproduce the bug:

  1. Enter the desktop app.
  2. Click "Options".
  3. In "Framerate cap", choose either 60 FPS or No limit.
  4. App is locked on 50 FPS on either option.

Expected behavior 60 FPS for 60, and 144 FPS (my desktop cap FPS) for no limit

Screenshots 50locked

Information about your device (please complete the following information):

Additional context I'm using G-Sync for performance; and MSI Afterburner for monitoring (FPS, RAM, CPU and GPU temperatures during demanding games, etc…)

Adiveler commented 1 year ago

Disabling G-Sync doesn't seem to solve the issue, it's still locked on 50 FPS.

NathanLovato commented 1 year ago

Thanks, I have no idea of what could be causing this, and it seems to be a low-priority issue. I'll wait to see if someone can pinpoint the cause.

Calinou commented 1 year ago

The cause is here: https://github.com/GDQuest/learn-gdscript/blob/6f52f8f76c3b03fefe8a99fe9aec7398f94e02bd/ui/UICore.gd#L31

No matter the value of Engine.target_fps, the engine will always sleep at least 20,000 microseconds between frames (= 20 milliseconds). This equates to 50 FPS at most.

When using low processor mode, I recommend not setting Engine.target_fps. Instead, set OS.low_processor_mode_sleep_usec to 1_000_000 / fps where fps is the maximum FPS as an integer.

Eventually, we should deprecate OS.low_processor_mode_sleep_usec entirely and only rely on Engine.target_fps to avoid this kind of "double limit" issue, but this will have to wait for Godot 4.1 at the earliest.

PS: While doing this, it's a good opportunity to disable V-Sync in the project settings to decrease input lag (on platforms that support disabling V-Sync). This should make scrolling and selecting text feel noticeably snappier. While disabling V-Sync will result in tearing, it's usually hard to notice in non-game applications.

NathanLovato commented 1 year ago

Thanks, gonna fix right away