Box2D 中大型静态边缘地形的性能问题

发布于 2024-11-09 04:03:32 字数 263 浏览 3 评论 0原文

我想在我正在制作的游戏中支持非常大的世界。这通常不是问题,因为我可以剔除世界的大部分,因为它不是一次性可见的。然而,Box2D 似乎不喜欢我的想法!

我的地形目前由大约 1000 个边缘形状组成。然而,仅此一项似乎就可以正常工作: 即使我只添加了一些(~25)动态对象(小圆圈),性能也会急剧下降!

  • 为什么会出现这种情况,动态 树应该取消所有未受影响的 静态地形很早就形成了 没有表现惩罚, 不应该吗?
  • (如何)我可以解决这个问题吗?

I'd like to support very large worlds in the game that I'm making. This is not a problem usually, because I can cull most of the world as it is not visible all at once. However, Box2D doesn't seem to like my idea!

My terrain currently consists of about 1000 edge shapes. This alone seems to work fine, however:
Even after I add only a few (~25) dynamic objects (small circles), the performance is decreasing dramatically!

  • Why does this happen, the dynamic
    tree should cancel out all unaffected
    static terrain shapes very early and
    without performance penalties,
    shouldn't it?
  • (How) can I work around this?

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

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

发布评论

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

评论(1

中二柚 2024-11-16 04:03:32

答案是因为边缘形状不会与其他边缘形状发生碰撞。

从手册:

边缘形状是线段。提供这些是为了帮助
为您的游戏提供自由形式的静态环境。一个主要限制是
边缘形状的特点是它们可以与圆形和多边形碰撞,但不能
与他们自己。 Box2D 使用的碰撞算法要求
两个碰撞形状中至少之一具有体积。边缘形状没有
体积,所以边边碰撞是不可能的。

因此,即使您有许多边缘形状,由于它们不会相互碰撞,您也不会看到性能下降。添加一些对象后,box2d 就会开始检查碰撞。

The answer is because edge shapes do not collide with other edge shapes.

From the manual:

Edge shapes are line segments. These are provided to assist in making
a free-form static environment for your game. A major limitation of
edge shapes is that they can collide with circles and polygons but not
with themselves. The collision algorithms used by Box2D require that
at least one of two colliding shapes have volume. Edge shapes have no
volume, so edge-edge collision is not possible.

So even though you have many edge shapes, as they do not collide with each other, you aren't seeing a performance drop. Once you add some objects, then box2d starts checking for collisions.

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