This object is in archive! 

[187] PB API: TimeSinceLastRun is inaccurate

Digi shared this bug 6 years ago
Won't Fix

This issue is pretty known already but it still is quite annoying having to explain to people that it's buggy.

Basically, TimeSinceLastRun is in 16ms steps instead of 16.66666667ms, that means that a game second is represented by 960ms instead of 1000ms, which is only for PB and a few other game features, and the error increases as time passes.

There's no reason why certain game things experience time differently, it's not like you can go fast enough to have time dilation.

Replies (2)

photo
1

Just guessing here.

As the `TimeSinceLastRun` is a `TimeSpan`-type, perhaps it is caused using the `FromMilliseconds` method or 5-arguments constructor?

Maybe using the higher resolution `FromTicks` method or 1-argument (`ticks`) constructor would solve the "problem"?(That is, if the game-engine actually keeps track of its 'game-time' using clock-ticks.)

b3666401f23d7c23a19a9674bab1bdff

photo
1

No, the internal timer used to create TimeSinceLastRun is literally being incremented with 16ms steps.


If you follow the TimeSinceLastRun setter you'll see that it uses MySession.Static.ElapsedGameTime, which is set in MySession.Update() to:

var timeSpan = new TimeSpan(0, 0, 0, 0, 16);
//...
this.ElapsedGameTime += (MyRandom.EnableDeterminism ? TimeSpan.FromMilliseconds(16.0) : timeSpan);
Regardless of first or 2nd condition passing, it does the same thing, which is adding 16ms exactly instead of (1/60)ms.


So the entire game is running on an inaccurate time, which makes it even more important to being fixed.

photo
1

So if the entire game-engine is running at '16.0 ms per game-tick' (i.e. 160000 clock-ticks), then I suppose that changing it to:

.. = new TimeSpan( (long)(1000/60.0 * TimeSpan.TicksPerMillisecond) );
.. = TimeSpan.FromTicks( (long)(1000/60.0 * TimeSpan.TicksPerMillisecond) );

will affect much more than just the Programmable Block's 'TimeSinceLastRun'?

photo
1

Yes, like the sun rotation.

Also mods/visual script (and probably even the admin menu) rotate the sun by changing that time, which is obviously really bad for the other systems assuming it's flowing like normal time... including PB scripts =)

So the issue goes even deeper xD


Ideal would be for the sun to have an offset that those methods change, instead of changing the game time along with the game time to be made accurate.

photo
1

I edited the game libs with dnSpy to try this TimeSpan edit and it didn't work, TimeSpan is inadequate for this. Instead, they would need to use an integer counter for updates and create TimeSpans from that on demand.

photo
1

Also mods/visual script (and probably even the admin menu) rotate the sun by changing that time, which is obviously really bad for the other systems assuming it's flowing like normal time... including PB scripts 
Indeed. I have to do this in my scripts now:

var lastRuntime = 1.0 / 0.96 * Math.Max(Runtime.TimeSinceLastRun.TotalSeconds, 0)

photo
1

Hello, everyone!


Thank you for your feedback, unfortunately this issue won't be fixed yet.


Keen Software House: QA Department

photo
1

It was actually fixed a few majors ago :P

Replies have been locked on this page!