Delta Time - Streamlined Time Keeping For Games
jordan4ibanez
jordan4ibanez002 at gmail.com
Sat Aug 20 22:15:44 UTC 2022
On Saturday, 20 August 2022 at 11:26:08 UTC, Abdulhaq wrote:
> On Saturday, 20 August 2022 at 00:32:25 UTC, jordan4ibanez
> wrote:
>
>> This library allows you to track it precisely between frames.
>> Nanoseconds precise.
>>
>
> just out of curiosity, when you say nanoseconds precise do you
> mean to imply it is nanoseconds accurate? And if so, what makes
> you confident that that is the case?
Because it is using the built in MonoTime. Which represents time
in system clock ticks utilizing the highest precision your system
allows. I should have clarified this gives you a USABLE delta,
not an integer or long. A double where you can just plop it into
code that's frame locked and get code that now basically
interpolates between frames properly. This is what I mean by
"keeping time". Not adding a bunch of values together to get the
total delta value since the program started, or trying to get the
beginning of the universe, just a value that allows player's to
have an enjoyably consistent experience.
So here is the actual calculation:
```d
Duration duration = after - before;
delta = cast(double)duration.total!("nsecs") / 1_000_000_000.0;
```
So I would understand if you have a response of: "WAIT, THAT'S A
DOUBLE! THAT'S NOT PRECISE!". And you're absolutely right, but if
you do this calculation yourself to get delta time, you will
still get the same double floating point errors. But the base
calculation using MonoTime is absolutely precise. (Precise in the
library code. Now in the field, well the follow up is some
examples)
If this is incorrect when calculated in your system there are
five possibilities:
1. The library is wrongly implemented for your operating system,
open a bug report into the library.
2. A stray particle of radiation has hit the floating point
calculation in your cpu. I can't help with this. Shield with lead.
3. You have managed to perfectly time your FPS to the point where
the timestamp division to get the real time in a usable format in
seconds has managed to find it's way into the precision loss of
IEEE-754. (I'm happy for you for having such a powerful pc) In
this case, we need 128bit floating point calculators in
computers. But I do not manufacture cpus.
4. Your cpu is so old that the timestamp total! throws an error
or returns 0 for the "nsecs" call. There's really nothing I can
do about that one.
5. You have overclocked your system and done something horribly,
horribly wrong to the point where it affects the system's ability
to keep time at all.
There are probably many, many, many more situations where things
just go absolutely insane. But at that point, I cannot possibly
go out to a location and diagnose operating system and hardware
things for everyone because that's expensive and I am just one
person. I hope this clarifies things. Thank you for reading.
More information about the Digitalmars-d
mailing list