raw input mouse problem

Started by
13 comments, last by Vortez 10 years ago


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?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Advertisement

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(..))
{
   ...
}

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


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);

This topic is closed to new replies.

Advertisement