精确延时,不需考虑整数回转问题

提示:如有转载请注明作者 小游戏 及出处

 

#define time_after(a,b) ((long)(b) - (long)(a) < 0)
#define time_before(a,b) time_after(b,a)

#define time_after_eq(a,b) ((long)(a) - (long)(b) >= 0)
#define time_before_eq(a,b) time_after_eq(b,a)


void delaytime(unsigned long nTime)
{
    unsigned long nEndTime = ::GetTickCount() + nTime;
    while(1)
       {
            if (time_after(::GetTickCount(), nEndTime))
            {               
                break;
            }
            MSG msg;
            if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
            {   
                TranslateMessage(&msg);  
                DispatchMessage(&msg);  
            }
       }
}

 

 

你可能感兴趣的:(游戏)