Newbie
Newbie

Reputation: 1613

Mouse coordinates lags if CPU usage is not 100% - really weird!

When i make my program to use only 0-2% cpu (removed some CPU intensive opengl function), my mouse coordinates starts to lag! and when i use 100% CPU (when enabling the opengl function) i get nice and smooth mouse coordinates, note that the opengl function does nothing to my mouse coordinates. look at below image i recorded my rotation function values by using mouse coordinates:

This is with 100% cpu usage (as it should look): no lag http://img15.imageshack.us/img15/1304/mousecursorsmoothcoords.png

-

This is with 2% cpu usage: lag http://img5.imageshack.us/img5/5514/mousecursorlaggedcoords.png

It is really annoying problem, because i am using mouse cursor position to change the rotation angle, and with the above image case, it looks really laggy rotation.

I might be able to make own interpolation or something, but i want to know what is causing this and how to fix it.

Im getting mouse coordinates with WM_MOUSEMOVE message and i also tried to use GetCursorPos() on every frame before my rotation code, but it has no difference.

Edit: I noticed that the CPU usage doesnt have to be 100% to get smooth, but the CPU just needs to be "waken up" and then it stays smooth even with low CPU usage.

Upvotes: 1

Views: 996

Answers (2)

Michael Burr
Michael Burr

Reputation: 340486

You might be able to get better information about the mouse motion by using the GetMouseMovePointsEx() API.


Sidenote: for some reason I can only see your first graphic

Upvotes: 0

Merlyn Morgan-Graham
Merlyn Morgan-Graham

Reputation: 59151

Your second graph seems like it is "bunching" updates. Jumps on the Y axis seem to be at a fixed frequency on the X axis.

Speculation:

  • Maybe power saving is kicking your CPU to/from a lower power state. Is this a laptop, or is CPU power saving enabled in Windows/BIOS (I'm not sure where the setting is)?
  • As GMan suggested in his comment, maybe it has to do with how many timeslices your app is getting
  • Some sort of sleep/timer functionality is regressing to a lower resolution. An example would be the difference between timeGetTime() and queryPerformanceCounter(): http://www.geisswerks.com/ryan/FAQS/timing.html

Upvotes: 1

Related Questions