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

FPS innaccurate for stage.frameRate #2710

Open
helpmeiguess opened this issue Jun 1, 2024 · 2 comments
Open

FPS innaccurate for stage.frameRate #2710

helpmeiguess opened this issue Jun 1, 2024 · 2 comments

Comments

@helpmeiguess
Copy link

Haxe version: latest stable
OpenFL version: latest stable
Lime version: latest stable
Affected targets: desktop, others untested.

Make a basic project with openfl create
Make an openfl.display.FPS and add it in main.
In your Starting state, set stage.frameRate to your monitors current hz.
In your project.xml, make sure vsync is "true" for your target.
Compile. The FPS display will be accurate to your actual hz, sometimes with a difference of around 1 or 2.
In project.xml, change vsync to false.
Compile. The FPS display will be inaccurate.

144 stage.frameRate displays ~168, 60 does 64.
Test with whatever numbers you'd like. if you're skeptical, try 90 fps and then try 91. The display changes from 92 to 102. That's definitely not right.

Main.hx:
package;

import openfl.display.Sprite;

class Main extends Sprite
{
	public function new()
	{
		super();

		addChild(new openfl.display.FPS());
		stage.frameRate = 144;
	}
}
@Dimensionscape
Copy link
Member

if You want to lock your framerate to your refresh rate, build with vsync enabled. This is not a bug, but a well known issue with the granularity of delta time in our main loop and a common issue in games or frameworks that rely on sdl. We can only measure time in whole milliseconds, which creates an issue where flooring prevents microsecond accuracy (60 fps would be ~16.6667ms per frame).

If we set the fps to 60, we end up with something like 62.5, which is 1000/16 instead of 1000/16.6667.

Fixing this ultimately requires modifying the main loop in lime. There is some discussion in regards to this here:
openfl/lime#1569 (comment)

@joshtynjala
Copy link
Member

I wonder if it makes sense to cap the value displayed by openfl.display.FPS by checking it against stage.frameRate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants