Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Smooth Mouse - Threads? Suspend/Resume?

This topic is 5894 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 developing my first intended FINISHED game (I''ve written many demos long ago) It''s very simple - just a Math24 game interface My problem is that the mouse cursor is incredibly sluggish and thats just on the menu! I tried some multithreading but I must have done something wrong as it didn''t really help What I did was create a mouse drawing thread that is usually suspended, but is resumes the moment I get a mousemove (I''m using Win32 messages to handle this) I was simply wondering how others do this, and what works best? I would really appreciate any comments anyone has on this - no matter how small or ''pathetic'' PS: I''ll put a URL up on this thread once I have a clean sample of what I''m doing (or what you guys/girls advise me to do)

Share this post

Link to post
Share on other sites
By sluggish, I guess you mean there''s a reasonable delay between mouse movement and cursor movement, as opposed to slow mouse cursor velocity (otherwise, look up mouse accelleration).

What are you drawing with? GDI? DirectX?
What command are you using to draw the cursor? copyrects?

Multithreading drawing routines can cause problems, because one thread can draw over the other thread when it''s supposed to be behind, etc. Unless you''re drawing the mouse cursor way more often than drawing the background image, you probably don''t want multithreading.

If you still want multithreading for your cursor, you want to assure that only one drawing routine is running at any one time, (a mutex does this well). This _might_ remove the problem.

A better solution _might_ be to read all your messages at the same point, and update your mouse cursor position whenever the message is mouse related. Then draw the cursor once per frame from your own mouse cursor position.

Share this post

Link to post
Share on other sites
i''ve had problems like this before. in my case it was that i wasnt refreshing the mouse''s position enough. What i did was move the actual mouse code into a seperate thread, so that it could update more often (and therefore be more responsive), and just blit the mouse to the screen every frame.

that _should_ work...

tell me how it goes


Share this post

Link to post
Share on other sites
Jonii, you may have a point

I''ve been thinking about it, and I think I understand my problem a little clearer.

I think I will need to put all the mouse drawing + messaging code into a separate thread.
Putting one or the other doesn''t really seem to work - both need to be put into the thread.

The reasons are:

1)If only the mouse *render* is threaded, the messages cannot be handled immediately cos the game loop function is intensively busy rendering,etc.
Even if the mouse *render* is responsive it will not help if the position of the mouse is not updated quick enough

2)If mouse *messages* are threaded, the FPS will still *visually* cause the mouse to be unresponsive

So the answer is probably that both will need to be threaded together

The whole threading thing is a bit messy to do though, but I think it may be a necessary evil in my case
I''m still clueless as to why I have a bad FPS on some systems
(I know one just has a cr*p video card however)

I still have one problem however - I''ve never tries multithreading something that reads from the windows messages while other messaging is busy.

I read the article ''Decoupling the mouse pointer update from the frame rate'' on gamedev (should be able to be searched)
to try figure out the answer, but I''m not sure I follow the article correctly.
The whole thing is explained very badly

Eg. does the second code snippet go into the usual windows messaging callback?

And does the MsgWaitForMultipleObjects cause the calling thread to wait too? or only the indicated objects?

I''m going to study it some more, but if anyone has some better understanding of the thing than I do - help would be greatly appreciated

Share this post

Link to post
Share on other sites
I''m trying to get more clarity from the author of the article, but still no reply

In the meantime I''m going to carry on experimenting

Share this post

Link to post
Share on other sites

  • 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!