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

Smoothing out Mouse Movement with MultiThreading - I need Help!

Started by oxygen728 Sep 11, 2006 at 6:42 PM 4 replies 1.2k views
Original Post
oxygen728
oxygen728
Greatings, I'm currently learning graphics engine programming. In the short term, I'd like to smooth out mouse movement using multithreading. After reading for an hour and a half, I see that one way to do this is to have one thread that waits for mouse events and then processes mouse events when they arrive. My goal - Have smooth, GLITCH FREE, mouse movement even when the frame-rate drops. As far as drawing the mouse, I've read (I think on a gamedev article) that the following things need to happen: - Restore the rectangle of pixels where the cursor was recently drawn - Save the rectangle of pixels where the cursor is about to be drawn - Draw the cursor to the frontbuffer - Render the cursor to the backbuffer What are my questions? Basically... if you could provide me with a good resource for learning the following, I would be VERY grateful. 1. Writing a function for a secondary thread to the main application that waits for mouse events & processes them without interfering with the main thread. 2. Saving a rectangle of pixels currently in the front or backbuffer. 3. To a lesser extent... Drawing a rectangle of pixels to a front or back buffer. Thank you for your time!
oxygen728
oxygen728
My goal
- Have smooth, GLITCH FREE, mouse movement even when the frame-rate drops.

Smooth mouse movement when the FPS is low gives the illusion that the game is, in fact, running quote smoothly. I need to cater to the slower computers. The thread will remain idle 99.9% of the time.
OrangyTang
OrangyTang
Uh, whats wrong with using a hardware cursor?

Seriously, all this hard work is already done for you. Mouse movement comes into the CPU as interupts so they're always received pretty much instantly, and graphics cards specifically handle cursors separately so it doesn't interfer with the drawing of everything else.

I'm not even sure if it'd be possible - you'd have to be able to draw on the front buffer, and the clear/redraw of the cursor is going to make it go horribly flickerly and tear all over the place. I don't know if its possible with D3D, but with GL usually you're either always drawing on the back buffer or always on the front buffer, but you can't switch manually, which snookers your whole idea.
oxygen728
oxygen728
Quote:
Original post by OrangyTang
Uh, whats wrong with using a hardware cursor?

Seriously, all this hard work is already done for you. Mouse movement comes into the CPU as interupts so they're always received pretty much instantly, and graphics cards specifically handle cursors separately so it doesn't interfer with the drawing of everything else.

I'm not even sure if it'd be possible - you'd have to be able to draw on the front buffer, and the clear/redraw of the cursor is going to make it go horribly flickerly and tear all over the place. I don't know if its possible with D3D, but with GL usually you're either always drawing on the back buffer or always on the front buffer, but you can't switch manually, which snookers your whole idea.


Quote:
Uh, whats wrong with using a hardware cursor?

Nothing. I hadn't read about it.

Quote:
Seriously, all this hard work is already done for you. Mouse movement comes into the CPU as interupts so they're always received pretty much instantly, and graphics cards specifically handle cursors separately so it doesn't interfer with the drawing of everything else.

Sounds good to me.

Quote:
usually you're either always drawing on the back buffer or always on the front buffer, but you can't switch manually, which snookers your whole idea.

As I stated on the original post... I'm learning this stuff. I did a couple hours of research... this seemed to me to be the way things were done.

Does using a hardware cursor allow it to move between frames?


Some resources that I've read
Game Dev Article: http://www.gamedev.net/reference/articles/article820.asp
Game Dev Tutorial: http://www.gamedev.net/reference/programming/features/gui/page5.asp

Quoting from the second article...
Quote:
A better, solution, however, is to grab a copy of the pixel data under the mouse cursor before you blt it, then, when the mouse moves, you erase your old blt by blting your saved pixel data back. I prefer the second method.


Thanks again for your time


oxygen728
oxygen728
I have successfully implemented the hardware cursor, and it has accomplished my goal.

I guess most of the articles I read were probably referring to graphics engines developed for video cards without hardware cursor support.

Thanks

Topic Locked

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

Sign in to reply to this topic.