Drawing performance in Java 6 versions 19.20 versus Java 6 update 3?
I am getting twice the frame rate with the earlier Java 6 u 3 version than the newer ones. Very strange. Can anyone provide some kind of explanation?
On Core 2 Duo 1.83ghz, integrated video (only one core is used) - 1500 (older java) versus 700 frames per second On Athlon 64 3500+ discrete video - 120 (older java) versus 55 fps
The app is a simple moving rectangle game. I am using Graphics2D to draw from a loop.
Edit: some code. All this is big, these are just some important parts.
public class SimpleRenderer extends JFrame{
SimpleGameEngine sge;
Canvas canvas; // Our drawing component
static final int WIDTH = 640;
static final int HEIGHT = 480;
Graphics2D g2d = null;
Graphics graphics = null;
Color background = Color.BLACK;
BufferedImage bi;
BufferStrategy buffer;
public SimpleRenderer(KeyboardInput keyboard, SimpleGameEngine sge) throws HeadlessException {
this.sge = sge;
setIgnoreRepaint( true );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
canvas = new Canvas();
canvas.setIgnoreRepaint( true );
canvas.setSize( WIDTH, HEIGHT );
add( canvas );
pack();
// Hookup keyboard polling
addKeyListener( keyboard );
canvas.addKeyListener( keyboard );
canvas.createBufferStrategy( 2 );
buffer = canvas.getBufferStrategy();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
bi = gc.createCompatibleImage( WIDTH, HEIGHT );
this.setVisible(true);
}
public void draw(int fps) {
g2d = bi.createGraphics();
g2d.setColor( background );
g2d.fillRect( 0, 0, WIDTH, HEIGHT );
g2d.setColor( Color.GREEN );
g2d.drawString( "Use arrow keys to move rect", 100, 20 );
g2d.drawString( "Press esc to exit", 100, 32 );
g2d.setColor( Color.GREEN );
g2d.drawString( "FPS: "+fps, 20, 20 );
g2d.drawRect( sge.bob.x, sge.bob.y, sge.bob.w, sge.bob.h );
graphics = buffer.getDrawGraphics();
graphics.drawImage( bi, 0, 0, null );
if( !buffer.contentsLost() )
buffer.show();
}
...
Game loop:
...
long loop =0;
long update = 0;
long start = System.currentTimeMillis();
long lastIterationTime = System.nanoTime();
long nanoseccount=0;
int cyclec = 0;
int fps=0;
System.out.println("start");
while(run) {
long now = System.nanoTime();
loop++;
while(lastIterationTime + StepSize*1000000 <= now && run ==true) {
Update(StepSize);
update++;
lastIterationTime += StepSize*1000000;
}
Draw(fps);
nanoseccount += System.nanoTime()-now;
cyclec++;
if (nanoseccount >= 1000*1000000 ) {
fps = (int)Math.round((double)cyclec/(nanoseccount/1000000000));
nanoseccount = 0;
cyclec = 0;
continue;
}
}
System.out.println("loop "+ loop +" # update "+ update+ " # u/l " + ((double)update/loop)*100);
long runtime = (System.currentTimeMillis()-start);
System.out.println("run time "+ (double)runtime/1000 +"s # loop/s "+ ((double)loop/((double)runtime/1000)));
System.out.println("updates/s "+ ((double)update/((double)runtime/1000)));
...
a source to share
Java 6 version 19.20 and the first versions released by Oracle instead of Sun. In many areas they have problems with gasil. For example, the web launch feature hardly works.
Here is one question like this . Google more if you like.
For the time being, I suggest you stick with the older versions and wait for the next releases.
a source to share