Little Pauses

I recently wrote a little bowling game in Java.

I tried really hard to reuse my objects and avoid the new keyword.

However, sometimes (not all the time, mind you) I still get this little pause before the ball hits the pins.

I’m calling the garbage collector in between frames but I still see these little pauses every once in a while - very annoying!

How do I figure out what is causing this exactly? I don’t have much experience with profilers, etc.

Thanks,

Drew

Don’t be overly afraid to use the new keyword, it’s not Evil.

Don’t call System.gc() manually.

And I’m willing to bet a lot of money that the pause is when the ball hits, not just before. Starting any sounds, or doing any massive amounts of physics?

Yes, there is a sound effect, I think that might be it. I just took it out and it helped.

It’s just an AudioClip class from Java 1.1 Applet package and I’m using the standard play() method.

Is there a better way to handle sound effects? I need to stick with Java 1.1, however.

Drew

Aaahh!! hides from the evil ms vm

Grrrr!

Well, it’s definetly the sound effects causing most of the pauses.

The only thing I can think is to remove the sound effects, but that’s a pretty lame solution. :’(

I guess I could put a toggle switch on it and let the user decide…

However, even after I removed all the sounds, there is one other little pause that comes when a sprite is rapidly changing directions. Not sure what is causing this one yet. ???

Drew

It’s a strange phenomenom that whenever a Java program isn’t smooth or performs bad, the GC is accused. ::slight_smile:

Hmm, well if you can get your hands on a Profiler it might help you track it down.

Hm hm, small pauses here and then are hard to detect with a profiler?

On what VM do you experience these pauses?
For example I experienced when you use a lot of memory in the MS VM, the GC will go nuts and cause a lot of little pauses. The Sun VM seems a lot better at this.

On the Sun VM you can use the -Xprof switch to profile and the -Xloggc: switch to log the GC activity. If that log shows a lot of ‘full gc’ reports that take some time (and also when the pauses occur), then it’s probably caused by the GC.
If it’s an applet, use the appletviewer and the -J switch to pass the above switches to the VM.

Try to increase the number of backbuffers, i used 2 buffers and got a FPS slowdown when my render loop was running too fast ( strange but when i inserted some drawImage loops my FPS increased ).

Then i switched from 2 to 4 Buffers and it solved a lot of problems 8)

[quote]Yes, there is a sound effect, I think that might be it. I just took it out and it helped.

It’s just an AudioClip class from Java 1.1 Applet package and I’m using the standard play() method.

Is there a better way to handle sound effects? I need to stick with Java 1.1, however.

Drew
[/quote]
I suppose u use Applet.getAudioClip(url) and then play().
I had the same problem, and i think i was cause it have to load the data everytime u want get the audioclip.

U can use classes of the package sun.audio (no standard, but maybe it can help u). In AudioPlayer u can specify a InputStream, so u can load the data of the audioclip in an array of bytes, and then use this array in a class of this package which extends of InputStream.

Sorry, but I have no the code here, so this is that i remember of it… If u wish try to search documentation about the package sun.audio