¿Por qué mi juego usa el 100% de la CPU y LunarLander no?

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

"My game is currently almost identical to the LunarLander example" - How is it different? Code would help a lot. -

Well I could post a few thousand lines of code, but that would make nobody happy. It's different in that I load and draw other bitmaps. I have an ontouchlistener which sets an offset on moving to draw the background in another position. And I draw Bitmap tiles on it (from an ArrayList) rather than a Drawable which is transformed. And that's about it. The overall structure (thread for game loop, update() method, draw() method) is the same. -

You probably do want to reduce the CPU load. The load you place on mobile hardware is directly related to how much of the user's battery power it will consume. -

1 Respuestas

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.

contestado el 23 de mayo de 17 a las 15:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.