I tried that and it seems to more or less work at first glance. The values obviously aren't off by too much at least, but I'm getting some strange behaviour when I read the values of variables that I'm outputting...
The interpolation values look a lot more precise and gradual now, and the display seems to look no worse than ever... but every so often it appears that a frame has its rendering stopped prematurely (i.e. there have been a few rendering passes and the interpolation value is not yet anywhere near 1) and then the next update frame has a time difference value of something absurd around 600 when it should be around 40. Then the next 15 or so update frames have a time difference of about 2 or so and show no sign of the rendering function being called at all (and the interpolation goes above 1.0... which should never happen, maybe something to do with so long since rendering?...) before everything resumes as normal.
Another strange thing: these seem to happen around the same times every time I run the program. I see one happens around the 60th update, another around the 140th.
Does this sound like some form of overflow at work? At least it looks like something is accumulating until it reaches something bad, and then "fixes" itself at least enough to work relatively normally.
I assume it's something to do with how I converted that SKIP_TICKS value... though I can't yet see why or how the time difference jumps so much all of a sudden. Between all of the possible casts going on and the kind of accuracy that's involved, it all could be something very minor and hard to notice.
Here's some sample output of what I've described. The Update ID and Time Difference lines are output every logical update frame, with the other lines each showing a rendering pass with the time difference multiplied by the interpolation, followed by the interpolation value itself for that frame.
Update ID: 63
Time Difference:40
4.66638 | INTERPOLATION: 0.116659
7.23423 | INTERPOLATION: 0.180856
9.89777 | INTERPOLATION: 0.247444
12.4778 | INTERPOLATION: 0.311946
14.8559 | INTERPOLATION: 0.371397
17.3153 | INTERPOLATION: 0.432882
19.8922 | INTERPOLATION: 0.497305
23.0212 | INTERPOLATION: 0.575531
26.2392 | INTERPOLATION: 0.655981
29.2069 | INTERPOLATION: 0.730173
31.8234 | INTERPOLATION: 0.795585
34.3607 | INTERPOLATION: 0.859017
36.6056 | INTERPOLATION: 0.915139
38.9679 | INTERPOLATION: 0.974197
Update ID: 64
Time Difference:40
3.63768 | INTERPOLATION: 0.0909421
6.05035 | INTERPOLATION: 0.151259
8.29023 | INTERPOLATION: 0.207256
10.294 | INTERPOLATION: 0.257351
12.723 | INTERPOLATION: 0.318075
15.0759 | INTERPOLATION: 0.376897
17.2527 | INTERPOLATION: 0.431317
19.6355 | INTERPOLATION: 0.490887
22.5972 | INTERPOLATION: 0.564929
25.4675 | INTERPOLATION: 0.636687
27.9269 | INTERPOLATION: 0.698172
30.5348 | INTERPOLATION: 0.763369
32.9358 | INTERPOLATION: 0.823394
35.8223 | INTERPOLATION: 0.895558
38.7406 | INTERPOLATION: 0.968514
Update ID: 65
Time Difference:39
3.49799 | INTERPOLATION: 0.0896919
5.5751 | INTERPOLATION: 0.142951
Update ID: 66
Time Difference:598
Update ID: 67
Time Difference:2
Update ID: 68
Time Difference:2
Update ID: 69
Time Difference:2
Update ID: 70
Time Difference:2
20.584 | INTERPOLATION: 10.292
Update ID: 71
Time Difference:4
Update ID: 72
Time Difference:2
Update ID: 73
Time Difference:2
Update ID: 74
Time Difference:2
Update ID: 75
Time Difference:2
11.2783 | INTERPOLATION: 5.63913
Update ID: 76
Time Difference:5
Update ID: 77
Time Difference:2
Update ID: 78
Time Difference:2
Update ID: 79
Time Difference:2
Update ID: 80
Time Difference:2
2.00298 | INTERPOLATION: 1.00149
Update ID: 81
Time Difference:4
0.47629 | INTERPOLATION: 0.119072
0.751395 | INTERPOLATION: 0.187849
1.00378 | INTERPOLATION: 0.250945
1.26182 | INTERPOLATION: 0.315456
1.52063 | INTERPOLATION: 0.380158
1.77522 | INTERPOLATION: 0.443805
1.98939 | INTERPOLATION: 0.497349
2.19667 | INTERPOLATION: 0.549167
2.49451 | INTERPOLATION: 0.623627
2.77416 | INTERPOLATION: 0.69354
3.00062 | INTERPOLATION: 0.750155
3.23221 | INTERPOLATION: 0.808053
3.43292 | INTERPOLATION: 0.858229
3.68048 | INTERPOLATION: 0.920119
3.9097 | INTERPOLATION: 0.977426
Update ID: 82
Time Difference:38
3.56342 | INTERPOLATION: 0.0937742
5.73105 | INTERPOLATION: 0.150817
8.22578 | INTERPOLATION: 0.216468
10.9996 | INTERPOLATION: 0.289463
13.7706 | INTERPOLATION: 0.362384
16.0441 | INTERPOLATION: 0.422213
18.2864 | INTERPOLATION: 0.481222
20.7137 | INTERPOLATION: 0.545097
23.057 | INTERPOLATION: 0.606764
25.5174 | INTERPOLATION: 0.67151
27.8717 | INTERPOLATION: 0.733465
30.2256 | INTERPOLATION: 0.79541
33.3237 | INTERPOLATION: 0.87694
36.6278 | INTERPOLATION: 0.963889
I'll have to go through this slowly...
EDIT: The code I'm using to derive the amount to add to next_game_tick is the following BTW:
LONGLONG SKIP_TICKS_QPC = ( LONGLONG( Engine::SKIP_TICKS ) * getQPFreq() ) / LONGLONG( 1000 );
Where Engine::SKIP_TICKS is an int.
Though I can now see that it would be possible for the result of getQPFreq() * 40 to overflow... the fact remains that IIRC it should all result in the same value every time, so that doesn't explain why it screws up only some of the time and with such regularity...
EDIT2: Yep, well it definitely does equal the same value every time.
EDIT3: Hmmm... studying it now and what happens seems to be that something unexpectedly causes the game to enter the update loop even though there should be tons of rendering time left before then. The only reasons this might happen are...
while( getQPC() > next_game_tick && loops < Engine::MAX_FRAMESKIP )
...if loops < Engine::MAX_FRAMESKIP (that's definitely not it), OR... if next_game_tick finds itself smaller than getQPC().
Sooo... considering this is happening after maybe... 2 or 3 renderings into an update frame, where the interpolation value may be 0.23432 or something before the rendering is abandoned for a logical update... and the only way next_game_tick can be changed is by having SKIP_TICKS_QPC added to it when inside the update loop, AND I know for a fact that SKIP_TICKS_QPC evaluates to the same value every time...
...does that make it seem as though next_game_tick overflowing in some way is the most likely explanation? If people are still following me.
As for why the time difference variable goes to around 600... maybe that's working fine and it's just thrown off by whatever next_game_tick's overflow is doing? Indeed, when I run it and look at the debug output window spewing lines of text, I often notice a very discernible pause before it starts up again. Could that be... 600ms of a pause? Looks likely that it probably is...
And yet I still can't quite figure out why it would actually be pausing for 600ms between 2 updates instead of just looping around calling update() on the active game state...