Do I need multithreading for my game?
I'm trying to make a simple breakout game with opengl es, on Android, and I can't decide wether I have to use a seperate thread for certain game logic stuff, like updating the game a开发者_如何学Cnd collission detection. I've prototyped a simple one: Drawing and Updating parallel of eachother in their own thread. It brought more problems than I thought, and so I thought:
Do I need more than one thread?
Since a breakout game for example, has like 6X5 grid of blocks, and for each block it needs to test
Does the ball touch this brick? And about 30 times a second. If I put this code in my main Drawing loop: OnDrawFrame(GL10) I'm afraid it will cost alot of rendering time. So can I just return to single threaded game, or not? (since Android devices are not that powerful compared to ..pc's.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.
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.
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).
精彩评论