• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
mrheisenberg

RawInput causes the window to lag severely.

10 posts in this topic

This is pretty much my input handler:

[CODE]Input* gInput = 0;
Input::Input()
{
raw = 0;
}
Input::~Input()
{
}
void Input::Release()
{

}
void Input::Initialize()
{
Rid[0].usUsagePage = 1;
Rid[0].usUsage = 6;
Rid[0].dwFlags = 0;
Rid[0].hwndTarget=NULL;
Rid[1].usUsagePage = 1;
Rid[1].usUsage = 2;
Rid[1].dwFlags = 0;
Rid[1].hwndTarget=NULL;
RegisterRawInputDevices(Rid, 2, sizeof(Rid[0]));
}
void Input::Update()
{
if (raw->header.dwType== RIM_TYPEMOUSE)
{
lastMouseX = raw->data.mouse.lLastX;
lastMouseY = raw->data.mouse.lLastY;
mouseFlags = raw->data.mouse.usFlags;
mouseButtonFlags = raw->data.mouse.usButtonFlags;
leftButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_LEFT_BUTTON_DOWN;
rightButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_RIGHT_BUTTON_DOWN;
middleButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_MIDDLE_BUTTON_DOWN;
if(raw->data.mouse.ulButtons & RI_MOUSE_WHEEL)
{
wheelZ = raw->data.mouse.usButtonData;
}
}
if (raw->header.dwType== RIM_TYPEKEYBOARD)
{
keyCode=raw->data.keyboard.VKey;
bool keyPressed=raw->data.keyboard.Flags & RI_KEY_BREAK;
}
}
[/CODE]


[CODE]class Input
{
#pragma region REGION:INPUT_METHODS
public:
Input();
~Input();

void Release();
void Initialize();
void Update();
#pragma endregion
#pragma region REGION:INPUT_MEMBERS
public:
RAWINPUTDEVICE Rid[2];
RAWINPUT *raw;
long lastMouseX;
long lastMouseY;
USHORT mouseFlags;
USHORT mouseButtonFlags;
USHORT wheelZ;
bool leftButtonDown;
bool rightButtonDown;
bool middleButtonDown;
USHORT keyCode;
#pragma endregion
};
extern Input* gInput;


#endif[/CODE]

When I initialize it in the main function like this:[CODE]gInput = new Input();
gInput->Initialize();[/CODE]

The window starts lagging and all 4 cores of my CPU show increased load,as much as 20% - 40% !!
I tried to read input with Enter and LeftMouseButton,but it doesn't respond:

[CODE]while(!done)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(msg.message == WM_QUIT)
{
done = true;
}

if(msg.message == WM_INPUT)
{
UINT bufferSize;
GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, NULL, &bufferSize, sizeof (RAWINPUTHEADER));
BYTE *buffer=new BYTE[bufferSize];
GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, (LPVOID)buffer, &bufferSize, sizeof (RAWINPUTHEADER));
SafeDelete(gInput->raw);
gInput->raw = (RAWINPUT*)buffer;
gInput->Update();
if(gInput->keyCode = VK_RETURN)
{
done = true;
}
if(gInput->leftButtonDown)
{
done = true;
}
}
else
{
gGraphics->Render();
}
}
[/CODE]
What am I doing wrong?Did I initialize with the wrong flags?I also tried it like this:

[CODE]
Rid[0].usUsagePage = 0x01;
Rid[0].usUsage = 0x02;
Rid[0].dwFlags = RIDEV_NOLEGACY;
Rid[0].hwndTarget = 0;


Rid[1].usUsagePage = 0x01;
Rid[1].usUsage = 0x06;
Rid[1].dwFlags = RIDEV_NOLEGACY;
Rid[1].hwndTarget = 0;

[/CODE]


Same thing happens..
1

Share this post


Link to post
Share on other sites
You need to put all of your message processing inside your PeekMessage block. i.e.

[CODE]
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);

if (msg.message == WM_INPUT)
{
...
}
}

[/CODE]


PeekMessage doesn't clear the MSG structure if no message is read, so processing WM_INPUT outside of that block means that any time you receive a WM_INPUT message, you're going to continue to process that same message over and over and over until another message is received. Which means your Render is not going to get called very often.
1

Share this post


Link to post
Share on other sites
thank you for your advices,it doesn't cause a heavy cpu load now,but it still doesn't work for some reason,here is how I check the input:

[CODE]
if (raw->header.dwType== RIM_TYPEMOUSE)
{
lastMouseX = raw->data.mouse.lLastX;
lastMouseY = raw->data.mouse.lLastY;
mouseFlags = raw->data.mouse.usFlags;
mouseButtonFlags = raw->data.mouse.usButtonFlags;
leftButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_LEFT_BUTTON_DOWN;
rightButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_RIGHT_BUTTON_DOWN;
middleButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_MIDDLE_BUTTON_DOWN;
if(raw->data.mouse.ulButtons & RI_MOUSE_WHEEL)
{
wheelZ = raw->data.mouse.usButtonData;
}
}
if (raw->header.dwType== RIM_TYPEKEYBOARD)
{
keyCode=raw->data.keyboard.VKey;
bool keyPressed=raw->data.keyboard.Flags & RI_KEY_BREAK;
}


[/CODE]

maybe I'm getting my info from a bad source?I read about it here: http://www.toymaker.info/Games/html/raw_input.html
Can anyone suggest another basic tutorial for RawInput? [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
0

Share this post


Link to post
Share on other sites
[quote name='krippy2k8' timestamp='1346804044' post='4976623']
What is it that doesn't work?
[/quote]

well basically in the loop where it checks for WM_INPUT(which I fixed now thanks to you guys) I do this:

[CODE]void Application::Run()
{
MSG msg;
bool done, result;
ZeroMemory(&msg, sizeof(MSG));

done = false;
while(!done)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
{
done = true;
}
if(msg.message == WM_INPUT)
{
UINT bufferSize;
GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, NULL, &bufferSize, sizeof (RAWINPUTHEADER));
BYTE *buffer=new BYTE[bufferSize];
GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, (LPVOID)buffer, &bufferSize, sizeof (RAWINPUTHEADER));
SafeDelete(gInput->raw);
gInput->raw = (RAWINPUT*)buffer;
gInput->Update();
}
}
gGraphics->Render();
}
}
[/CODE]


so I'm basically setting the raw from the RAWINPUT* raw that is a member of the Input class to the info I get from the message loop and then I set a bunch of bools depending on it:

[CODE]void Input::Update()
{
if (raw->header.dwType== RIM_TYPEMOUSE)
{
lastMouseX = raw->data.mouse.lLastX;
lastMouseY = raw->data.mouse.lLastY;
mouseFlags = raw->data.mouse.usFlags;
mouseButtonFlags = raw->data.mouse.usButtonFlags;
leftButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_LEFT_BUTTON_DOWN;
rightButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_RIGHT_BUTTON_DOWN;
middleButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_MIDDLE_BUTTON_DOWN;
if(raw->data.mouse.ulButtons & RI_MOUSE_WHEEL)
{
wheelZ = raw->data.mouse.usButtonData;
}
}
if (raw->header.dwType== RIM_TYPEKEYBOARD)
{
keyCode=raw->data.keyboard.VKey;
bool keyPressed=raw->data.keyboard.Flags & RI_KEY_BREAK;
}
}[/CODE]


If I put a message box under [b]if (raw->header.dwType== RIM_TYPEMOUSE)[/b], it pops up every time i click or move the mouse,which means it works perfectly.Same when I test for the keyboard.The problem is that when I do this somewhere else:

[CODE]if(gInput->leftButtonDown)
{
MessageBox(NULL,L"lolzorz",L"lololol",MB_OK);
}[/CODE]

like right after [b]gGraphics->Render()[/b] and it should make a pop up box when I click the mouse button,right?Well it doesn't.I tried with keys and with everything,it doesn't respond to any input.I'm thinking the way I set the bools is wrong?
0

Share this post


Link to post
Share on other sites
Yeah, you want to test usButtonFlags, not ulButtons. See [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645578%28v=vs.85%29.aspx"]MSDN[/url]
0

Share this post


Link to post
Share on other sites
[quote name='krippy2k8' timestamp='1346825749' post='4976716']
Yeah, you want to test usButtonFlags, not ulButtons. See [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645578%28v=vs.85%29.aspx"]MSDN[/url]
[/quote]

yeah I tried that too but it only works in the [b]while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) [/b]block,I have the feeling that the program stays inside of this block of code forever,since nothing works outisde of it,but if I replace the [b]while [/b]with an [b]if[/b],it lags again extremely.
0

Share this post


Link to post
Share on other sites
Okay I see. The messages indicate transition states, not the complete state of the buttons. What's probably happening is you're getting mouse movement messages after your button down messages, so when you test for mouse button down in the mouse movement message it is coming up false and clearing your button down flag.

So you'll want to do something like this in your Update:

[CODE]
if (raw->header.dwType== RIM_TYPEMOUSE)
{
if (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN)
leftButtonDown = true;
else if (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP)
leftButtonDown = false;
}

[/CODE]
0

Share this post


Link to post
Share on other sites
[quote name='krippy2k8' timestamp='1346875670' post='4976963']
Okay I see. The messages indicate transition states, not the complete state of the buttons. What's probably happening is you're getting mouse movement messages after your button down messages, so when you test for mouse button down in the mouse movement message it is coming up false and clearing your button down flag.

So you'll want to do something like this in your Update:

[CODE]
if (raw->header.dwType== RIM_TYPEMOUSE)
{
if (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN)
leftButtonDown = true;
else if (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP)
leftButtonDown = false;
}

[/CODE]
[/quote]

Yes,but I am alredy getting good input,the problem is that the way it is now:
[CODE]while(!done)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
//Dostuff;
}
}
//Dostuff2;[/CODE]

Dostuff2 will never be executed,because the program stays in [b]while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))[/b] forever.If I change it to [b][u]if[/u](PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))[/b],it starts to lag again.I'm confused,since in MSDN they also say you should use the [b]while(PeekMessage(...))[/b] way,how will it ever get out of the loop?My [b]PeekMessage[/b] seems to return [b]true [/b]always.
0

Share this post


Link to post
Share on other sites
Your //Dostuff2 is outside of the main loop, that will never be reached until your message loop completely ends (i.e. the application is closing.)

Do this:

[CODE]
while(!done)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
//Dostuff;
}
//Dostuff2;
}

[/CODE]


If that is what you actually have and Dostuff2 is never reached, then you must be doing something within the inner loop to generate new messages.

You may want to post your actual code again Edited by krippy2k8
0

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  
Followers 0