开发者

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

开发者 https://www.devze.com 2022-12-19 03:08 出处:网络
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

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 kn开发者_如何转开发ow 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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消