0

Androidエミュレーターとjvmの両方でこのコードを実行しようとしました。JVM では 33 ~ 34 ミリ秒スリープしますが、Android では 68 ~ 85 ミリ秒です。なぜそんなに不正確なのですか?

ご協力ありがとうございました。

package android.apps.td;

public class Logic は Runnable を実装します {

private long frame_time = 1000000000/30;
private long offset = 0;
private long timestamp = 0;

public void run(){
    long step;
    while(true){
        step = System.nanoTime();
        if((offset = (step - timestamp)) > frame_time){
            System.out.println("FRAME     "+(step - timestamp)/1000000+" ms");
            timestamp = step;
            update();
            render();
            repaint();
            try {
                Thread.sleep(frame_time/1000000+1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }else{
            try {
                System.out.println("Sleep ["+((frame_time-offset)/1000000+1)+" ms]");

                Thread.sleep(((frame_time-offset)/1000000+1));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

private void update() {
}

private void render() {
}

private void repaint() {
}

}

4

0 に答える 0