Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lag free input

Started by chot Jul 22, 2010 at 11:28 AM 2 replies 2k views
Original Post
chot
chot
Hi,

I'm writing a small project in C#, using SlimDX and DirectX9, and I've worked on input for some time now. My problem is, I can't seem to get it absolutely lag free.

What I've got is a small test project, which only goal is to render a quad on the screen where the windows cursor is. This all works fine, except the quad moves a few ms behind the cursor, so if I just keep moving the cursor to the right for example, the quad is located a few mm to the left of the cursor. The program runs in windowed mode at > 200 fps.

* Overriding the controls OnMouseMove, using the event, listening to WM_MOUSEMOVE in WndProc etc etc, nothing based on WM_MOUSEMOVE seems to cut it
* Using RawInput, i.e. registering RegisterRawInputDevices and use WM_INPUT, but it gives the exact same result (I tried drawing one two quads simultaneously just to see, and they move exactly the same provided I turn off mouse acceleration)
* DirectInput is deprecated, and the docs says: "Internally, DirectInput creates a second thread to read WM_INPUT data, and using the DirectInput APIs will add more overhead than simply reading WM_INPUT directly."

What else is there?

Is it possible that it's not the input that's lagging but something with the drawing of directx stuff to the window?
----------Thale Cres
Buckeye
Buckeye
Are you concerned with the actual lag, or just the appearance when it lags?

If it's just the appearance, hide the cursor and draw your own where you draw the box. As the long as the mouse moves, keep redrawing until your draw position and the actual mouse position match. It may still give you the feeling of lag as you're instinctively familiar with how the mouse should move, but the appearance will match.

If it's the actual lag, it's guaranteed you can move the mouse while the box is being rendered, no matter how quickly you get the mouse position.
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.
Codarki
Codarki
I'm not an expert on input devices, but couple ideas...

You could put a timer between the rectangle position updates, and if the frequency is low enough (update is much less than 200 times per second), extrapolate the position when drawing.

Direct3D buffers multiple frames beforehand in drivers to keep GPU busy. I dont recall if there was some command to flush the pipe in DX9, but at least in DX10 you can wait for an event at CPU when frame is done.
chot
chot
Buckeye:
Mainly the actual lag (although the appearance would be nice to get rid of as well, for example when moving an object in an editor you'd want it to follow the cursor).

Quote:
If it's the actual lag, it's guaranteed you can move the mouse while the box is being rendered, no matter how quickly you get the mouse position.


Hm good point.. I did some more thinking: if I move the mouse from one side to another on my screen in about the same rate as I did in my program (where the box appeared to lag behind) it takes around 4 sec, which means it moves 1280px/4sec/60fps = 5 pixels each frame, which is about the amount it lags behind.. so maybe it's not a very good test of input accuracy

Ftn:
Quote:
You could put a timer between the rectangle position updates, and if the frequency is low enough (update is much less than 200 times per second), extrapolate the position when drawing.

Direct3D buffers multiple frames beforehand in drivers to keep GPU busy. I don't recall if there was some command to flush the pipe in DX9, but at least in DX10 you can wait for an event at CPU when frame is done.

Also very good points, I'll have to check them both out, *added to tomorrows todo list* :)
----------Thale Cres

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.