Jump to content
  • Advertisement
Sign in to follow this  
DesignerX

DirectInput question

This topic is 4906 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'm trying to use DirectInput mouse device for getting mouse data Now, I'm using the buffered approach and I have the following problem : When I move the mouse very slowly the cursor moves fine, but when I make fast moves with the mouse the cursor is moving very slowly with big jumps and after a few seconds of moving the mouse I get an error message that the device buffer has overflowed. Why is that happening ? any ideas ? Is it better to use the immidiate approach ? Again, when I move the mouse very slowly everything works fine (no error messasges) but as I move the mouse like a natural user will do the buffer overflows. P.S. I set buffer size to 128 (which should be more than enough i think)

Share this post


Link to post
Share on other sites
Advertisement
The mouse information updates VERY fast/often. Its very possible that you're buffering your information and not clearing it (or not clearing it enough) -- which would lead to a buffer overflow. I suppose if you want to be lazy you could just clear the buffer if it throws an exception.

Share this post


Link to post
Share on other sites
If your mouse movement is important and your frame rate can become slow, you need a large buffer for mouse input. This is the code I use for DI8+:

DIPROPDWORD Prop;
Prop.diph.dwSize = sizeof(DIPROPDWORD);
Prop.diph.dwHeaderSize = sizeof(DIPROPHEADER);
Prop.diph.dwObj = 0;
Prop.diph.dwHow = DIPH_DEVICE;
Prop.dwData = max( 1000, (num_buttons + num_povs) * 2 + num_axes * 100 );
MouseDevice->SetProperty(DIPROP_BUFFERSIZE,&Prop.diph);


That is, a minimum of 1000 entries can be stored up. I've never had any kind of problem except on loading screens. You need to avoid throwing errors because of overflows.

Usually, buttons will come through even though an overflow occurs, and this means the mouse or such tried to move somewhere and click. But since you had an overflow, the mouse won't reach it's goal, and the click is still logged. So they will click, but in the wrong place. I would ignore any button presses or drags when you detect an overflow.

Share this post


Link to post
Share on other sites
Oops, to answer your second question:

Buffered input stores events as they happen into a buffer. When your program grabs this buffer, you get a list of events in the same order they were executed. This means if a button is pressed and released before your engine even knows it was pressed at all, it will see both of these events taking place.

Unbuffered input is as simple as seeing what state the button currently has. The button can be pressed and released in between your polling method calls and you'll have no idea it happened. It can become very ugly unless your frame rate is constant. I would guess that a human usually holds a button down for about 50 to 200 milliseconds when they are trying to press and release. So if no more than 30 milliseconds passes in a frame, it's unlikely you will miss anything. It all depends on how much caffeine the user has had [disturbed]

The mouse and other wheels and axes are a little different. With buffered input, every time the device is checked by your hardware, it stores another update. This means the number of updates can grow pretty quick. With unbuffered input, you usually just grab the absolute mouse position and subtract it's last position to see how much it moved. Although you would have no idea the order of movements it made, which could be important for painting or drawing selection shapes or other such things.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!