gpt4 book ai didi

java - Java 6 更新 19,20 中的绘图性能与 Java 6 更新 3 相比?

转载 作者:行者123 更新时间:2023-11-30 11:59:21 28 4
gpt4 key购买 nike

我使用较早的 Java 6 u 3 获得的帧速率是新版本的两倍。很奇怪。谁能解释一下?

在 Core 2 Duo 1.83ghz 上,集成视频(仅使用一个内核)- 1500(较旧的 java)与 700 fps在 Athlon 64 3500+ 上,离散视频 - 120(较旧的 java)与 55 fps

该应用程序是一款带有移动矩形的简单游戏。我正在使用 Graphics2D 从循环中绘制。

编辑:一些代码。整个东西很大,这只是一些重要的部分。

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();
}
...

游戏循环:

    ...
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)));
...

最佳答案

Java 6 版本 19,20 和由 Oracle 而不是 Sun 发布的第一个版本。他们在许多领域都有无数的问题。例如,Web 启动功能几乎已损坏。

这是一个issue like this .如果需要,请谷歌搜索更多信息。

目前,我建议您坚持使用旧版本,并等待下一个版本。

关于java - Java 6 更新 19,20 中的绘图性能与 Java 6 更新 3 相比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2670975/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com