I'm playing with the original Quake2 game source code for Windows. There is the code which me some doubts an questions.
Sys_Milliseconds function implementation (q_shwin.c):
/*
================
Sys_Milliseconds
================
*/
int curtime;
int Sys_Milliseconds (void)
{
static int base;
static qboolean initialized = false;
if (!initialized)
{ // let base retain 16 bits of effectively random data
base = timeGetTime() & 0xffff0000;
initialized = true;
}
curtime = timeGetTime() - base;
return curtime;
}
Sys_Milliseconds function usage (sys_win.c) - the main game loop:
...
oldtime = Sys_Milliseconds ();
/* main window message loop */
while (1)
{
// if at a full screen console, don't update unless needed
if (Minimized || (dedicated && dedicated->value) )
{
Sleep (1);
}
while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!GetMessage (&msg, NULL, 0, 0))
Com_Quit ();
sys_msg_time = msg.time;
TranslateMessage (&msg);
DispatchMessage (&msg);
}
do
{
newtime = Sys_Milliseconds ();
time = newtime - oldtime;
} while (time < 1);
// Con_Printf ("time:%5.2f - %5.2f = %5.2f\n", newtime, oldtime, time);
// _controlfp( ~( _EM_ZERODIVIDE /*| _EM_INVALID*/ ), _MCW_EM );
_controlfp( _PC_24, _MCW_PC );
Qcommon_Frame (time);
oldtime = newtime;
}
...
Now I'm wondering is it at all possible for the time variable to be < 1? since the oldtime will ALWAYS be < then newtime just because we take the newtime AFTER the oldtime!?
Can You be so nice and try to explain it to Me. Thx.
User contributions licensed under CC BY-SA 3.0