如果 CPU 使用率不是 100%,鼠标坐标就会滞后 - 真的很奇怪!

发布于 2024-08-20 15:04:40 字数 877 浏览 6 评论 0原文

当我让我的程序仅使用 0-2% cpu(删除了一些 CPU 密集型 opengl 函数)时,我的鼠标坐标开始滞后!当我使用 100% CPU 时(启用 opengl 函数时),我会得到漂亮且平滑的鼠标坐标,请注意 opengl 函数对我的鼠标坐标没有任何作用。看下图,我使用鼠标坐标记录了我的旋转函数值:

这是 100% cpu 使用率(正如它应该看起来的那样): 无延迟 http://img15.imageshack.us/img15/1304/mousecursorsmoothcoords.png< /a>

-

这是 2% cpu 使用率的情况: 滞后 http://img5.imageshack.us/img5/5514/mousecursorlaggedcoords.png

这确实是一个烦人的问题,因为我使用鼠标光标位置来改变旋转角度,并且在上面的图像情况下,它看起来真的很滞后旋转。

我也许可以进行自己的插值或其他操作,但我想知道是什么原因造成的以及如何修复它。

我通过 WM_MOUSEMOVE 消息获取鼠标坐标,并且我还尝试在旋转代码之前的每一帧上使用 GetCursorPos() ,但它没有区别。

编辑:我注意到CPU使用率不一定要100%才能流畅,但CPU只需要被“唤醒”,然后即使CPU使用率较低也能保持流畅。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只是一片海 2024-08-27 15:04:41

你的第二张图看起来像是“捆绑”更新。 Y 轴上的跳跃似乎在 X 轴上以固定频率进行。

推测:

  • 也许省电会使您的 CPU 进入或退出较低功耗状态。这是一台笔记本电脑,还是在 Windows/BIOS 中启用了 CPU 省电功能(我不确定设置在哪里)?
  • 正如 GMan 在他的评论中建议的那样,也许这与您的应用程序获得的时间片数量有关
  • 某种睡眠/计时器功能正在回归到较低的分辨率。一个例子是 timeGetTime() 和 queryPerformanceCounter() 之间的区别:
    http://www.geisswerks.com/ryan/FAQS/timing.html

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
撩心不撩汉 2024-08-27 15:04:41

您可以使用 获得有关鼠标运动的更好信息GetMouseMovePointsEx() API。


旁注:由于某种原因我只能看到你的第一个图形

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文