0

i am working on a rapid fire program for games and what not and i'm trying to search around to find a way to have a consistently timed loop, now i understand windows is not a real-time operating system (RTOS), i'm only wanting to know what the most reliable method would be for what i'm trying to do. My current method is just threading and sleeping. If you could provide me with a code sample on the best method to use that would be great. Also a side question is C++ more accurate when it comes to timing ?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
DaftHacker
  • 13
  • 1
  • 5

1 Answers1

2

Unless you're working on dedicated hardware you can't guarantee any kind of consistency in the timing of your loop since you have no control over what else is running on the same system, but you can work around it by factoring the time passed between each iteration of your loop into your computations.

The term for this is delta-time - which typically means the change in time since the last frame in the context of game development. For example if your game is running at 60 fps, then your delta-time will usually be somewhere around 16 milliseconds, or 0.016 seconds.

If you start searching using delta-time you'll find a lot more useful results. For example:

Community
  • 1
  • 1
Brett
  • 843
  • 1
  • 7
  • 18
  • I'm not really trying to do anything game specific, I'm just looping and checking if a key is pressed and then simulating key presses. I'm just trying to figure out the best and most accurate method of handling it. – DaftHacker Sep 26 '16 at 07:11
  • @DaftHacker : Even if you managed to simulate key-presses with deterministic timing, they will just be placed into the input event queue of the receiving process which will be processed when *that* process chooses to do so, which you have no control over so it is perhaps ultimately pointless. – Clifford Oct 03 '16 at 22:04