Hieran_Del8 wrote:Ok, the vsync issue. When using mouse as input and having multiple backbuffers in video sync, it is possible to have mouse lag--that is, the mouse movement has a delayed affect on the frames displayed. One remedy is disabling vsync. In the d3d presentation parameters, set the presentation interval to D3DPRESENT_INTERVAL_IMMEDIATE. That's it.
I don't disable vsync, because I don't like graphical tears, and I rarely notice mouse lag. Others may be more affected by it, though.
Just following up on this earlier post. There is another remedy to this situation that preserves video sync and keeps the window's messages flowing: run the message pump in the extra time in between the frame presentations. For instance:
- Code: Select all
MSG msg;
bool bAppRunning = true;
while(bAppRunning)
{
if(PeekMessage(g_hWnd, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
{
bAppRunning = false;
break;
}
}
static DWORD dwFrameControl = GetTickCount();
d3ddev->BeginScene();
//... drawing frame ...
d3ddev->EndScene();
d3ddev->Present(0,0,0,0);
while(GetTickCount() - dwFrameControl < 17)
{
if(PeekMessage(g_hWnd, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
{
bAppRunning = false;
break;
}
}
}
dwFrameControl = GetTickCount();
}
Notice how the message pump runs twice: once at the beginning (to determine upon entry into the function whether to quit the app), and once continuously at the end until 17 milliseconds have passed (1/60th of a second, a standard monitor framerate). Because dwFrameControl is declared static, its value persists between function calls, causing the last continuous message pump to run during the time the rest of the program does not need extra cycles.
By implementing this, you can have raw input, vsync, and no mouse lag! You can adjust the 17 milliseconds to whatever value fits your needs. Just make sure it's at least as long as the presentation interval (usually is 60hz = 1 frame per 1/60th second = 1 frame per 17 milliseconds).