There is the code in the Quake 2 main game loop implementation:
1 2 3 4 5 6
if (!initialized)
{ // let base retain 16 bits of effectively random data
base = timeGetTime() & 0xffff0000;
initialized = true;
}
curtime = timeGetTime() - base;
I'm wondering about the line:
base = timeGetTime() & 0xffff0000
Why are they applying the
0xffff0000
mask on the retrieved time? Why not to use just:
1 2 3 4 5 6
if (!initialized)
{ // let base retain 16 bits of effectively random data
initialTime = timeGetTime();
initialized = true;
}
curtime = timeGetTime() - initialTime;
The if (!initialized) check will only pass once. Therefore curtime will become larger with each gameloop, which wouldn't be the case with suggested rewrite, since the upper word may increase after sufficiently many gameloops.
Is that your same account? The fact that the reply here (nikkinemo95) is the same reply as the one in the SO thread is awfully suspicious...
It doesn't really matter, because it's effectively a time-based "random" initial value, like it says in the comment. It might have been a typo, and the programmer meant & 0xffff instead.