Opened 10 years ago

Closed 9 years ago

Last modified 7 years ago

#2882 closed defect (fixed)

[PATCH] 200 FPS in main menu

Reported by: Salesome Owned by: Itms
Priority: Should Have Milestone: Alpha 19
Component: Core engine Keywords: patch
Cc: Patch:

Description (last modified by fabio)

When starting the game, the FPS counter shows around 200 FPS in the main menu (see attached screenshot).

I think, there should be a hard-coded limit of 60 or 30 FPS.

Attachments (4)

screenshot.jpg (376.3 KB ) - added by Salesome 10 years ago.
see FPS counter
t2882_limit_fps_wip_v1.patch (627 bytes ) - added by elexis 9 years ago.
Limits the FPS to 60 max. (showcase / wip)
t2882_limit_fps_v2.patch (4.2 KB ) - added by elexis 9 years ago.
Adds a binary config option to limit the FPS to 50 if not ingame. Checking that config value each frame is no problem, since ConfigDB caches those values. vsync is ignored. If a user has 60 Hz, he/she will end up with 30 fps if I understand the description above correctly.
t2882_limit_fps_v3.patch (5.0 KB ) - added by elexis 9 years ago.
Use the prefix "gui.menu" to the setting name and adds an entry to default.cfg.

Download all attachments as: .zip

Change History (19)

by Salesome, 10 years ago

Attachment: screenshot.jpg added

see FPS counter

comment:1 by fabio, 10 years ago

You can enable vsync in game options for that, it will also save power (also fans should run lower, etc.) and avoid tearing. This should eventually be enabled by default.

by elexis, 9 years ago

Limits the FPS to 60 max. (showcase / wip)

comment:2 by elexis, 9 years ago

Keywords: patch review added
Milestone: BacklogAlpha 19
Priority: Nice to HaveShould Have

This ticket should definitely be fixed as every instance of 0ad draws as many frames as possible and consequently uses 100% cpu of a single core, no matter what.

Open questions:

-Where to save the constant (1/maxFPS)? -Should some sort of vsync be used? -SDL_WaitEvent should not be used?

// don't use SDL_WaitEvent: don't want the main loop to freeze until app focus is restored

-Limit the FPS only in the main menu, or ingame too?

comment:3 by fabio, 9 years ago

Enabling vsync by default would be better, other than limiting fps it will also avoid tearing.

comment:4 by elexis, 9 years ago

I remember from old times that I had to disable vsync to make the games run with acceptable performance. Some research suggests that vsync indeed can have negative performance impact causing the performance to drop by 50%:

From https://www.reddit.com/r/ftlgame/comments/15mxmt/does_vsync_affect_performance/

Most monitors refresh at 60 Hz (60 fps), so Vsync will limit your refresh rate options to things that divide evenly into that: 60, 30, 15, 7.5, etc. If you're currently getting something just under 60 fps, Vsync will cut it all the way to 30, which looks bad on paper but it's exactly what it's intended to do.

From http://www.tweakguides.com/Graphics_9.html

There is however a more fundamental problem with enabling VSync, and that is it can significantly reduce your overall framerate, often dropping your FPS to exactly 50% of the refresh rate. This is a difficult concept to explain, but it just has to do with timing. When VSync is enabled, your graphics card becomes a slave to your monitor. If at any time your FPS falls just below your refresh rate, each frame starts taking your graphics card longer to draw than the time it takes for your monitor to refresh itself. So every 2nd refresh, your graphics card just misses completing a new whole frame in time. This means that both its primary and secondary frame buffers are filled, it has nowhere to put any new information, so it has to sit idle and wait for the next refresh to come around before it can unload its recently completed frame, and start work on a new one in the newly cleared secondary buffer. This results in exactly half the framerate of the refresh rate whenever your FPS falls below the refresh rate.

comment:5 by elexis, 9 years ago

Some extracts from the IRC logs:

April 8th 2015: (23:09:44) leper: (yes we should cap that at some point, but you can also just enable vsync)

March 16th 2015: (21:59:57) Arthur_D: in SuperTuxKart, we limit FPS in menus and cutscenes to about 30-33 FPS, also if vsync is off. Makes it easier for laptops too (22:00:47) Philip`: Arthur_D: Yeah, that seems better than forcing people to enable vsync (22:01:06) Philip`: since vsync hurts performance when you're actually playing (22:02:12) Arthur_D: some newer screens are 120 or more hz though, which is still overkill for menus ;)

comment:6 by Itms, 9 years ago

Just don't cap FPS in the main game in a hardcoded way, or gamers will commit suicide. Might be okay for menus though. Maybe make that a config option? One value for menus, default 30 or 60, one value for game, default unlimited?

Last edited 9 years ago by Itms (previous) (diff)

by elexis, 9 years ago

Attachment: t2882_limit_fps_v2.patch added

Adds a binary config option to limit the FPS to 50 if not ingame. Checking that config value each frame is no problem, since ConfigDB caches those values. vsync is ignored. If a user has 60 Hz, he/she will end up with 30 fps if I understand the description above correctly.

comment:7 by Stan, 9 years ago

@Elexis, are you sure the string "Persist Match Settings" instead of "Persist match settings" should be included for this ticket ?

in reply to:  7 comment:8 by elexis, 9 years ago

Replying to stanislas69:

@Elexis, are you sure the string "Persist Match Settings" instead of "Persist match settings" should be included for this ticket ?

I thought it could be fixed as the other options are capitalized as well: https://i.imgur.com/aWIvzfD.jpg

comment:9 by Stan, 9 years ago

Okay, just wanted to make sure it wasn't unintentional :)

comment:10 by Itms, 9 years ago

Summary: 200 FPS in main menu[PATCH] 200 FPS in main menu

by elexis, 9 years ago

Attachment: t2882_limit_fps_v3.patch added

Use the prefix "gui.menu" to the setting name and adds an entry to default.cfg.

comment:11 by Itms, 9 years ago

Owner: set to Itms
Resolution: fixed
Status: newclosed

In 16927:

Optionally limit the framerate in menus to 50 FPS, to save power. Patch by elexis, fixes #2882

comment:12 by Itms, 9 years ago

Keywords: review removed

Thanks for the patch. I changed the config option to limitfps for consistency and added a check for avoiding passing negative values to SDL_Delay. I also made the comment in the main loop larger.

comment:13 by elexis, 7 years ago

In 19507:

Optional FPS Limiter for running games too, use the Slider GUI object in the config to specify custom limits.
Make it way more accurate by excluding the SDL_Wait time and microsecond precision.

Differential Revision: https://code.wildfiregames.com/D109
Refs #2882
Reviewed By: Vladislav

comment:14 by fabio, 7 years ago

Description: modified (diff)

Hi, I noticed when moving the sliders a numeric indicator was appearing in a tooltip, but disappear when it reachs the maximum value. Also the number in the tooltip has too many decimal digits, I think 1 is just enough.

Note: See TracTickets for help on using tickets.