3 ms·
Values are already offset (in noted snippet, timer_begin is approx. the time process has started, as in - queried during initialization). While I'll defend the
by CookiePLMonster 8y ago
Values are already offset (in noted snippet, timer_begin is approx. the time process has started, as in - queried during initialization).
While I'll defend the idea of modifying QueryPerformanceFrequency result to achieve desired resolution (in this case, ticks per ms), you are absolutely right about the possibility of the value becoming several orders of magnitude smaller in the future. In this case multiplying the subtraction result by 1000 instead of dividing frequency is indeed far safer.
- vardump 8y agoWhy do you use floats in the first place? > While I'll defend the idea of modifying QueryPerformanceFrequency result to achieve desired resolution (in this case, ticks per ms) Did a quick back-of-the-envelope calculation, and the suggested solution is off by 42 milliseconds per minute on a hypothetical 3 GHz system. It might not sound like much (~2.5 frames at 60 fps), but I've seen smaller errors cause massive issues when it comes to time. It's better to do it right rather than to later on debug these often surprising issues we didn't have sufficient imagination for. Unless one is looking for an amazing bug hunting war story, of course. :)
- CookiePLMonster 8y agoI don't - it's not my code I had to fix. And as for returning the result - original code does return a float, so while I could also return a double it probably wouldn't make any difference, as I expect the game to store those results in floats too. Moreover, since the result is basically "session time", it is expected to last up to several hours - in which case floats are still fine.
- vardump 8y agoI've often seen code like that written by mathematicians and physicists. Sigh. Things like using a bit weird data types (floats instead of doubles) and writing functions thousands (!) of lines long. Then asking me why did the reconstruction have a weird circular error around the origo...
- CookiePLMonster 8y agoEither way, it may indeed be beneficial to return time as a double - so code which stores it in floats will not care about the change, but the code which uses it in intermediate calculations will and it will potentially benefit from it. Notes taken! EDIT: Will generate more code warnings of course, but I believe it's a good tradeoff, since the game has a ton of them anyway and going through them all is something for another day.