当 GC 启动时 Xna Xbox 掉帧

发布于 2025-01-07 05:25:24 字数 945 浏览 0 评论 0 原文

我正在为 XBOX 开发一个应用程序(XNA Game),这是一个非常简单的应用程序。起始页包含带有移动 gif 图像的图块。这些 gif 图像实际上都是 png 图像,每个图块都会加载一次,并放入一个数组中。然后,使用定义的延迟来播放这些图像(使用每次延迟过去时都会增加的计数器)。

这一切都运行良好,但是,我注意到 GIF 图像的移动每隔 x 秒就会出现一些小滞后。然后我开始添加一些基准测试内容:

http://gyazo.com/f5fe0da3ff81bd45c0c52d963feb91d8

如您所见,对于如此简单的游戏来说 FPS 相当低程序(这是在调试中,当从 Xbox 本身运行应用程序时,我得到的平均帧率为 62fps)。 2 个重要设置:

Graphics.SynchronizeWithVerticalRetrace = false; 
IsFixedTimeStep = false;

将 isFixedTimeStep 更改为 true 会增加延迟。设置图块有旋转的轮子,您可以看到轮子每 x 秒向后退一点。 SynchronizeWVR 也同样如此,也会增加延迟。

我注意到滞后和垃圾收集器启动的那一刻之间存在联系,每次启动时,都会出现滞后...

不要介意 MAX HMU(堆内存使用量),因为这需要占用开始,avg更现实。

这是性能监视器的另一个屏幕,但是我对这个工具不太了解,第一次使用它......希望它有帮助:

http://gyazo.com/f70a3d400657ac61e6e9f2caaaf17587

I'm developing an app (XNA Game) for the XBOX, which is a pretty simple app. The startpage contains tiles with moving gif images. Those gif images are actually all png images, which gets loaded once by every tile, and put in an array. Then, using a defined delay, these images are played (using a counter which increases every time a delay passes).

This all works well, however, I noticed some small lag every x seconds in the movement of the GIF images. I then started to add some benchmarking stuff:

http://gyazo.com/f5fe0da3ff81bd45c0c52d963feb91d8

As you can see, the FPS is pretty low for such a simple program (This is in debug, when running the app from the Xbox itself, I get an avg of 62fps).
2 important settings:

Graphics.SynchronizeWithVerticalRetrace = false; 
IsFixedTimeStep = false;

Changing isFixedTimeStep to true increases the lag. The settings tile has wheels which rotate, and you can see the wheels go back a little every x seconds. The same counts for SynchronizeWVR, also increases lag.

I noticed a connection between the lag and the moment the garbage collector kicks in, every time it kicks in, there is a lag...

Don't mind the MAX HMU(Heap memory usage), as this is takes the amount of the start, the avg is more realistic.

Here is another screen from the performance monitor, however I don't understand much from this tool, first time I'm using it... Hope it helps:

http://gyazo.com/f70a3d400657ac61e6e9f2caaaf17587

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

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

发布评论

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

评论(1

夏日落 2025-01-14 05:25:24

经过一番研究,我找到了罪魁祸首。

我有自定义组件,它们全部派生自 GameComponent,并且被添加到主 Game 类的组件列表中。

这是一个(总共 2 个)主要问题,导致更新所有不需要更新的内容。 (绘制方法是唯一记住页面状态的方法,并且仅在需要时绘制)。
我通过使用不同的“屏幕”(或我所说的页面)修复了这个问题,这是唯一从 GameComponent 派生的组件。

然后我只更新处于活动状态的页面,并且该页面上的自定义组件也会更新。问题已解决。

第二个大问题如下:
我制作了一个课程,帮助我在屏幕上定位内容,即相对的百分比和类似的内容。父容器、对齐和V 形对齐等
该类具有大小和属性等属性。向量,但我没有将计算值保存在支持字段中,而是每次访问属性时都重新计算它们。但是计算这样复杂的东西需要使用引用(例如对父容器和子容器的引用),这使得 CLR 变得非常困难,因为它有很多工作要做。

我现在将整个定位类重建为功能齐全的优化类,并使用不同的标志在必要时重新计算,并且我现在得到的平均速度为 170+fps,而不是下降 20fps!

After a little research I found the culprit.

I have custom components that all derive from GameComponent, and who get added to the Component list of the main Game class.

This was one (of a total of 2) major problem, causing to update everything that wasn't needing an update. (The draw method was the only one who kept the page state in mind, and only drew if needed).
I fixed this by using different "screens" (or pages as I called them), wich are the only components who derive from GameComponent.

Then I only update the page wich is active, and the custom components on that page also get updated. Problem fixed.

The second big problem, is the following;
I made a class which helps me on positioning stuff on the screen, relative that is, with percentages and stuff like that. Parent containers, aligns & v-aligns etc etc.
That class had properties, for size & vectors, but instead of saving the calculated value in a backing field, I recalculated them everytime I accessed a property. But calculating complex stuff like that uses references (to parent & child containers for example) wich made it very hard for the CLR, because it had alot of work to do.

I now rebuilt the whole positioning class to a fully functional optimized class, with different flags for recalculating when necessairy, and instead of drops of 20fps, I now get an average of 170+fps!

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