Proper design for game loop?

Put your problem here if it does not fit any of the other categories.

Proper design for game loop?

Postby FlySwat » Sat Mar 14, 2009 4:44 pm

I'm using the multithreaded (SurfaceView + Thread) pattern used in the lunar lander demo for my first game project.

The game features a particle engine that displays up to 200 particles on the screen at once, and is not as performant as I would expect. I am wondering if the constant locking and releasing of the canvas is causing the slowdown.

Are there any example game loop/threads around on here?

My other theory for the crummy performance is that when I looked at LogCat:

D/dalvikvm(12128): GC freed 14 objects / 536 bytes in 76ms
D/dalvikvm(12128): GC freed 14 objects / 552 bytes in 73ms
D/dalvikvm(12128): GC freed 14 objects / 536 bytes in 73ms
D/dalvikvm(12128): GC freed 14 objects / 552 bytes in 79ms
D/dalvikvm(12128): GC freed 14 objects / 536 bytes in 75ms
D/dalvikvm(12128): GC freed 14 objects / 552 bytes in 76ms
D/dalvikvm(12128): GC freed 14 objects / 536 bytes in 75ms

This is happening every frame, so I am apparently newing up an object and releasing it per frame. I'm surprised the the GC is collecting constantly, I thought it was a generational GC.

However, any advice on pinpointing what this resource is so I can make it longer living and avoid the per frame collection?
FlySwat
Freshman
Freshman
 
Posts: 6
Joined: Sat Mar 07, 2009 10:53 pm

Top

Postby MrSnowflake » Sat Mar 14, 2009 9:42 pm

You might wanna try this:
romain guy wrote:It's pretty easy. Launch the tool called DDMS (the standalone one, not
the one that comes with the Eclipse plugin.) Inside the tool, go to
the Allocations Tracker tab. Click Start Tracking, use your app a
little, then click Get Allocations. You will get a list of all
allocations with, for each one of them, the stack trace to the
allocation.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby FlySwat » Sat Mar 14, 2009 11:19 pm

Thanks Mr.SnowFlake...Turns out I was allocating a new Bitmap/Canvas for double buffering while painting... I made them into private members so they can be reused.

The game is running faster, though definitely not at the speed I'd like as I'm still adding complexity.
FlySwat
Freshman
Freshman
 
Posts: 6
Joined: Sat Mar 07, 2009 10:53 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 30 guests