我的游戏需要多线程吗?

发布于 2024-12-09 15:49:38 字数 1432 浏览 0 评论 0原文

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

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

发布评论

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

评论(4

人海汹涌 2024-12-16 15:49:38

我正在尝试制作一个简单的突破游戏

不,你不需要线程任何东西。

线程不适用于“简单”任务。线程适用于您可以合理预期会出现重大性能问题的任务,这样您实际上可以通过多线程获得一些好处。

通过对 Breakout 克隆进行线程化,您将获得令人头疼的编码问题。而已。它根本没有重要到需要它的程度,如果您不需要线程,那么您几乎永远不应该使用它。

I'm trying to make a simple breakout game

No, you do not need to thread anything.

Threading is not for "simple" tasks. Threading is for tasks where you can reasonably expect significant problems with performance, such that you would actually gain something by going multithreaded.

What you will gain by threading a Breakout clone is a coding headache. Nothing more. It simply isn't significant enough to require it, and if you don't need threading, you should almost never use it.

狼性发作 2024-12-16 15:49:38

是的,您绝对不应该使用单个线程进行渲染和计算。
顺便说一句,您可能会发现此处有关实时 Android 游戏的 IO 讨论很有用。

Yes, you should definitely not be using a single thread for your rendering and calculations.
As an aside you might find the IO talk on realtime android games here useful.

冰之心 2024-12-16 15:49:38

例如,由于闯关游戏具有类似 6X5 的块网格,因此需要对每个块进行测试

,因此每次更新您必须执行 30 次圆形重新调整测试。我认为当前的计算机速度足够快,每秒可以执行数十万次。

多线程使某些事情变得更容易,并且将渲染和游戏逻辑保持在单独的线程中是常见的做法。但就您而言,随之而来的开销根本不值得付出努力。此外,只有在多核 CPU 上才能实现性能提升。

Since a breakout game for example, has like 6X5 grid of blocks, and for each block it needs to test

So you have to perform 30 circle-recangle tests per update. I think current computers are fast enough to do this a few hundred of thousand times a second.

Multithreading makes some things easier, and keeping rendering and game logic in separate threads is a common practice. But in your case the overhead that comes with it is simply not worth the effort. Also a gain in performance is only achieveable on multicore CPUs.

猫卆 2024-12-16 15:49:38

如果您的应用程序应该在多核系统上运行,那么多线程就有意义。

当线程数超过核心数时,称为超额订阅,这在线程应用程序中通常会产生不良影响,因为它会带来额外的开销。

有时,当您期望某些线程等待相当长的时间(例如文件系统上的读/写操作)时,就会出现超额订阅。

Multithreading make sense if your application is supposed to run on multicore systems.

When # of threads exceeds number of cores it is called Oversubscription, which is usually bad effect in threaded applications because it gives additional overhead.

Sometimes oversubscription is intended when you expect some threads to be waiting for considerable amount of time (e.g. read/write operation on filesystem).

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