Time calculation in the main game loop.

Aug 26, 2020 at 8:41am
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;


???
What is the role of that mask?
Last edited on Aug 26, 2020 at 8:43am
Aug 26, 2020 at 9:59am


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.
Aug 26, 2020 at 2:24pm
Ok, but what's for applying the mask?
Aug 26, 2020 at 3:53pm
Also posted here: https://stackoverflow.com/questions/63564634/time-calculation-in-the-main-game-loop
And here: https://sourceforge.net/p/orwelldevcpp/forums/general/thread/4212230bf5/?limit=25

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.
Last edited on Aug 26, 2020 at 3:56pm
Aug 26, 2020 at 4:40pm
Topic archived. No new replies allowed.