r/howdidtheycodeit • • Jul 28 '22

Question How Does FPS Limiting Work

It just dawned on me I have no idea how limiting FPS in an engine works.

The piece I'm most uncertain about is what to do with the time after you've hit the cap. For example, if cap at 60fps and we get through everything in 0.75 seconds what happens to the remaining 0.25? If the engine sits idle for that time until the next second, won't there be a notable jitter in either input handling or rendering as we wait for the 0.25 to expire? If that tracks and I haven't missed something, or am otherwise completely off, it seems to suggest there is some method of sequencing the 60 frames across the full second but I don't suspect you could possibly know how long a frame will take to calculate before it is going to be dealt with.

I hope the question I am asking in that paragraph is clear. I also think there is a whole lot about rendering that I'm not aware of so if that is the case I'd love to be taught.

39 Upvotes

9 comments sorted by

View all comments

Show parent comment

2

u/WikiSummarizerBot Jul 28 '22

Multiple buffering

Double buffering in computer graphics

In computer graphics, double buffering is a technique for drawing graphics that shows no (or less) stutter, tearing, and other artifacts. It is difficult for a program to draw a display so that pixels do not change more than once. For instance, when updating a page of text, it is much easier to clear the entire page and then draw the letters than to somehow erase only the pixels that are used in old letters but not in new ones. However, this intermediate image is seen by the user as flickering.

[ F.A.Q | Opt Out | Opt Out Of Subreddit | GitHub ] Downvote to remove | v1.5