I created an application using Java and it runs smoothly on the Windows platform. However, when it was tested on my Macbook Pro Retina 15 'with the 4960HQ, the displayed frame rate was significantly lower.
I encoded a program to run animations at a constant frequency of 60 frames per second, and the console shows that 60 frames per second are retrieved on both Mac and Windows. However, the program on a Mac looks like it is running at a speed of 6-8 frames per second.
Is there a custom coding methodology developed for the Mac? Or is Java just not optimized for Mac OSX?
Minimum working code example:
long framerate = 1000 / 60;
long frameStart;
long frameCount = 0;
long elapsedTime;
long totalElapsedTime = 0;
while(true){
frameStart = System.currentTimeMillis();
world.moveBG(3);
elapsedTime = System.currentTimeMillis() - frameStart;
try {
if (elapsedTime < framerate) {
Thread.sleep(framerate - elapsedTime);
} else {
Thread.sleep(5);
}
} catch (InterruptedException e) {
break;
}
++frameCount;
totalElapsedTime += (System.currentTimeMillis() - frameStart);
if (totalElapsedTime > 1000) {
reportedFramerate = (long) ((double) frameCount
/ (double) totalElapsedTime * 1000.0);
System.out.println("fps: " + reportedFramerate);
frameCount = 0;
totalElapsedTime = 0;
}
}
fps, 60fps . world.moveBG(3) 3 ( , ). Mac 10fps 60. 60 .
, , Mac, Windows, , Mac