another problem I am having is that I have a delay and it is not that smooth when I move mouse quickly.
What does your run loop look like? Are you processing all window messages before you continue in the loop?
another problem I am having is that I have a delay and it is not that smooth when I move mouse quickly.
What does your run loop look like? Are you processing all window messages before you continue in the loop?
Personnally i prefer doing this by responding to WM_MOUSExxxx messages, it keep thing simple and it's the way windows work, you only get notified when something happen.
I think rawinput is better for pooling.
I was using it before but I wanted to learn Raw Input. So I might get back to it if I cant solve the problems that I am having with Raw Input fast.
What does your run loop look like? Are you processing all window messages before you continue in the loop?
This is my WndProc
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch( message )
{
case WM_INPUT:
InputManager::HandleInput((HRAWINPUT)lParam);
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hWnd, message, wParam, lParam );
}
return 0;
}
I have a GameWindow class which is a container for window
const bool GameWindow::ProcessMessages() const
{
static MSG message;
if(PeekMessage(&message, hWnd, 0, 0, PM_REMOVE))
{
if(message.message == WM_QUIT)
{
return false;
}
else
{
TranslateMessage(&message);
DispatchMessage(&message);
}
}
return true;
}
And my game loop is like this
while(gameWindow->ProcessMessages())
{
// do update and rendering stuff here
}
if(PeekMessage(&message, hWnd, 0, 0, PM_REMOVE)) { if(message.message == WM_QUIT) { return false; } else { TranslateMessage(&message); DispatchMessage(&message); } }
The delay you mention above is likely because you process only one message per render loop. That will probably be corrected if you change that to:
while( PeekMessage(..))
{
...
}
if(PeekMessage(&message, hWnd, 0, 0, PM_REMOVE)) { if(message.message == WM_QUIT) { return false; } else { TranslateMessage(&message); DispatchMessage(&message); } }The delay you mention above is likely because you process only one message per render loop. That will probably be corrected if you change that to:
while( PeekMessage(..)) { ... }
Thanks this solved my problem and increased my FPS. Also I change my mouse position code a little
This
mouseInfo.movementX = raw->data.mouse.lLastX;
mouseInfo.movementY = raw->data.mouse.lLastY;
to
mouseInfo.movementX += raw->data.mouse.lLastX;
mouseInfo.movementY += raw->data.mouse.lLastY;
Since that while loop can call this function more than once. And in my Update function for input manager I reset them to 0 after I process the current value.
Just a little sidenote on you're message loop, this:
if(message.message == WM_QUIT)
{
return false;
}
else
{
TranslateMessage(&message);
DispatchMessage(&message);
}
Can be reduced to this:
if(message.message == WM_QUIT)
return false;
TranslateMessage(&message);
DispatchMessage(&message);