0

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.

Any ideas? :-)

  • 1
    "My game is currently almost identical to the LunarLander example" - How is it different? Code would help a lot. – fredley Jan 08 '11 at 15:14
  • 2
    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. –  Jan 08 '11 at 15:24
  • 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. – adamp Jan 08 '11 at 23:35

1 Answers1

1

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.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135