First of all, that's a cool idea for a module
I get the same result; the rewind speed differs from the play speed when vsync is turned off. I compared the FPS while playing vs rewinding, and the framerate is higher during rewinding (about 270fps while rewinding vs 230fps while recording). That makes sense: especially with high framerates the library stores quite a lot of timeFrames, and this code segment iterates over all of them every single frame:
Code: Select all
-- timetraveler.lua:41
for i, v in ipairs(timeFrames) do
if os.difftime(os.time(), v[2][2]) >= M.rewindLimit then
table.remove(timeFrames, i)
end
end
Since you store those time frames chronologically (newer time frames are at the end of the array, right?), couldn't you do the following instead?
Code: Select all
local time = os.time()
for i, v in ipairs(timeFrames) do
if os.difftime(time, v[2][2]) >= M.rewindLimit then
table.remove(timeFrames, i)
else
break -- skip the other timeframes once we encounter a timeframe that is within the rewindLimit,
-- since all following time frames will also be within the rewindLimit.
end
end
From some quick tests it seems like that does fix the speed differences for the most part.
---
However, I'm not sure if the library is actually supporting variable timesteps, even with the recent changes. That might be a matter of interpretation, and @zorg might correct me on that, but if the library supported variable timesteps then I would expect some sort of linear interpolation between the recorded positions when replaying. Here is what I mean: Let's say that you are on a motor bike. At time 0 you are at position 0, and you start driving. After 15 minutes you traveled 30 kilometres (so on average 2km/min). After another 20 minutes you travelled only 20 more kilometres (so on average 1km/min).
Let's say that these times and positions are your timeFrames: {{0km, 0min}, {30km, 15min}, {50km, 35min}}.
Now, if you were to rewind time by 20 minutes, then you would know exactly where you had been at that time, because one of the timeframes was recorded at that time. But if you wanted to rewind time by 25 minutes instead (so back to the 10th minute of your road trip), then there is no exact time frame for that moment. Instead, you would use the average speed between the first and second timeFrame to estimate where you might have been at that time. That is: (30km - 0km) * (10min/(15min - 0min)) = 20km.
I hope you see what I'm getting at. The point is that with variable timesteps, timeFrames might be recorded at varying speeds, and rewinding might happen at varying speed, too. You would need to walk through your history and interpolate between the two closest timeframes (or at least rewind to the timeFrame that is closest to the queried time) to account for variable timesteps.