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.
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.
多线程使某些事情变得更容易,并且将渲染和游戏逻辑保持在单独的线程中是常见的做法。但就您而言,随之而来的开销根本不值得付出努力。此外,只有在多核 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.
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).
发布评论
评论(4)
不,你不需要线程任何东西。
线程不适用于“简单”任务。线程适用于您可以合理预期会出现重大性能问题的任务,这样您实际上可以通过多线程获得一些好处。
通过对 Breakout 克隆进行线程化,您将获得令人头疼的编码问题。而已。它根本没有重要到需要它的程度,如果您不需要线程,那么您几乎永远不应该使用它。
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.
是的,您绝对不应该使用单个线程进行渲染和计算。
顺便说一句,您可能会发现此处有关实时 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.
,因此每次更新您必须执行 30 次圆形重新调整测试。我认为当前的计算机速度足够快,每秒可以执行数十万次。
多线程使某些事情变得更容易,并且将渲染和游戏逻辑保持在单独的线程中是常见的做法。但就您而言,随之而来的开销根本不值得付出努力。此外,只有在多核 CPU 上才能实现性能提升。
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.
如果您的应用程序应该在多核系统上运行,那么多线程就有意义。
当线程数超过核心数时,称为超额订阅,这在线程应用程序中通常会产生不良影响,因为它会带来额外的开销。
有时,当您期望某些线程等待相当长的时间(例如文件系统上的读/写操作)时,就会出现超额订阅。
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).