If you check Quake 1 source code (sys_linux.c), you can see something like this:
double time, oldtime, newtime;
double Sys_FloatTime (void)
{
struct timeval tp;
struct timezone tzp;
static int secbase; // new epoch
gettimeofday(&tp, &tzp);
if (!secbase)
{
secbase = tp.tv_sec;
return tp.tv_usec/1000000.0;
}
return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
}
while (1)
{
// find time spent rendering last frame
newtime = Sys_FloatTime ();
time = newtime - oldtime;
if (time > sys_ticrate.value*2) // 50 ms * 2
oldtime = newtime;
else
oldtime += time;
Host_Frame (time);
}
Why does Quake do = some time and += at other times? I suppose it must be some floating point issue, but Sys_FloatTime() returns a double, which is very accurate. It is also adjusted to return seconds from the start of the program, it doesn't count from 1/1/1970. Changing the code to use assignment at all times, doesn't seem to change anything.
EDIT: If you check QW source code, you will see, that Sys_FloatTime() is renamed to Sys_DoubleTime(). But even if a float was returned, why would using += vs = make any difference? IMO, ever using a float for something like this was wrong, plain and simple.
oldtime = newtime;andoldtime += time;do the same thing. I doubt this is to manipulatefloatcalculations, as in the worst case your result might be 0.0001 milliseconds different, which makes absolutely no difference when you are calculating frames. Arenewtimeandoldtimedefined asdoubleas well? \$\endgroup\$newtimeis current time of the frame (from the start of the application).oldtimeis the same, but of the previous frame.timeis the difference between them. Sooldtime + time == newtimeno? So the statementsoldtime = newtimeis the same asoldtime = oldtime +time. Please correct me if I'm wrong, as I find this topic very interesting. \$\endgroup\$Sys_FloatTime. It looks like an unsuccessful attempt to use floats to me, where they don't belong. Both aredoubleyes, added to the code. \$\endgroup\$