I guess the question is straightforward. I’m creating a simple 2D game with a few animation and 30 or 60 fps are more than enough. I’d like to cap the fps to reduce power consumption on my laptop when testing my own game. I can manage that from the nvidia control panel, but I can do that from ingame code? I can see many games provide a fps cap option. How do they achieve that? Sleeping/calling Sdl_delay doesn’t seem a great option and neither is active waiting while checking for passed time. Is there an hardware mechanism I can block to?

  • @Redkey
    link
    122 days ago

    deleted by creator

  • @Redkey
    link
    122 days ago

    You say active waiting, but I wonder if you mean a busy-wait? Busy-waiting is generally bad, but don’t forget that your main loop is just what executes when the OS decides to give your program some processor time. If you just check a stored timestamp vs the current clock at the start of each iteration, and then do nothing unless enough time has passed, control will go back to the OS for a bit, not the start of your next loop, so it’s not a true busy-wait.

    The original PC’s hardware timer was… not great, and I believe that the situation only got worse over time. I understand the desire not to waste resources, but modern OSs are designed with the fear of not fully exploiting resources, so there’s only so much you can do.