VSync - detecting missed frames

The VSync in SDL2 works well, but there is one thing that I don’t know how to do. I’m going to make the animation speed synchronized with the refresh rate. For example, it can be one animation frame per two refresh frames (for 60 Hz screens; for higher refresh rates it should be more). I can call SDL_RenderPresent (with a renderer that uses VSync) a specific number of times to make it so, but there is a possibility that the screen was already refreshed at least once before doing it, due to the game code, or anything else in the system, taking some CPU time. In such case the game should reduce the number of calls to SDL_RenderPresent to take into account the missed frames.

So, is there a way to detect the number of screen refreshes that happened after the last call to SDL_RenderPresent? I thought about using SDL_GetTicks to count the amount of time passed, but as far as I know it’s not very accurate. If that matters, my game is 2d (so I’m not using OpenGL or anything like that), and I’m developing it for Windows only - I have no plans to make it multiplatform anytime soon, so if the solution works only on Windows, I’m OK with it.

Should probably make your animation time based instead of frame based.

“No matter how many frames are displayed per second, the character can only move this much in a second”.

Should result in consistent animation across many systems. Ive seen a lot of people pull it off with SDL_GetTicks measuring HINT ==> Delta Time <== HINT, but if you’re worried about accuracy, try C++11s . I haven’t done a side by side with it and SDL, but I’ve heard just as many good things about it as I have about SDLs timing mechanisms. It could be better, but it won’t be worse…if either is bad at all.------------------------
"You all look like lions to me. Lets be rabbits again."
https://github.com/ts-williams

Thanks, my tests show that the SDL_GetTicks function is quite accurate (so there’s no need to use ), my assumption that it isn’t was caused by my experiences with SDL 1.2 some time ago, where I tried to create my own VSync, as it wasn’t available as a part of SDL, like it is now. I did it by counting the number of milliseconds before refreshing the screen, but it didn’t work well. But in SDL2 it seems to be accurate enough to count the number of frames that passed.