godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.25k stars 19.99k forks source link

"Engine.max_fps" Fails When Running HTML5 Build On Google Chrome On Android Mobile Devices? #74014

Open ghost opened 1 year ago

ghost commented 1 year ago

Godot version

v4.0.rc5.official [6296b4600]

System information

[4.0 RC5 Win 11] - HTML5 on Google Chrome On Android Mobile Devices

Issue description

Hi,

Running Godot Engine v4.0 RC 5 on Windows 11.

When running an HTML5 build of our game on Google Chrome on Android mobile devices, "Engine.max_fps" fails? The Frames Per Seconds of our HTML5 game runs with no limiting, ie: the game runs as fast as the device can perform?

If we switch over to: Engine.physics_ticks_per_second = x The FPS limit is honored?

This only affects HTML5 builds running on Google Chrome on Android mobile devices, PC desktop Internet browsers are OK...

Any ideas?

Jesse "JeZxLee"

Steps to reproduce

Read description.

Minimal reproduction project

https://github.com/BetaMaxHero/GDScript_Godot_4_T-Story

Calinou commented 1 year ago

If we switch over to: Engine.physics_ticks_per_second = x The FPS limit is honored?

How are you checking the framerate? physics_ticks_per_second affects the physics simulation rate – it has no impact on rendered framerate. It is possible for physics FPS to differ from rendering FPS, but you don't want physics FPS to be lower than rendering FPS unless you're using physics interpolation (it will look jittery otherwise).

ghost commented 1 year ago

Hi...

We currently lock the game's framerate below: https://github.com/BetaMaxHero/GDScript_Godot_4_T-Story/blob/main/Main.gd#L80 (it works on everything)

If we switch it back to "Engine.max_fps" and below:

func _process(_delta):
    ScreensCore.ProcessScreenToDisplay()
    pass

It works on everything except HTML5 build on Google Chrome on Android mobile devices?

Thanks!

Jesse

ghost commented 1 year ago

Sorry, look below for our code that calculates current game Frames Per Second: https://github.com/BetaMaxHero/GDScript_Godot_4_T-Story/blob/main/ScreensCore.gd#L2197

Calinou commented 1 year ago

You don't need to calculate FPS manually. Displaying the result of Engine.get_frames_per_second() is all you need to get a FPS counter.

yfekraoui commented 1 year ago

Same problem here, i think thats because Chrome force to enable v-sync (in my opinion) since few updates ago ... I got the same problem with my game (on Godot v3.5) : few months ago, i was able to limit max fps to 30 ... its not possible anymore

Calinou commented 1 year ago

Same problem here, i think thats because Chrome force to enable v-sync (in my opinion) since few updates ago ... I got the same problem with my game (on Godot v3.5) : few months ago, i was able to limit max fps to 30 ... its not possible anymore

Godot does not ignore max_fps when V-Sync is enabled (or even when it's forced in the graphics driver or browser). The issue is somewhere else, and I don't think Chrome has changed its stance on V-Sync recently –it's been forced on many platforms for over a decade now.

We need a proper minimal reproduction project to be able to diagnose this.

yfekraoui commented 1 year ago

Same problem here, i think thats because Chrome force to enable v-sync (in my opinion) since few updates ago ... I got the same problem with my game (on Godot v3.5) : few months ago, i was able to limit max fps to 30 ... its not possible anymore

Godot does not ignore max_fps when V-Sync is enabled (or even when it's forced in the graphics driver or browser). The issue is somewhere else, and I don't think Chrome has changed its stance on V-Sync recently –it's been forced on many platforms for over a decade now.

We need a proper minimal reproduction project to be able to diagnose this.

Ok, here a minimal reproduction project : https://filebin.net/bo0vmb2ccezoyq9p/minimalProject.zip with Godot v4.0.1 Bugsquad edit (GitHub mirror): minimalProject.zip

yfekraoui commented 1 year ago

Hello @Faless , any idea how we can fix this issue ?

Faless commented 1 year ago

I think if the behavior changed in recent chrome versions what broke might be the forced redraw detection.

My guess is that GodotDisplayScreen.updateSize is incorrectly detecting a change: https://github.com/godotengine/godot/blob/master/platform/web/js/libs/library_godot_display.js#L288-L325

I wonder if it would make sense to put the force_redraw check after the max_fps check in web_main, but that will have side effects (slower resizing at low fps). https://github.com/godotengine/godot/blob/master/platform/web/web_main.cpp#L68-L73

In any case, we should double check if that is indeed the issue and possibly fix it in library_godot_display.js .