Jump to content
  • Advertisement
Sign in to follow this  
ryan mccabe

some questions on getting input

This topic is 2550 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I had my input system written but it was a strange mix of windows messages and polling with getasync() ect. The real problem though was that when trying to use the mouse and the keyboard the entire engine stuttered. I'm no too sure what I did there but it pushed me to try to wrap raw input and depend only on that. Its resolved the stuttering but now I'm getting mouse lag like Ive never seen. Everything keeps moving fine but a second of mouse movement is turning into a minute of movement and being locked out of further input. So if i move the mouse and hit esc to quit I have to wait for the extremely slowed input lag to finish. The whole thing is rather frustrating I'm almost ready to say die and hook in directinput, but then again that may be more hours of debugging.

What I really want to do is sidestep the message queue and go with nothing but getasync() for movement controls, will that cause problems down the line?
Raw Input is recommended but its the most complicated, for movement controls is it really the best choice?
Anyone have a link / name for some demo code and / or wrappers for raw input (c++)?

Lastly, if anyone has a minute could you take a look at the input code's latest incarnation and let me know if a message queue lagging issue pops? Any comments on the code are more than welcome too.


switch(umsg)
{
case WM_CREATE:
{
RAWINPUTDEVICE Rid[2];

Rid[0].usUsagePage = 0x01;
Rid[0].usUsage = 0x02;
Rid[0].dwFlags = 0; // adds HID mouse
Rid[0].hwndTarget = 0;

Rid[1].usUsagePage = 0x01;
Rid[1].usUsage = 0x06;
Rid[1].dwFlags = 0; // adds HID keyboard
Rid[1].hwndTarget = 0;

if (RegisterRawInputDevices(Rid, 2, sizeof(Rid[0])) == FALSE) {
strPrinter("input registration failed");
}


}

case WM_INPUT:
{
UINT dwSize;
// Determine how big the buffer should be
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize,
sizeof(RAWINPUTHEADER));
BYTE* lpb;
lpb = new BYTE[dwSize];

if (lpb == NULL)
{
strPrinter("lpb not initialized");
return 0;
}

if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize,
sizeof(RAWINPUTHEADER)) != dwSize )
strPrinter("GetRawInputData does not return correct size !");

GetRawInputData((HRAWINPUT)lParam, RID_INPUT,(LPVOID)lpb, &dwSize,
sizeof(RAWINPUTHEADER));
RAWINPUT* raw = (RAWINPUT*)lpb;

switch (raw->header.dwType)
{
case RIM_TYPEMOUSE:
{
// read the mouse data
long mx = raw->data.mouse.lLastX;
long my = raw->data.mouse.lLastY;
m_Input->mouseMove(mx, my);
delete[] lpb;
return 0;
}
case RIM_TYPEKEYBOARD:
{
// read the keyboard data
m_Input->KeyUp(raw->data.keyboard.VKey);
delete[] lpb;
return 0;
}
}
delete[] lpb;
return 0;
}


Thanks guys n gals.

Share this post


Link to post
Share on other sites
Advertisement
I think your right. Ive seen GetMessage / PeekMessage in a while loop is that what I should do? Ive tried assigning peek to a boolean and running until false but doing that blocked everything and I ended up with a black screen


void SystemClass::Run()
{
MSG msg;
bool done, result;

// Initialize the message structure.
ZeroMemory(&msg, sizeof(MSG));

// Loop until there is a quit message from the window or the user.
done = false;
while(!done)
{
// Handle the windows messages.
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

// If windows signals to end the application then exit out.
if(msg.message == WM_QUIT)
{
done = true;
}
else
{
result = Frame();
if(!result)
{
done = true;
}
}

}

return;

}


frame starts the frame processing and rendering.

Share this post


Link to post
Share on other sites

I think your right. Ive seen GetMessage / PeekMessage in a while loop is that what I should do? Ive tried assigning peek to a boolean and running until false but doing that blocked everything and I ended up with a black screen


void SystemClass::Run()
{
MSG msg;
bool done, result;

// Initialize the message structure.
ZeroMemory(&msg, sizeof(MSG));

// Loop until there is a quit message from the window or the user.
done = false;
while(!done)
{
// Handle the windows messages.
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

// If windows signals to end the application then exit out.
if(msg.message == WM_QUIT)
{
done = true;
}
else
{
result = Frame();
if(!result)
{
done = true;
}
}

}

return;

}


frame starts the frame processing and rendering.



void SystemClass::Run()
{
MSG msg;
bool done, result;

// Initialize the message structure.
ZeroMemory(&msg, sizeof(MSG));

// Loop until there is a quit message from the window or the user.
done = false;
while(!done)
{
// Handle the windows messages.
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
// If windows signals to end the application then exit out.
if(msg.message == WM_QUIT)
{
done = true;
}
else
{
if(!Frame())
{
done = true;
}
}
}
}
return;
}


Edit: indentation is messed up.

Share this post


Link to post
Share on other sites
SimonForsman, that version still processes a game frame for every message.

I imagine something like this (warning: not a Win32 programmer):

void SystemClass::Run()
{
while(true)
{
MSG msg = {};
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);

if(msg.message == WM_QUIT)
{
return;
}
}

if(!Frame())
{
return;
}
}
}


This should remove the problems you were having, and you can probably return to using simple Windows messages rather than using the more complex raw input APIs, unless there is something specific in the raw input APIs that you need.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!