Sign in to follow this  
NimrodPSI

Lagging input with WM_INPUT

Recommended Posts

NimrodPSI    131
Hello, I'm currently developing a fairly simple gaming system where u move about a 3d world and hack stuff with a sword, C++ with openGL for graphics btw. Now, when standing still(e.x. not using the keyboard for movement input) clicking will cause you to attack, this works great with no apparent lag, problem comes when you move around and attack rapidly theres a great amount of delay between mouse clicks and then when you stop moving and aren't clicking the mouse, it continues to attack multiple times as if its still reading those delayed mouse clicks. Is there anyway to simply clear out the input buffer for the mouse to stop this lag effect? I'm trying to stay away from Direct Input, because from what i here its no better. Thanks!

Share this post


Link to post
Share on other sites
Evil Steve    2017
Are you processing all window messages before rendering one frame? Or are you processing one window message per frame? You should definitely be doing the former.

EDIT: And yes, DirectInput just handles WM_INPUT internally in another thread. So you gain nothing (Except perhaps a bit of abstraction) and lose a bit of speed from thread context switching (Admittedly, not much).

Share this post


Link to post
Share on other sites
NimrodPSI    131
Egh.... wont lie im not quite sure what you mean lol. Perhapse some code...

ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
Initialize();
while (!done)
{
PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
if (msg.message == WM_QUIT)
{
done = TRUE;
}
if(keys[VK_ESCAPE])
{
done = TRUE;
}
else
{

DrawGLScene();
SwapBuffers(g_HDC);
glFlush();

GetCursorPos(&mousePos);
GetInput();

Camera.RotateByMouse(mousePos.x, mousePos.y, w, h);
SetCursorPos(w, h);

TranslateMessage(&msg);
DispatchMessage(&msg);

SetCursorPos(w, h);
}

}

i think im doing it once a frame, the coding for the window and messages is based off of gamedevs OpenGL Game Programing book

Share this post


Link to post
Share on other sites
NimrodPSI    131
Alrighty well it appears i did know what you meant more than i thought. Simply put PeekMessage in an if statement before drawing the scene, if it returned true( there was a message) it manually calls WndProc and handles it. Seems to have solved my problem perfectly, heres the changed code:

//PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE); (old PeekMessage)
if (msg.message == WM_QUIT)
{
done = TRUE;
}
if(GetAsyncKeyState(VK_ESCAPE))
{
done = TRUE;
}
if( PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE)){
WndProc( hwnd, msg.message, NULL, NULL);
}
else
{
DrawGLScene();
etc.
}
}

Thanks alot for your help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this