Well basically my question is right in the title: why does my game use 100% cpu and the LunarLander example does not?
My game is currently almost identical to the LunarLander example in function, with a separate thread for the game loop, updating physics/events in a while() loop and drawing to the screen continuously.
However when I run LunarLander and enable the debug tools, it shows about 50% cpu usage (the emulator uses about 25% on my dual-core PC). My own game uses 100% of the cpu (and the emulator 50% on my pc).
I don't necessarily want or need to reduce the cpu load and increase the performance of my game (although it runs a bit sluggish on the emulator and on a slower phone), but I just really don't understand why the LunarLander example doesn't use 100%? It basically has a while(true) loop in which it updates the physics and draws to the screen constantly. Why does that not reach 100%?
Also my game is quite similar: I update my game state in a method and then draw everything to the screen. First a background image, then a few other images on it (the LunarLander example uses Drawables while I use Bitmap, because I don't have to transform them and they're supposed to be faster). When I don't interact with the game, nothing even really happens, and interaction is done through events, not even in the main loop.
¿Algunas ideas? :-)
preguntado el 08 de enero de 11 a las 15:01
The only way any thread can use less than 100% of its core is if it contains I/O, sleeps, competition with another thread, or anything that suspends it some of the time. So if you pause the lunar lander a few times, you will see how it suspends.