游戏味精循环中的计算时间

问题描述

我正在使用Windows的原始quake2游戏源代码。有一些令我有些疑问的代码

Sys_Milliseconds函数实现( 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函数用法 sys_win.c )-游戏主循环:

...
    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,PM_norEMOVE))
        {
            if (!GetMessage (&msg,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;
    }
...

现在我想知道time变量是否完全小于1?因为oldtime总是newtime只是因为我们在newtime之后取oldtime!?

您能这么高兴,然后尝试向我解释一下。 谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)